author | Claus Gittinger <cg@exept.de> |
Tue, 18 Jun 1996 23:24:09 +0200 | |
changeset 891 | 1be0400433d5 |
parent 888 | 69447418e2b1 |
child 894 | 1041c0edbd35 |
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 |
||
23 |
!Image class methodsFor:'documentation'! |
|
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 |
||
283 | 441 |
!Image class methodsFor:'initialization'! |
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 |
||
0 | 519 |
update:something |
520 |
"flush all device specific stuff when restarted from a snapshot" |
|
521 |
||
522 |
(something == #restarted) ifTrue:[ |
|
72 | 523 |
self flushDeviceImages |
0 | 524 |
] |
525 |
! ! |
|
526 |
||
283 | 527 |
!Image class methodsFor:'instance creation'! |
528 |
||
529 |
extent:ext depth:d bits:bits |
|
530 |
"ST-80 compatibility; assume 32-bit padding" |
|
531 |
||
532 |
^ self extent:ext depth:d bits:bits pad:32 |
|
24 | 533 |
! |
534 |
||
283 | 535 |
extent:ext depth:d bits:bits pad:padding |
536 |
"ST-80 compatibility" |
|
537 |
||
538 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
24 | 539 |
! |
540 |
||
283 | 541 |
extent:ext depth:d palette:aColormap bits:bits pad:padding |
542 |
"ST-80 compatibility" |
|
543 |
||
544 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
545 |
! |
|
546 |
||
547 |
extent:ext fromArray:bits offset:offset |
|
548 |
"ST-80 compatibility" |
|
549 |
||
550 |
^ self width:ext x height:ext y fromArray:bits |
|
89 | 551 |
! |
552 |
||
553 |
fromForm:aForm |
|
554 |
"create & return an Image given a form" |
|
555 |
||
556 |
|cls| |
|
557 |
||
558 |
cls := self. |
|
559 |
cls == Image ifTrue:[ |
|
560 |
cls := self implementorForDepth:aForm depth |
|
561 |
]. |
|
562 |
^ (cls new) fromForm:aForm. |
|
563 |
||
564 |
" |
|
565 |
|f| |
|
566 |
||
567 |
f := Form width:16 height:16. |
|
568 |
f clear. |
|
569 |
f displayLineFromX:0 y:0 toX:15 y:15. |
|
570 |
f inspect. |
|
571 |
(Image fromForm:f) inspect |
|
572 |
" |
|
573 |
! |
|
574 |
||
575 |
fromImage:anImage |
|
576 |
"create & return an Image given another image. This can be used to |
|
577 |
convert an image to another depth." |
|
578 |
||
579 |
(self == Image or:[anImage class == self]) ifTrue:[^ anImage]. |
|
580 |
^ self new fromImage:anImage. |
|
581 |
||
582 |
" |
|
583 |
|i1 i8| |
|
584 |
||
585 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
586 |
i8 := Depth8Image fromImage:i1. |
|
587 |
i8 inspect |
|
588 |
" |
|
589 |
! |
|
590 |
||
191 | 591 |
fromSubImage:anImage in:aRectangle |
592 |
"create & return an Image from a rectangular area in another image. |
|
593 |
This can also be used to get a subimage in another depth." |
|
594 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
595 |
|newImage| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
596 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
597 |
self == Image ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
598 |
newImage := self implementorForDepth:anImage depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
599 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
600 |
newImage := self new. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
601 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
602 |
^ newImage fromSubImage:anImage in:aRectangle. |
191 | 603 |
|
604 |
" |
|
605 |
|i1 i8| |
|
606 |
||
607 |
i1 := Image fromFile:'bitmaps/garfield.gif'. |
|
608 |
i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20). |
|
609 |
i8 inspect |
|
610 |
" |
|
650 | 611 |
" |
612 |
|i1 i8| |
|
613 |
||
614 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
|
615 |
i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50). |
|
616 |
i8 inspect |
|
617 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
618 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
619 |
|i1 i8| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
620 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
621 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
622 |
i8 := Image fromSubImage:i1 in:(70@50 extent:50@50). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
623 |
i8 inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
624 |
" |
191 | 625 |
|
626 |
"Created: 20.9.1995 / 01:05:43 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
627 |
"Modified: 10.6.1996 / 18:11:08 / cg" |
191 | 628 |
! |
629 |
||
283 | 630 |
new |
631 |
"create a new image. Redefined to set the photometric to |
|
632 |
greyScale with black being 0 as default." |
|
633 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
634 |
^ super new photometric:(self defaultPhotometric) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
635 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
636 |
"Modified: 10.6.1996 / 18:08:37 / cg" |
283 | 637 |
! |
638 |
||
89 | 639 |
width:w height:h |
640 |
"create a new image, given width, height. Assume a depth of 1." |
|
641 |
||
642 |
|cls| |
|
643 |
||
644 |
cls := self. |
|
645 |
cls == Image ifTrue:[ |
|
646 |
cls := self implementorForDepth:1 |
|
647 |
]. |
|
648 |
^ cls new width:w height:h depth:1 |
|
649 |
! |
|
650 |
||
82 | 651 |
width:w height:h depth:d |
89 | 652 |
"create a new image, given width, height and depth" |
653 |
||
191 | 654 |
^ (self implementorForDepth:d) new |
655 |
width:w height:h depth:d |
|
82 | 656 |
! |
657 |
||
658 |
width:w height:h depth:d fromArray:pixelData |
|
89 | 659 |
"create a new image, given width, height, depth and data. |
660 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
134 | 661 |
depth (8-bit padded)." |
82 | 662 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
663 |
^ (self implementorForDepth:d) new |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
664 |
width:w height:h depth:d fromArray:pixelData |
82 | 665 |
|
666 |
" |
|
667 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
668 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
669 |
depth:1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
670 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
671 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
672 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
673 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
674 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
675 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
676 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
677 |
2r00110011]. |
82 | 678 |
" |
679 |
||
680 |
" |
|
681 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
682 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
683 |
depth:2 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
684 |
fromArray:#[4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
685 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
686 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
687 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
688 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
689 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
690 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
691 |
4r0011 4r0011]. |
89 | 692 |
" |
693 |
||
694 |
" |
|
695 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
696 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
697 |
depth:4 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
698 |
fromArray:#[16r00 16r01 16rf0 16rf1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
699 |
16r02 16r03 16rf2 16rf3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
700 |
16r04 16r05 16rf4 16rf5 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
701 |
16r06 16r07 16rf6 16rf7 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
702 |
16r08 16r09 16rf8 16rf9 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
703 |
16r0a 16r0b 16rfa 16rfb |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
704 |
16r0c 16r0d 16rfc 16rfd |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
705 |
16r0e 16r0f 16rfe 16rff]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
706 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
707 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
708 |
"Modified: 10.6.1996 / 18:18:10 / cg" |
132 | 709 |
! |
710 |
||
134 | 711 |
width:w height:h depth:d fromArray:pixelData pad:padding |
712 |
"create a new image, given width, height, depth and data. |
|
713 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
714 |
depth." |
|
715 |
||
716 |
|img newBits srcRowBytes dstRowBytes srcIndex dstIndex| |
|
717 |
||
718 |
img := (self implementorForDepth:d) new width:w height:h depth:d . |
|
719 |
||
720 |
padding ~~ 8 ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
721 |
"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
|
722 |
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
|
723 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
724 |
dstRowBytes := img bytesPerRow. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
725 |
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
|
726 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
727 |
newBits := ByteArray new:(dstRowBytes * h). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
728 |
srcIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
729 |
dstIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
730 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
731 |
1 to:h do:[:row | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
732 |
newBits replaceFrom:dstIndex |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
733 |
to:(dstIndex + dstRowBytes - 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
734 |
with:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
735 |
startingAt:srcIndex. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
736 |
srcIndex := srcIndex + srcRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
737 |
dstIndex := dstIndex + dstRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
738 |
]. |
134 | 739 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
740 |
pixelData class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
741 |
newBits := ByteArray withAll:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
742 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
743 |
newBits := pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
744 |
] |
134 | 745 |
]. |
746 |
img bits:newBits. |
|
747 |
^ img |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
748 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
749 |
"Modified: 8.6.1996 / 10:07:47 / cg" |
134 | 750 |
! |
751 |
||
283 | 752 |
width:w height:h fromArray:anArray |
753 |
"create a new image, given width, height. Assume a depth of 1 of the |
|
754 |
receiving class is Image. |
|
755 |
Data must be a ByteArray containing correctly aligned bits for depth 1 |
|
756 |
(i.e. 8 bits per byte)." |
|
757 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
758 |
|cls d pixels| |
283 | 759 |
|
760 |
cls := self. |
|
761 |
cls == Image ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
762 |
cls := self implementorForDepth:1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
763 |
d := 1. |
283 | 764 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
765 |
d := cls imageDepth |
283 | 766 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
767 |
anArray class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
768 |
pixels := ByteArray withAll:anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
769 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
770 |
pixels := anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
771 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
772 |
^ cls new width:w height:h depth:d fromArray:pixels |
191 | 773 |
|
774 |
" |
|
283 | 775 |
Image width:8 |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
776 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
777 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
778 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
779 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
780 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
781 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
782 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
783 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
784 |
2r00110011]. |
191 | 785 |
" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
786 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
787 |
"Modified: 8.6.1996 / 10:07:26 / cg" |
283 | 788 |
! ! |
789 |
||
650 | 790 |
!Image class methodsFor:'file reading'! |
791 |
||
792 |
fromFile:aFileName |
|
793 |
"read an image from a file - this methods tries to find |
|
794 |
out the file format itself (by the extension and by contents) |
|
795 |
and lets the appropriate reader read the file." |
|
796 |
||
797 |
|image name nm inStream suffixLen| |
|
798 |
||
799 |
" |
|
800 |
before trying each reader, check if file is readable |
|
801 |
" |
|
802 |
name := aFileName. |
|
803 |
inStream := Smalltalk systemFileStreamFor:name. |
|
804 |
inStream isNil ifTrue:[ |
|
805 |
inStream := Smalltalk bitmapFileStreamFor:name. |
|
806 |
inStream isNil ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
807 |
('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintCR. |
650 | 808 |
^ nil |
809 |
]. |
|
810 |
name := 'bitmaps/' , name. |
|
811 |
]. |
|
812 |
inStream close. |
|
813 |
||
814 |
" |
|
815 |
get the imageReader class from the files extension |
|
816 |
" |
|
817 |
nm := name. |
|
818 |
(name endsWith:'.Z') ifTrue:[ |
|
819 |
suffixLen := 2 |
|
820 |
] ifFalse:[ |
|
821 |
(name endsWith:'.gz') ifTrue:[ |
|
822 |
suffixLen := 3 |
|
823 |
] ifFalse:[ |
|
824 |
suffixLen := 0 |
|
825 |
] |
|
826 |
]. |
|
827 |
suffixLen ~~ 0 ifTrue:[ |
|
828 |
nm := name copyWithoutLast:suffixLen |
|
829 |
]. |
|
830 |
||
831 |
" |
|
832 |
ask the corresponding readerclass first |
|
833 |
" |
|
834 |
FileFormats keysAndValuesDo:[:suffix :readerClass | |
|
835 |
(nm endsWith:suffix) ifTrue:[ |
|
836 |
readerClass notNil ifTrue:[ |
|
837 |
image := readerClass fromFile:name. |
|
838 |
image notNil ifTrue:[^ image]. |
|
839 |
] |
|
840 |
] |
|
841 |
]. |
|
842 |
||
843 |
" |
|
844 |
no known extension - ask all readers if they know |
|
845 |
this format ... |
|
846 |
" |
|
847 |
FileFormats do:[:readerClass | |
|
848 |
readerClass notNil ifTrue:[ |
|
849 |
(readerClass isValidImageFile:name) ifTrue:[ |
|
850 |
^ readerClass fromFile:name |
|
851 |
] |
|
852 |
] |
|
853 |
]. |
|
854 |
||
855 |
" |
|
856 |
nope - unknown format |
|
857 |
" |
|
858 |
'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL. |
|
859 |
^ nil |
|
860 |
||
861 |
" |
|
862 |
Image fromFile:'bitmaps/dano.tiff' |
|
863 |
Image fromFile:'bitmaps/test.fax' |
|
864 |
Image fromFile:'bitmaps/voice.tiff' |
|
865 |
Image fromFile:'voice.tiff' |
|
866 |
||
867 |
Image fromFile:'../fileIn/bitmaps/claus.gif' |
|
868 |
Image fromFile:'../fileIn/bitmaps/garfield.gif' |
|
869 |
||
870 |
Image fromFile:'../fileIn/bitmaps/founders.im8' |
|
871 |
Image fromFile:'../goodies/faces/next.com/steve.face' |
|
872 |
||
873 |
Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico' |
|
874 |
Image fromFile:'bitmaps/globe1.xbm' |
|
875 |
Image fromFile:'bitmaps/globe1.xbm.Z' |
|
876 |
Image fromFile:'bitmaps/hello_world.icon' |
|
877 |
" |
|
878 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
879 |
"Modified: 10.6.1996 / 14:36:18 / cg" |
650 | 880 |
! ! |
881 |
||
283 | 882 |
!Image class methodsFor:'misc'! |
883 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
884 |
ditherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
885 |
"return the way we dither - |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
886 |
#threshold, or nil -> no dither |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
887 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
888 |
#error or #floydSteinberg -> errorDiffusion; much better |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
889 |
#burkes -> errorDiffusion; even better." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
890 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
891 |
^ DitherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
892 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
893 |
"Created: 17.6.1996 / 18:57:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
894 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
895 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
896 |
ditherAlgorithm:aSymbol |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
897 |
"define how to dither - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
898 |
#threshold, or nil -> no dither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
899 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
900 |
#error or #floydSteinberg -> errorDiffusion; much better |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
901 |
#burkes -> errorDiffusion; even better." |
283 | 902 |
|
903 |
DitherAlgorithm := aSymbol |
|
904 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
905 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
906 |
Image dither:#pattern |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
907 |
Image dither:#floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
908 |
Image dither:#burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
909 |
Image dither:nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
910 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
911 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
912 |
"Modified: 10.6.1996 / 12:27:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
913 |
"Created: 17.6.1996 / 18:57:19 / cg" |
283 | 914 |
! |
915 |
||
916 |
numberOfDitherColors:n |
|
917 |
"define how many colors (i.e. patterns) to use when |
|
918 |
doing a pattern dither" |
|
919 |
||
920 |
NumberOfDitherColors := n |
|
798 | 921 |
! |
922 |
||
923 |
orderedDitherMatrixOfSize:sz |
|
924 |
sz == 2 ifTrue:[ |
|
925 |
^ #[ |
|
926 |
0 2 |
|
927 |
3 1 |
|
928 |
]. |
|
929 |
]. |
|
930 |
||
931 |
sz == 4 ifTrue:[ |
|
932 |
^ #[ |
|
933 |
0 8 2 10 |
|
934 |
12 4 14 6 |
|
935 |
3 11 1 9 |
|
936 |
15 7 13 5 |
|
937 |
]. |
|
938 |
]. |
|
939 |
||
940 |
sz == 8 ifTrue:[ |
|
941 |
^ #[ |
|
942 |
0 32 8 40 2 34 10 42 |
|
943 |
48 16 56 24 50 18 58 26 |
|
944 |
12 44 4 36 14 46 6 38 |
|
945 |
60 28 52 20 62 30 54 22 |
|
946 |
||
947 |
3 35 11 43 1 33 9 41 |
|
948 |
51 19 59 27 49 17 57 25 |
|
949 |
15 47 7 39 13 45 5 37 |
|
950 |
63 31 55 23 61 29 53 21 |
|
951 |
]. |
|
952 |
]. |
|
953 |
||
954 |
^ nil |
|
955 |
||
956 |
"Created: 7.6.1996 / 14:15:05 / cg" |
|
283 | 957 |
! ! |
958 |
||
959 |
!Image class methodsFor:'queries'! |
|
960 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
961 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
962 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
963 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
964 |
^ #blackIs0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
965 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
966 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
967 |
"Created: 10.6.1996 / 18:08:12 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
968 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
969 |
|
283 | 970 |
imageDepth |
579 | 971 |
"return the depth of images represented by instances of |
972 |
this class. |
|
973 |
Must be redefined in concrete subclasses" |
|
974 |
||
975 |
^ self shouldNotImplement |
|
976 |
||
977 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
|
191 | 978 |
! |
979 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
980 |
implementorForDepth:depth |
283 | 981 |
"return the class, which best implements images of depth" |
982 |
||
983 |
depth == 1 ifTrue:[^ Depth1Image]. |
|
984 |
depth == 2 ifTrue:[^ Depth2Image]. |
|
985 |
depth == 4 ifTrue:[^ Depth4Image]. |
|
986 |
depth == 8 ifTrue:[^ Depth8Image]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
987 |
depth == 15 ifTrue:[^ Depth16Image]. "/ kludge for 15bit XFree |
283 | 988 |
depth == 16 ifTrue:[^ Depth16Image]. |
989 |
depth == 24 ifTrue:[^ Depth24Image]. |
|
990 |
^ self |
|
991 |
! ! |
|
992 |
||
993 |
!Image class methodsFor:'screen capture'! |
|
994 |
||
995 |
fromScreen |
|
996 |
"return an image of the full screen" |
|
997 |
||
998 |
|display| |
|
999 |
||
1000 |
display := Screen current. |
|
1001 |
^ 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
|
1002 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1003 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1004 |
Image fromScreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1005 |
" |
283 | 1006 |
! |
1007 |
||
1008 |
fromScreen:aRectangle |
|
1009 |
"return an image of a part of the screen" |
|
1010 |
||
1011 |
^ self fromScreen:aRectangle on:Screen current |
|
1012 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1013 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1014 |
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
|
1015 |
" |
283 | 1016 |
! |
1017 |
||
1018 |
fromScreen:aRectangle on:aDisplay |
|
1019 |
"return an image of a part of the screen, which may be on |
|
1020 |
another Display." |
|
1021 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1022 |
|depth vis img| |
283 | 1023 |
|
1024 |
depth := aDisplay depth. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1025 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1026 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1027 |
"/ 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
|
1028 |
"/ (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
|
1029 |
"/ 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
|
1030 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1031 |
vis := aDisplay visualType. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1032 |
(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
|
1033 |
depth > 8 ifTrue:[ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1034 |
depth := 24. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1035 |
] |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1036 |
]. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1037 |
|
283 | 1038 |
img := (self implementorForDepth: depth) new. |
1039 |
^ img fromScreen:aRectangle on:aDisplay |
|
1040 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1041 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1042 |
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
|
1043 |
" |
283 | 1044 |
! |
1045 |
||
1046 |
fromScreenArea |
|
1047 |
"return an image of a part of the screen; |
|
1048 |
let user specify screen area." |
|
1049 |
||
1050 |
^ self fromScreen:(Rectangle fromUser) |
|
1051 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1052 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1053 |
Image fromScreenArea |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1054 |
" |
283 | 1055 |
! |
1056 |
||
1057 |
fromUser |
|
1058 |
"return an image of a part of the screen; let user specify screen area. |
|
1059 |
Same as fromScreenArea, for ST-80 compatibility" |
|
1060 |
||
1061 |
^ self fromScreenArea |
|
1062 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1063 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1064 |
Image fromUser |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1065 |
" |
283 | 1066 |
! |
1067 |
||
1068 |
fromView:aView |
|
1069 |
"return an image taken from a views contents as currently |
|
1070 |
on the screen. The returned image has the same depth and photometric |
|
1071 |
as the Display. Notice, that for invisible or partial covered |
|
1072 |
views, the returned Image is NOT correct. You may want to raise |
|
1073 |
the view before using this method." |
|
1074 |
||
1075 |
|org dev| |
|
1076 |
||
744 | 1077 |
dev := aView graphicsDevice. |
283 | 1078 |
org := dev translatePoint:(0@0) |
744 | 1079 |
from:(aView id) |
1080 |
to:dev rootWindowId. |
|
283 | 1081 |
^ self fromScreen:(org extent:aView extent) on:dev |
191 | 1082 |
|
1083 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1084 |
Image fromView:(NewLauncher allInstances first topView) |
283 | 1085 |
Image fromView:(SystemBrowser allInstances first topView) |
191 | 1086 |
" |
744 | 1087 |
|
1088 |
"Modified: 28.5.1996 / 20:23:32 / cg" |
|
157 | 1089 |
! ! |
1090 |
||
0 | 1091 |
!Image methodsFor:'accessing'! |
1092 |
||
592 | 1093 |
bitsPerSample |
1094 |
"return the number of bits per sample. |
|
1095 |
The return value is an array of bits-per-plane." |
|
1096 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1097 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1098 |
^ Array with:self depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1099 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1100 |
"Modified: 10.6.1996 / 18:04:21 / cg" |
592 | 1101 |
! |
1102 |
||
1103 |
colorMap |
|
1104 |
"return the colormap" |
|
1105 |
||
1106 |
^ colorMap |
|
1107 |
! |
|
1108 |
||
852 | 1109 |
colorMap:aColorMap |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1110 |
"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
|
1111 |
|
852 | 1112 |
|sz "{ Class: SmallInteger }" |
1113 |
sameColors| |
|
1114 |
||
1115 |
(aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self]. |
|
1116 |
photometric == #palette ifTrue:[ |
|
1117 |
"/ any change at all ? |
|
1118 |
(sz := aColorMap size) == colorMap size ifTrue:[ |
|
1119 |
sameColors := true. |
|
1120 |
||
1121 |
1 to:sz do:[:idx | |
|
1122 |
(aColorMap at:idx) = (colorMap at:idx) ifFalse:[ |
|
1123 |
sameColors := false. |
|
1124 |
] |
|
1125 |
]. |
|
1126 |
sameColors ifTrue:[^ self]. |
|
1127 |
] |
|
1128 |
]. |
|
1129 |
||
1130 |
colorMap := aColorMap. |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1131 |
colorMap notNil ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1132 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1133 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1134 |
(photometric == #palette) ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1135 |
photometric := #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1136 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1137 |
]. |
852 | 1138 |
deviceForm notNil ifTrue:[ |
1139 |
self release |
|
1140 |
] |
|
592 | 1141 |
|
1142 |
"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
|
1143 |
"Modified: 15.6.1996 / 09:32:09 / cg" |
592 | 1144 |
! |
1145 |
||
757 | 1146 |
container:aVisualContainer |
1147 |
"ignored here - added to allow images to be used like |
|
1148 |
VisualComponents (later, Image should inherit from it)" |
|
1149 |
||
1150 |
"Created: 28.5.1996 / 23:43:49 / cg" |
|
1151 |
"Modified: 29.5.1996 / 10:22:23 / cg" |
|
1152 |
! |
|
1153 |
||
592 | 1154 |
depth |
1155 |
"return the depth of the image" |
|
1156 |
||
1157 |
^ self bitsPerPixel |
|
1158 |
! |
|
1159 |
||
1160 |
device |
|
1161 |
"return the device, the receiver is associated with. |
|
1162 |
Return nil, if the image is unassigned." |
|
1163 |
||
1164 |
^ device |
|
1165 |
! |
|
1166 |
||
1167 |
extent |
|
1168 |
"return the images extent" |
|
1169 |
||
1170 |
^ width@height |
|
1171 |
! |
|
1172 |
||
1173 |
fullColorId |
|
1174 |
"return the id of the full color image on the device. |
|
1175 |
Return nil, if the image is unassigned." |
|
1176 |
||
1177 |
fullColorDeviceForm isNil ifTrue:[^ nil]. |
|
1178 |
^ fullColorDeviceForm id |
|
1179 |
! |
|
1180 |
||
728 | 1181 |
graphicsDevice |
1182 |
"same as #device - for ST-80 compatibility" |
|
1183 |
||
1184 |
^ device |
|
1185 |
! |
|
744 | 1186 |
|
592 | 1187 |
height |
1188 |
"return the height of the image" |
|
1189 |
||
1190 |
^ height |
|
1191 |
! |
|
1192 |
||
1193 |
id |
|
1194 |
"return the id of the image on the device. |
|
1195 |
Return nil, if the image is unassigned." |
|
1196 |
||
1197 |
deviceForm isNil ifTrue:[^ nil]. |
|
1198 |
^ deviceForm id |
|
1199 |
! |
|
1200 |
||
1201 |
monochromeId |
|
1202 |
"return the id of the monochrome image on the device. |
|
1203 |
Return nil, if the image is unassigned." |
|
1204 |
||
1205 |
monoDeviceForm isNil ifTrue:[^ nil]. |
|
1206 |
^ monoDeviceForm id |
|
1207 |
! |
|
1208 |
||
1209 |
palette |
|
1210 |
"return the colormap; ST-80 compatibility" |
|
1211 |
||
1212 |
^ colorMap |
|
1213 |
! |
|
1214 |
||
1215 |
palette:aColormap |
|
1216 |
"set the colormap; ST-80 compatibility" |
|
1217 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1218 |
self colorMap:aColormap |
592 | 1219 |
|
1220 |
"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
|
1221 |
"Modified: 8.6.1996 / 09:54:02 / cg" |
592 | 1222 |
! |
1223 |
||
1224 |
photometric |
|
1225 |
"return the photometric, a symbol such as #palette, #rgb etc." |
|
1226 |
||
1227 |
^ photometric |
|
1228 |
! |
|
1229 |
||
1230 |
samplesPerPixel |
|
1231 |
"return the number of samples per pixel in the image. |
|
1232 |
The return value is an array of bits-per-plane." |
|
1233 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1234 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1235 |
^ 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1236 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1237 |
"Modified: 10.6.1996 / 18:03:30 / cg" |
592 | 1238 |
! |
1239 |
||
1240 |
width |
|
1241 |
"return the width of the image" |
|
1242 |
||
1243 |
^ width |
|
1244 |
! ! |
|
1245 |
||
1246 |
!Image methodsFor:'accessing - pixels'! |
|
1247 |
||
0 | 1248 |
at:aPoint |
2 | 1249 |
"retrieve the pixel at aPoint; return a color. |
1250 |
Pixels start at 0@0 for upper left pixel, end at |
|
81 | 1251 |
(width-1)@(height-1) for lower right pixel. |
2 | 1252 |
You should not use this method for image-processing, its |
81 | 1253 |
very slow ... |
1254 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
0 | 1255 |
|
1256 |
^ self atX:aPoint x y:aPoint y |
|
1257 |
! |
|
1258 |
||
283 | 1259 |
at:aPoint put:aColor |
1260 |
"set the pixel at aPoint to aColor. |
|
1261 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1262 |
(width-1)@(height-1) for lower right pixel. |
|
1263 |
You should not use this method for image-processing, its |
|
1264 |
very slow ... |
|
1265 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1266 |
||
1267 |
^ self atX:aPoint x y:aPoint y put:aColor |
|
1268 |
! |
|
1269 |
||
1270 |
atPoint:aPoint |
|
1271 |
"ST-80 compatibility: return the pixelValue at:aPoint." |
|
1272 |
||
1273 |
^ self valueAtX:aPoint x y:aPoint y |
|
1274 |
! |
|
1275 |
||
0 | 1276 |
atX:x y:y |
2 | 1277 |
"retrieve a pixel at x/y; return a color. |
81 | 1278 |
Pixels start at 0@0 for upper left pixel, end at |
1279 |
(width-1)@(height-1) for lower right pixel. |
|
2 | 1280 |
You should not use this method for image-processing, its |
81 | 1281 |
very slow ... |
1282 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1283 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1284 |
|pixel maxPixel| |
89 | 1285 |
|
1286 |
pixel := self valueAtX:x y:y. |
|
1287 |
photometric == #blackIs0 ifTrue:[ |
|
746 | 1288 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1289 |
^ Color gray:(pixel * (100 / maxPixel)). |
|
89 | 1290 |
]. |
1291 |
photometric == #whiteIs0 ifTrue:[ |
|
746 | 1292 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1293 |
^ Color gray:100 - (pixel * (100 / maxPixel)). |
|
89 | 1294 |
]. |
1295 |
photometric == #palette ifTrue:[ |
|
746 | 1296 |
^ colorMap at:(pixel + 1) |
89 | 1297 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1298 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1299 |
^ self colorFromValue:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1300 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1301 |
"Modified: 8.6.1996 / 10:53:22 / cg" |
2 | 1302 |
! |
1303 |
||
1304 |
atX:x y:y put:aColor |
|
1305 |
"set the pixel at x/y to aColor. |
|
81 | 1306 |
Pixels start at 0@0 for the upper left pixel, end at |
1307 |
(width-1)@(height-1) for the lower right pixel. |
|
89 | 1308 |
This method checks if the color can be stored in the image. |
1309 |
(i.e. if the receiver is a palette image, the color must be present in there). |
|
1310 |
You should not use this method for image-processing, it is very slow ... |
|
81 | 1311 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
1312 |
||
89 | 1313 |
|pixel maxPixel| |
1314 |
||
1315 |
photometric == #whiteIs0 ifTrue:[ |
|
798 | 1316 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1317 |
pixel := maxPixel - (aColor brightness * maxPixel) rounded. |
|
89 | 1318 |
] ifFalse:[ |
798 | 1319 |
photometric == #blackIs0 ifTrue:[ |
1320 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
|
1321 |
pixel := (aColor brightness * maxPixel) rounded. |
|
1322 |
] ifFalse:[ |
|
1323 |
photometric ~~ #palette ifTrue:[ |
|
1324 |
self error:'format not supported'. |
|
1325 |
^ nil |
|
1326 |
]. |
|
1327 |
pixel := colorMap indexOf:aColor. |
|
1328 |
pixel == 0 ifTrue:[ |
|
1329 |
" |
|
1330 |
the color to be stored is not in the images colormap |
|
1331 |
" |
|
1332 |
self error:'invalid color - not in colorMap' |
|
1333 |
]. |
|
1334 |
pixel := pixel - 1 |
|
1335 |
] |
|
89 | 1336 |
]. |
1337 |
self atX:x y:y putValue:pixel. |
|
798 | 1338 |
|
1339 |
"Modified: 7.6.1996 / 19:17:48 / cg" |
|
81 | 1340 |
! |
1341 |
||
283 | 1342 |
atX:x y:y putValue:aPixelValue |
1343 |
"set the pixel at x/y to aPixelValue. |
|
1344 |
The interpretation of the pixelValue depends on the photometric |
|
1345 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1346 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1347 |
(width-1) @ (height-1) for the lower right pixel. |
|
1348 |
You should not use this method for image-processing, its |
|
1349 |
very slow ... |
|
1350 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1351 |
||
1352 |
^ self subclassResponsibility |
|
1353 |
! |
|
1354 |
||
1355 |
bits |
|
1356 |
"return the raw image data; depending on the photometric, |
|
1357 |
this has to be interpreted as monochrome, greyscale, |
|
1358 |
palette or rgb data. It is also packed to be dense, so |
|
1359 |
a 4 bitPerSample palette image will store 2 pixels per byte." |
|
1360 |
||
1361 |
^ bytes |
|
1362 |
! |
|
1363 |
||
1364 |
data |
|
1365 |
"for backward compatibility - will vanish" |
|
1366 |
||
1367 |
^ bytes |
|
1368 |
! |
|
1369 |
||
1370 |
data:aByteArray |
|
1371 |
"for backward compatibility - will vanish" |
|
1372 |
||
1373 |
bytes := aByteArray |
|
1374 |
! |
|
1375 |
||
81 | 1376 |
valueAt:aPoint |
1377 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1378 |
Pixels start at 0@0 for upper left pixel, end at |
|
1379 |
width-1@height-1 for lower right pixel. |
|
1380 |
The returned numbers interpretation depends on the photometric |
|
1381 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
2 | 1382 |
You should not use this method for image-processing, its |
81 | 1383 |
very slow ... |
1384 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1385 |
||
1386 |
^ self valueAtX:aPoint x y:aPoint y |
|
1387 |
! |
|
1388 |
||
1389 |
valueAtX:x y:y |
|
1390 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1391 |
Pixels start at 0/0 for upper left pixel, and end at |
|
1392 |
width-1@height-1 for lower right pixel. |
|
1393 |
The returned numbers interpretation depends on the photometric |
|
1394 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
1395 |
You should not use this method for image-processing of |
|
1396 |
big images, its very slow ... |
|
1397 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1398 |
|
1399 |
^ self subclassResponsibility |
|
592 | 1400 |
! ! |
1401 |
||
1402 |
!Image methodsFor:'accessing - private'! |
|
1403 |
||
1404 |
bits:aByteArray |
|
1405 |
"set the raw data. |
|
1406 |
||
1407 |
This interface is only to be used when initializing |
|
1408 |
instances or by image readers. Calling for a change of an |
|
1409 |
existing image may confuse later pixel interpretation." |
|
1410 |
||
1411 |
bytes := aByteArray |
|
1412 |
||
1413 |
"Modified: 23.4.1996 / 11:08:28 / cg" |
|
2 | 1414 |
! |
1415 |
||
592 | 1416 |
bitsPerSample:aNumber |
1417 |
"set the number of bits per sample. |
|
1418 |
||
1419 |
This interface is only to be used when initializing |
|
1420 |
instances or by image readers. Calling for a change of an |
|
1421 |
existing image may confuse later pixel interpretation." |
|
1422 |
||
1423 |
bitsPerSample := aNumber |
|
1424 |
||
1425 |
"Modified: 23.4.1996 / 11:08:31 / cg" |
|
1426 |
! |
|
1427 |
||
1428 |
depth:d |
|
1429 |
"set the depth of the image. |
|
1430 |
||
1431 |
This interface is only to be used when initializing |
|
1432 |
instances or by image readers. Calling for a change of an |
|
1433 |
existing image may confuse later pixel interpretation." |
|
1434 |
||
1435 |
d == 24 ifTrue:[ |
|
1436 |
samplesPerPixel := 3. |
|
1437 |
bitsPerSample := #(8 8 8) |
|
1438 |
] ifFalse:[ |
|
1439 |
samplesPerPixel := 1. |
|
1440 |
bitsPerSample := Array with:d |
|
1441 |
] |
|
1442 |
||
1443 |
"Modified: 23.4.1996 / 11:08:34 / cg" |
|
1444 |
! |
|
1445 |
||
1446 |
extent:anExtent |
|
1447 |
"set the images extent. |
|
1448 |
||
1449 |
This interface is only to be used when initializing |
|
1450 |
instances or by image readers. Calling for a change of an |
|
1451 |
existing image may confuse later pixel interpretation." |
|
1452 |
||
1453 |
width := anExtent x. |
|
1454 |
height := anExtent y |
|
1455 |
||
1456 |
"Modified: 23.4.1996 / 11:08:38 / cg" |
|
1457 |
! |
|
1458 |
||
1459 |
height:aNumber |
|
1460 |
"set the height of the image. |
|
1461 |
||
1462 |
This interface is only to be used when initializing |
|
1463 |
instances or by image readers. Calling for a change of an |
|
1464 |
existing image may confuse later pixel interpretation." |
|
1465 |
||
1466 |
height := aNumber |
|
1467 |
||
1468 |
"Modified: 23.4.1996 / 11:08:40 / cg" |
|
1469 |
! |
|
1470 |
||
1471 |
photometric:aSymbol |
|
1472 |
"set the photometric interpretation of the pixel values. |
|
1473 |
The argument, aSymbol is one of: |
|
1474 |
#blackIs0, #whiteIs0, #palette, #rgb |
|
1475 |
See TIFF documentation, from which the photometric concept is borrowed. |
|
1476 |
||
1477 |
This interface is only to be used when initializing |
|
1478 |
instances or by image readers. Calling for a change of an |
|
1479 |
existing image may confuse later pixel interpretation." |
|
1480 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1481 |
|b| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1482 |
|
798 | 1483 |
photometric := aSymbol. |
1484 |
bitsPerSample isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1485 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1486 |
b := self class imageDepth // 3. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1487 |
bitsPerSample := Array with:b with:b with:b |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1488 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1489 |
bitsPerSample := Array with:(self class imageDepth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1490 |
]. |
798 | 1491 |
]. |
1492 |
samplesPerPixel isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1493 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1494 |
samplesPerPixel := 3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1495 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1496 |
samplesPerPixel := 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1497 |
] |
798 | 1498 |
]. |
1499 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1500 |
"Modified: 10.6.1996 / 18:21:29 / cg" |
592 | 1501 |
! |
1502 |
||
1503 |
samplesPerPixel:aNumber |
|
1504 |
"set the array of samples per pixel. |
|
1505 |
||
1506 |
This interface is only to be used when initializing |
|
1507 |
instances or by image readers. Calling for a change of an |
|
1508 |
existing image may confuse later pixel interpretation." |
|
1509 |
||
1510 |
samplesPerPixel := aNumber |
|
1511 |
||
1512 |
"Modified: 23.4.1996 / 11:08:45 / cg" |
|
81 | 1513 |
! |
1514 |
||
283 | 1515 |
width:aNumber |
592 | 1516 |
"set the width of the image. |
1517 |
||
1518 |
This interface is only to be used when initializing |
|
1519 |
instances or by image readers. Calling for a change of an |
|
1520 |
existing image may confuse later pixel interpretation." |
|
283 | 1521 |
|
1522 |
width := aNumber |
|
592 | 1523 |
|
1524 |
"Modified: 23.4.1996 / 11:08:48 / cg" |
|
100 | 1525 |
! |
1526 |
||
283 | 1527 |
width:w height:h |
592 | 1528 |
"set the width and height of the image. |
1529 |
||
1530 |
This interface is only to be used when initializing |
|
1531 |
instances or by image readers. Calling for a change of an |
|
1532 |
existing image may confuse later pixel interpretation." |
|
283 | 1533 |
|
1534 |
width := w. |
|
1535 |
height := h |
|
592 | 1536 |
|
1537 |
"Modified: 23.4.1996 / 11:08:53 / cg" |
|
81 | 1538 |
! |
2 | 1539 |
|
283 | 1540 |
width:w height:h depth:d |
592 | 1541 |
"set the width, height and depth of the image. |
1542 |
||
1543 |
This interface is only to be used when initializing |
|
1544 |
instances or by image readers. Calling for a change of an |
|
1545 |
existing image may confuse later pixel interpretation." |
|
283 | 1546 |
|
1547 |
width := w. |
|
1548 |
height := h. |
|
1549 |
self depth:d. |
|
592 | 1550 |
|
1551 |
"Modified: 23.4.1996 / 11:08:56 / cg" |
|
89 | 1552 |
! |
1553 |
||
283 | 1554 |
width:w height:h depth:d fromArray:bits |
592 | 1555 |
"set the width, height, depth and pixels of the image. |
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." |
|
283 | 1560 |
|
1561 |
width := w. |
|
1562 |
height := h. |
|
1563 |
self depth:d. |
|
1564 |
bytes := bits |
|
592 | 1565 |
|
1566 |
"Modified: 23.4.1996 / 11:08:59 / cg" |
|
1567 |
! |
|
1568 |
||
1569 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels |
|
1570 |
"set all relevant internal state of the image. |
|
1571 |
||
1572 |
This interface is only to be used when initializing |
|
1573 |
instances or by image readers. Calling for a change of an |
|
1574 |
existing image may confuse later pixel interpretation." |
|
1575 |
||
1576 |
width := w. |
|
1577 |
height := h. |
|
1578 |
photometric := p. |
|
1579 |
samplesPerPixel := spp. |
|
1580 |
bitsPerSample := bps. |
|
1581 |
colorMap := cm. |
|
1582 |
bytes := pixels. |
|
1583 |
||
1584 |
"Created: 23.4.1996 / 11:06:40 / cg" |
|
1585 |
"Modified: 23.4.1996 / 11:09:02 / cg" |
|
0 | 1586 |
! ! |
1587 |
||
283 | 1588 |
!Image methodsFor:'binary storage'! |
1589 |
||
1590 |
readBinaryContentsFrom: stream manager: manager |
|
1591 |
"read a binary representation of an image from stream. |
|
1592 |
Redefined to flush any device data." |
|
1593 |
||
1594 |
super readBinaryContentsFrom: stream manager: manager. |
|
1595 |
device := nil. |
|
1596 |
deviceForm := nil. |
|
1597 |
monoDeviceForm := nil. |
|
1598 |
fullColorDeviceForm := nil. |
|
0 | 1599 |
! |
1600 |
||
283 | 1601 |
storeBinaryDefinitionOn: stream manager: manager |
1602 |
"store a binary representation of the receiver on stream. |
|
592 | 1603 |
This is an internal interface for binary storage mechanism. |
283 | 1604 |
Redefined to not store the device form (which is recreated at |
1605 |
load time anyway)" |
|
1606 |
||
1607 |
|tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm| |
|
1608 |
||
1609 |
tDevice := device. |
|
1610 |
tDeviceForm := deviceForm. |
|
1611 |
tMonoDeviceForm := monoDeviceForm. |
|
1612 |
tFullColorDeviceForm := fullColorDeviceForm. |
|
1613 |
||
1614 |
device := nil. |
|
1615 |
deviceForm := nil. |
|
1616 |
monoDeviceForm := nil. |
|
1617 |
fullColorDeviceForm := nil. |
|
1618 |
||
1619 |
super storeBinaryDefinitionOn: stream manager: manager. |
|
1620 |
||
1621 |
device := tDevice. |
|
1622 |
deviceForm := tDeviceForm. |
|
1623 |
monoDeviceForm := tMonoDeviceForm. |
|
1624 |
fullColorDeviceForm := tFullColorDeviceForm. |
|
592 | 1625 |
|
1626 |
"Modified: 23.4.1996 / 09:30:50 / cg" |
|
0 | 1627 |
! ! |
1628 |
||
1629 |
!Image methodsFor:'converting'! |
|
1630 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1631 |
asBurkesDitheredMonochromeImage |
837 | 1632 |
"return a burkes dithered monochrome image from the receiver image. |
1633 |
Depending on the images contents, this may or may not look better than |
|
1634 |
a floyd-steinberg dithered image. |
|
1635 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
1636 |
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
|
1637 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1638 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1639 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1640 |
monoBits := self burkesDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1641 |
^ 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
|
1642 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1643 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1644 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1645 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1646 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1647 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1648 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1649 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1650 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1651 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1652 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1653 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1654 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1655 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1656 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1657 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1658 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1659 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1660 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1661 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1662 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1663 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1664 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1665 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1666 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1667 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1668 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1669 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1670 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1671 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1672 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1673 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1674 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1675 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1676 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1677 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1678 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1679 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1680 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1681 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1682 |
"Created: 10.6.1996 / 12:34:44 / cg" |
837 | 1683 |
"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
|
1684 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1685 |
|
283 | 1686 |
asCachedImage |
592 | 1687 |
"return the receiver associated to the current screens device. |
1688 |
For ST-80 compatibility |
|
1689 |
(ST/X uses Image for both device- and nonDevice-images)" |
|
283 | 1690 |
|
1691 |
^ self on:Screen current |
|
592 | 1692 |
|
1693 |
"Modified: 23.4.1996 / 11:10:32 / cg" |
|
0 | 1694 |
! |
1695 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1696 |
asErrorDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1697 |
"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
|
1698 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1699 |
DitherAlgorithm == #burkes ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1700 |
^ self asBurkesDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1701 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1702 |
DitherAlgorithm == #stevensonArce ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1703 |
^ self asStevensonArgceDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1704 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1705 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1706 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1707 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1708 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1709 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1710 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1711 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1712 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1713 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1714 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1715 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1716 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1717 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1718 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1719 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1720 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1721 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1722 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1723 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1724 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1725 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1726 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1727 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1728 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1729 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1730 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1731 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1732 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1733 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1734 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1735 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1736 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1737 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1738 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1739 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1740 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1741 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1742 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1743 |
"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
|
1744 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1745 |
|
854 | 1746 |
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
1747 |
"return a floyd-steinberg dithered pseudoForm from the palette picture. |
|
1748 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
|
1749 |
colors assigned to aDevice, such as the preallocated colors of the |
|
1750 |
Color class. |
|
1751 |
By passing the ditherColors as extra array, this method can |
|
1752 |
also be used to dither an 8bit image into a smaller number of colors, |
|
1753 |
for example to create dithered Depth4Images from Depth8Images." |
|
1754 |
||
1755 |
|pseudoBits f has8BitImage deviceDepth |
|
1756 |
map | |
|
1757 |
||
1758 |
deviceDepth := aDevice depth. |
|
1759 |
deviceDepth == 8 ifTrue:[ |
|
1760 |
has8BitImage := true. |
|
1761 |
] ifFalse:[ |
|
1762 |
has8BitImage := false. |
|
1763 |
aDevice supportedImageFormats do:[:fmt | |
|
1764 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
1765 |
has8BitImage := true. |
|
1766 |
] |
|
1767 |
] |
|
1768 |
]. |
|
1769 |
has8BitImage ifFalse:[^ nil]. |
|
1770 |
||
1771 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
|
1772 |
pseudoBits isNil ifTrue:[^ nil]. |
|
1773 |
||
1774 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
|
1775 |
f isNil ifTrue:[^ nil]. |
|
1776 |
||
1777 |
"/ |
|
1778 |
"/ have to create a funny colorMap, where |
|
1779 |
"/ color at:index == color colorId:index |
|
1780 |
"/ |
|
1781 |
map := Array new:256. |
|
1782 |
fixColors do:[:clr | |
|
1783 |
map at:clr colorId + 1 put:clr |
|
1784 |
]. |
|
1785 |
f colorMap:map. |
|
1786 |
f initGC. |
|
1787 |
f bits:pseudoBits. |
|
1788 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
|
1789 |
width:width height:height |
|
1790 |
x:0 y:0 |
|
1791 |
into:(f id) x:0 y:0 |
|
1792 |
width:width height:height with:(f gcId). |
|
1793 |
^ f |
|
1794 |
||
1795 |
" |
|
1796 |
example: |
|
1797 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
|
1798 |
||
1799 |
|img8 reducedImg8 img4 map form| |
|
1800 |
||
1801 |
map := #( |
|
1802 |
(0 0 0) |
|
1803 |
(0 0 100) |
|
1804 |
(0 50 0) |
|
1805 |
(0 50 100) |
|
1806 |
(0 100 0) |
|
1807 |
(0 100 100) |
|
1808 |
(100 0 0) |
|
1809 |
(100 0 100) |
|
1810 |
(100 50 0) |
|
1811 |
(100 50 100) |
|
1812 |
(100 100 0) |
|
1813 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
|
1814 |
green:(rgb at:2) |
|
1815 |
blue:(rgb at:3)) on:Display]. |
|
1816 |
||
1817 |
img8 := Image fromFile:'bitmaps/bf.im8'. |
|
1818 |
form := img8 paletteImageAsDitheredPseudoFormOn:Display |
|
1819 |
colors:map |
|
1820 |
nRed:2 |
|
1821 |
nGreen:3 |
|
1822 |
nBlue:2. |
|
1823 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
|
1824 |
img4 := Depth4Image fromImage:img8. |
|
1825 |
" |
|
1826 |
||
1827 |
"Modified: 14.6.1996 / 16:52:34 / cg" |
|
1828 |
! |
|
1829 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1830 |
asFloydSteinbergDitheredGrayFormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1831 |
"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
|
1832 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1833 |
|f depth bits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1834 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1835 |
depth := aDevice depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1836 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1837 |
"/ for monochrome, there is specialized |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1838 |
"/ monochrome dither code available |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1839 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1840 |
bits := self floydSteinbergDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1841 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1842 |
bits := self floydSteinbergDitheredBitsDepth:depth. |
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 |
|
816 | 1845 |
^ 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
|
1846 |
|
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 f| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1849 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1850 |
i := Image fromFile:'bitmaps/claus.gif'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1851 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1852 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1853 |
|
841 | 1854 |
" |
1855 |
|i f| |
|
1856 |
||
1857 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1858 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
|
1859 |
" |
|
1860 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1861 |
"Created: 10.6.1996 / 14:11:39 / cg" |
841 | 1862 |
"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
|
1863 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1864 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1865 |
asFloydSteinbergDitheredGrayImageDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1866 |
"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
|
1867 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1868 |
|ditheredBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1869 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1870 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1871 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1872 |
]. |
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 |
ditheredBits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1875 |
^ (self class implementorForDepth:depth) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1876 |
width:width height:height fromArray:ditheredBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1877 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1878 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1879 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1880 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1881 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1882 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1883 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1884 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1885 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1886 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1887 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1888 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1889 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1890 |
|
829 | 1891 |
i := Depth24Image width:4 height:1 |
1892 |
fromArray:#[ |
|
1893 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1894 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1895 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1896 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00]. |
|
1897 |
i := i magnifiedBy:4@1. |
|
1898 |
i inspect. |
|
1899 |
||
1900 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1901 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1902 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1903 |
" |
|
1904 |
||
1905 |
" |
|
1906 |
|i| |
|
1907 |
||
1908 |
i := Depth24Image width:4 height:6 |
|
1909 |
fromArray:#[ |
|
1910 |
16r00 16r00 16r00 16r00 16r00 16r80 16r00 16r00 16rff 16r00 16r80 16r00 |
|
1911 |
16r00 16r80 16r80 16r00 16rFF 16r00 16r00 16rFF 16r80 16r00 16rFF 16rFF |
|
1912 |
16r80 16r00 16r00 16r80 16r00 16r80 16r80 16r00 16rff 16r80 16r80 16r00 |
|
1913 |
16r80 16r80 16r80 16r80 16rFF 16r00 16r80 16rFF 16r80 16r80 16rFF 16rFF |
|
1914 |
16rFF 16r00 16r00 16rFF 16r00 16r80 16rFF 16r00 16rff 16rFF 16r80 16r00 |
|
1915 |
16rFF 16r80 16r80 16rFF 16rFF 16r00 16rFF 16rFF 16r80 16rFF 16rFF 16rFF]. |
|
1916 |
i := i magnifiedBy:30. |
|
1917 |
i inspect. |
|
1918 |
||
1919 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1920 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1921 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1922 |
" |
|
1923 |
" |
|
1924 |
|i| |
|
1925 |
||
1926 |
i := Image fromFile:'granite.tiff'. |
|
1927 |
i inspect. |
|
1928 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1929 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1930 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1931 |
" |
|
1932 |
||
1933 |
" |
|
1934 |
|i| |
|
1935 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1936 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1937 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1938 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1939 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1940 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1941 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1942 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1943 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1944 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1945 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1946 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1947 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1948 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1949 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1950 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1951 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1952 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1953 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1954 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1955 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1956 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1957 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1958 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1959 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1960 |
" |
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 |
"Created: 10.6.1996 / 12:33:47 / cg" |
829 | 1963 |
"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
|
1964 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1965 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1966 |
asFloydSteinbergDitheredMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1967 |
"return a dithered moncohrome form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1968 |
|
816 | 1969 |
|monoBits clr0 clr1| |
1970 |
||
1971 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
|
1972 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1973 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1974 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1975 |
|i f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1976 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1977 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1978 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1979 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1980 |
|
816 | 1981 |
" |
1982 |
|i f| |
|
1983 |
||
1984 |
i := Depth2Image width:8 height:8 |
|
1985 |
fromArray:#[ |
|
1986 |
4r0000 4r0000 |
|
1987 |
4r0000 4r0000 |
|
1988 |
4r1111 4r1111 |
|
1989 |
4r1111 4r1111 |
|
1990 |
4r2222 4r2222 |
|
1991 |
4r2222 4r2222 |
|
1992 |
4r3333 4r3333 |
|
1993 |
4r3333 4r3333 |
|
1994 |
]. |
|
1995 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
|
1996 |
" |
|
1997 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1998 |
"Created: 10.6.1996 / 14:11:39 / cg" |
816 | 1999 |
"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
|
2000 |
! |
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 |
asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2003 |
"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
|
2004 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2005 |
|monoBits| |
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 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2008 |
^ 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
|
2009 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2010 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2011 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2012 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2013 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2014 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2015 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2016 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2017 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2018 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2019 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2020 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2021 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2022 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2023 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2024 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2025 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2026 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2027 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2028 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2029 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2030 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2031 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2032 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2033 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2034 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2035 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2036 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2037 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2038 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2039 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2040 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2041 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2042 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2043 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2044 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2045 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2046 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2047 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2048 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2049 |
"Created: 10.6.1996 / 12:33:47 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2050 |
"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
|
2051 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2052 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2053 |
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2054 |
"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
|
2055 |
using colors in colors for dithering." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2056 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2057 |
|pseudoBits f has8BitImage deviceDepth |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2058 |
map | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2059 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2060 |
deviceDepth := aDevice depth. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2061 |
deviceDepth == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2062 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2063 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2064 |
has8BitImage := false. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2065 |
aDevice supportedImageFormats do:[:fmt | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2066 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2067 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2068 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2069 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2070 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2071 |
has8BitImage ifFalse:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2072 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2073 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:colors. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2074 |
pseudoBits isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2075 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2076 |
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
|
2077 |
f isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2078 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2079 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2080 |
"/ have to create a funny colorMap, where |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2081 |
"/ color at:index == color colorId:index |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2082 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2083 |
map := Array new:256 withAll:0. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2084 |
colors do:[:clr | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2085 |
clr notNil ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2086 |
map at:clr colorId + 1 put:clr |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2087 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2088 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2089 |
f colorMap:map. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2090 |
f initGC. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2091 |
f bits:pseudoBits. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2092 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2093 |
width:width height:height |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2094 |
x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2095 |
into:(f id) x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2096 |
width:width height:height with:(f gcId). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2097 |
^ f |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2098 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2099 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2100 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2101 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2102 |
i := Image fromFile:'bitmaps/garfield.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2103 |
(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
|
2104 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2105 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2106 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2107 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2108 |
i := Image fromFile:'bitmaps/claus.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2109 |
(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
|
2110 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2111 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2112 |
"Created: 17.6.1996 / 12:13:35 / cg" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2113 |
"Modified: 17.6.1996 / 12:45:21 / cg" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2114 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2115 |
|
0 | 2116 |
asFormOn:aDevice |
72 | 2117 |
"get a device form, with best possible approximation. |
2118 |
remember it in case someone asks again." |
|
2119 |
||
2120 |
|form| |
|
2121 |
||
2122 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
|
0 | 2123 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2124 |
aDevice depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2125 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2126 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2127 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2128 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2129 |
^ self asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2130 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2131 |
|
873 | 2132 |
(aDevice visualType == #PseudoColor) ifTrue:[ |
2133 |
form := self asPseudoFormQuickOn:aDevice. |
|
2134 |
form notNil ifTrue:[ |
|
2135 |
^ form |
|
2136 |
]. |
|
2137 |
]. |
|
2138 |
||
0 | 2139 |
(photometric == #palette) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2140 |
form := self paletteImageAsFormOn:aDevice |
72 | 2141 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2142 |
(photometric == #rgb) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2143 |
form := self rgbImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2144 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2145 |
form := self greyImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2146 |
] |
0 | 2147 |
]. |
2148 |
||
72 | 2149 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2150 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2151 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2152 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2153 |
deviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2154 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2155 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2156 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2157 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2158 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2159 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2160 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2161 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2162 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2163 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2164 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2165 |
] |
0 | 2166 |
]. |
2167 |
||
72 | 2168 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2169 |
|
873 | 2170 |
"Modified: 17.6.1996 / 10:41:02 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2171 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2172 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2173 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2174 |
"get a gray device form" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2175 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2176 |
^ self asGrayFormOn:aDevice dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2177 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2178 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2179 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2180 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2181 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2182 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2183 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2184 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2185 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2186 |
"Created: 10.6.1996 / 18:44:42 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2187 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2188 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2189 |
asGrayFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2190 |
"get a greyscale device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2191 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2192 |
|grayBits depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2193 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2194 |
depth := aDevice depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2195 |
depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2196 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2197 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2198 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2199 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2200 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2201 |
^ self asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2202 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2203 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2204 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2205 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2206 |
^ self asOrderedDitheredGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2207 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2208 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2209 |
^ self asFloydSteinbergDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2210 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2211 |
"Created: 10.6.1996 / 18:42:01 / cg" |
852 | 2212 |
"Modified: 14.6.1996 / 15:17:28 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2213 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2214 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2215 |
asGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2216 |
"get a gray image from the receiver" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2217 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2218 |
^ self asGrayImageDepth:depth dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2219 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2220 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2221 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2222 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2223 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2224 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2225 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2226 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2227 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2228 |
"Created: 10.6.1996 / 19:07:08 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2229 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2230 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2231 |
asGrayImageDepth:depth dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2232 |
"get a greyscale image, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2233 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2234 |
|grayBits| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2235 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2236 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2237 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2238 |
^ self asThresholdGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2239 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2240 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2241 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2242 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2243 |
^ self asOrderedDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2244 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2245 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2246 |
^ self asFloydSteinbergDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2247 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2248 |
"Created: 10.6.1996 / 19:08:21 / cg" |
0 | 2249 |
! |
2250 |
||
2251 |
asMonochromeFormOn:aDevice |
|
2252 |
"get a monochrome device form" |
|
2253 |
||
72 | 2254 |
|form| |
2255 |
||
2256 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm]. |
|
2257 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2258 |
form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm. |
0 | 2259 |
|
72 | 2260 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2261 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2262 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2263 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2264 |
monoDeviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2265 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2266 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2267 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2268 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2269 |
Lobby registerChange:self |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2272 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2273 |
twice (here and in the device form) |
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 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2276 |
] |
0 | 2277 |
]. |
2278 |
||
72 | 2279 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2280 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2281 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2282 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2283 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2284 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2285 |
(i asMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2286 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2287 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2288 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2289 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2290 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2291 |
asMonochromeFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2292 |
"get a monochrome device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2293 |
|
816 | 2294 |
|monoBits clr0 clr1 mustInvert| |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2295 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2296 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2297 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2298 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2299 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2300 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2301 |
aDitherAlgorithm == #burkes ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2302 |
monoBits := self burkesDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2303 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2304 |
aDitherAlgorithm == #stevensonArce ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2305 |
monoBits := self stevensonArceDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2306 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2307 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2308 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2309 |
^ self asOrderedDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2310 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2311 |
^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2312 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2313 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2314 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2315 |
|
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 |
"/ make its pixel interpretation correct for the device |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2318 |
"/ |
816 | 2319 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
2320 |
||
2321 |
"Modified: 10.6.1996 / 20:18:05 / cg" |
|
89 | 2322 |
! |
2323 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2324 |
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
|
2325 |
"return a nearest paint pseudoForm from the palette picture. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2326 |
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
|
2327 |
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
|
2328 |
Color class. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2329 |
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
|
2330 |
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
|
2331 |
for example to create dithered Depth4Images from Depth8Images." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2332 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2333 |
|pseudoBits f has8BitImage deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2334 |
map | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2335 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2336 |
deviceDepth := aDevice depth. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2337 |
deviceDepth == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2338 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2339 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2340 |
has8BitImage := false. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2341 |
aDevice supportedImageFormats do:[:fmt | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2342 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2343 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2344 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2345 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2346 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2347 |
has8BitImage ifFalse:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2348 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2349 |
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
|
2350 |
pseudoBits isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2351 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2352 |
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
|
2353 |
f isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2354 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2355 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2356 |
"/ have to create a funny colorMap, where |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2357 |
"/ color at:index == color colorId:index |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2358 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2359 |
map := Array new:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2360 |
fixColors do:[:clr | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2361 |
map at:clr colorId + 1 put:clr |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2362 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2363 |
f colorMap:map. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2364 |
f initGC. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2365 |
f bits:pseudoBits. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2366 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2367 |
width:width height:height |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2368 |
x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2369 |
into:(f id) x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2370 |
width:width height:height with:(f gcId). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2371 |
^ f |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2372 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2373 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2374 |
example: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2375 |
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
|
2376 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2377 |
|img8 reducedImg8 img4 map form| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2378 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2379 |
map := #( |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2380 |
(0 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2381 |
(0 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2382 |
(0 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2383 |
(0 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2384 |
(0 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2385 |
(0 100 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2386 |
(100 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2387 |
(100 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2388 |
(100 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2389 |
(100 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2390 |
(100 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2391 |
(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
|
2392 |
green:(rgb at:2) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2393 |
blue:(rgb at:3)) on:Display]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2394 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2395 |
img8 := Image fromFile:'bitmaps/claus.gif'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2396 |
form := img8 asNearestPaintDepth8FormOn:Display |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2397 |
colors:map |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2398 |
nRed:2 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2399 |
nGreen:3 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2400 |
nBlue:2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2401 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2402 |
img4 := Depth4Image fromImage:img8. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2403 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2404 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2405 |
"Created: 17.6.1996 / 18:47:46 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2406 |
"Modified: 17.6.1996 / 18:52:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2407 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2408 |
|
808 | 2409 |
asOrderedDitheredGrayFormOn:aDevice |
2410 |
"return a dithered depth-x grey form from the receiver image. |
|
2411 |
Uses an 8x8 dithermatrix." |
|
2412 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2413 |
|f depth bits| |
808 | 2414 |
|
2415 |
depth := aDevice depth. |
|
2416 |
depth == 1 ifTrue:[ |
|
2417 |
"/ for monochrome, there is highly specialized |
|
2418 |
"/ monochrome dither code available |
|
2419 |
||
2420 |
^ self asOrderedDitheredMonochromeFormOn:aDevice |
|
2421 |
]. |
|
2422 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2423 |
bits := self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2424 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
808 | 2425 |
ditherWidth:8 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2426 |
depth:depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2427 |
|
816 | 2428 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2429 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2430 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2431 |
|i| |
808 | 2432 |
|
2433 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2434 |
(i asOrderedDitheredGrayFormOn:Display) inspect |
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 |
|
816 | 2437 |
"Modified: 10.6.1996 / 20:10:07 / cg" |
808 | 2438 |
! |
2439 |
||
798 | 2440 |
asOrderedDitheredGrayImageDepth:depth |
2441 |
"return a dithered depth-x grey image from the receiver image. |
|
2442 |
Uses an 8x8 dithermatrix." |
|
2443 |
||
2444 |
|dither| |
|
2445 |
||
2446 |
dither := self class orderedDitherMatrixOfSize:8. |
|
2447 |
||
2448 |
depth == 1 ifTrue:[ |
|
2449 |
"/ for monochrome, there is highly specialized |
|
2450 |
"/ monochrome dither code available |
|
2451 |
||
2452 |
^ Depth1Image |
|
2453 |
width:width |
|
2454 |
height:height |
|
2455 |
fromArray:( |
|
2456 |
self |
|
2457 |
orderedDitheredMonochromeBitsWithDitherMatrix:dither |
|
2458 |
ditherWidth:8) |
|
2459 |
]. |
|
2460 |
||
2461 |
^ (self class implementorForDepth:depth) |
|
2462 |
width:width |
|
2463 |
height:height |
|
2464 |
fromArray:( |
|
2465 |
self |
|
2466 |
orderedDitheredBitsWithDitherMatrix:dither |
|
2467 |
ditherWidth:8 |
|
2468 |
depth:depth) |
|
2469 |
||
2470 |
" |
|
2471 |
|i i1 i2 i4 i8| |
|
2472 |
||
2473 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2474 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2475 |
i1 inspect. |
|
2476 |
||
2477 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2478 |
i2 inspect. |
|
2479 |
||
2480 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2481 |
i4 inspect. |
|
2482 |
||
2483 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2484 |
i8 inspect. |
|
2485 |
" |
|
2486 |
||
2487 |
" |
|
2488 |
|i i1 i2 i4 i8| |
|
2489 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2490 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2491 |
i1 inspect. |
|
2492 |
||
2493 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2494 |
i2 inspect. |
|
2495 |
||
2496 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2497 |
i4 inspect. |
|
2498 |
||
2499 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2500 |
i8 inspect. |
|
800 | 2501 |
|
2502 |
i2 := i8 asOrderedDitheredGrayImageDepth:2. |
|
2503 |
i2 inspect. |
|
798 | 2504 |
" |
2505 |
||
2506 |
"Created: 7.6.1996 / 18:03:54 / cg" |
|
800 | 2507 |
"Modified: 7.6.1996 / 19:41:59 / cg" |
798 | 2508 |
! |
2509 |
||
2510 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2511 |
"return a dithered monochrome form from the grey image. |
|
2512 |
Uses a 4x4 dithermatrix." |
|
2513 |
||
2514 |
"/ 4x4 seems a good comprimize between: |
|
2515 |
"/ number of grey levels (8x8 is better) |
|
2516 |
"/ artifacts (4x4 is better) |
|
2517 |
"/ |
|
2518 |
"/ could look at the image and decide upon the number of |
|
2519 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2520 |
"/ 4x4 for small number of colors ... |
|
2521 |
||
2522 |
^ self |
|
2523 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2524 |
ditherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2525 |
ditherWidth:4 |
|
2526 |
||
2527 |
"/ ^ self |
|
2528 |
"/ asOrderedDitheredMonochromeFormOn:aDevice |
|
2529 |
"/ ditherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2530 |
"/ ditherWidth:8 |
|
2531 |
||
2532 |
" |
|
2533 |
|i f| |
|
2534 |
||
2535 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2536 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2537 |
||
2538 |
||
2539 |
|i f| |
|
2540 |
||
2541 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2542 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2543 |
||
2544 |
||
2545 |
|i f| |
|
2546 |
||
2547 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2548 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2549 |
||
2550 |
||
2551 |
|i f| |
|
2552 |
||
2553 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2554 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2555 |
||
2556 |
||
2557 |
|i f| |
|
2558 |
||
2559 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
2560 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2561 |
" |
|
2562 |
||
2563 |
"Created: 7.6.1996 / 14:52:32 / cg" |
|
2564 |
"Modified: 7.6.1996 / 16:37:47 / cg" |
|
2565 |
! |
|
2566 |
||
2567 |
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW |
|
2568 |
"return a dithered monochrome form from the image. |
|
2569 |
Uses the passed ditherMatrix and ditherWidth." |
|
2570 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2571 |
|monoBits clr0 clr1| |
798 | 2572 |
|
2573 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
816 | 2574 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
813
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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2577 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2578 |
|i| |
798 | 2579 |
|
2580 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2581 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2582 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2583 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2584 |
|i| |
798 | 2585 |
|
2586 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2587 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2588 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2589 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2590 |
|i| |
798 | 2591 |
|
2592 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2593 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
798 | 2594 |
" |
2595 |
||
2596 |
"Created: 7.6.1996 / 14:51:42 / cg" |
|
816 | 2597 |
"Modified: 10.6.1996 / 20:18:07 / cg" |
798 | 2598 |
! |
2599 |
||
2600 |
asOrderedDitheredMonochromeImage |
|
2601 |
"return a dithered monochrome image from the receiver image. |
|
2602 |
Uses a 4x4 dithermatrix." |
|
2603 |
||
2604 |
"/ 4x4 seems a good comprimize between: |
|
2605 |
"/ number of grey levels (8x8 is better) |
|
2606 |
"/ artifacts (4x4 is better) |
|
2607 |
"/ |
|
2608 |
"/ could look at the image and decide upon the number of |
|
2609 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2610 |
"/ 4x4 for small number of colors ... |
|
2611 |
||
2612 |
^ self |
|
2613 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2614 |
ditherWidth:4 |
|
2615 |
||
2616 |
"/ ^ self |
|
2617 |
"/ asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2618 |
"/ ditherWidth:8 |
|
2619 |
||
2620 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2621 |
|i| |
798 | 2622 |
|
2623 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2624 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2625 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2626 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2627 |
|i| |
798 | 2628 |
|
2629 |
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
|
2630 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2631 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2632 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2633 |
|i| |
798 | 2634 |
|
2635 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2636 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2637 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2638 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2639 |
|i| |
798 | 2640 |
|
2641 |
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
|
2642 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2643 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2644 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2645 |
|i| |
798 | 2646 |
|
2647 |
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
|
2648 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2649 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2650 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2651 |
|i| |
798 | 2652 |
|
2653 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2654 |
i asOrderedDitheredMonochromeImage inspect |
798 | 2655 |
" |
2656 |
||
2657 |
"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
|
2658 |
"Modified: 10.6.1996 / 11:15:09 / cg" |
798 | 2659 |
! |
2660 |
||
2661 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
2662 |
"return a dithered monochrome image from the receiver image. |
|
2663 |
Uses the passed ditherMatrix and ditherWidth." |
|
2664 |
||
2665 |
|monoBits| |
|
2666 |
||
2667 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
2668 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
|
2669 |
||
2670 |
"order-4 dither: |
|
2671 |
||
2672 |
|i| |
|
2673 |
||
2674 |
i := Image fromFile:'garfield.gif'. |
|
2675 |
i |
|
2676 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4) |
|
2677 |
ditherWidth:4 |
|
2678 |
" |
|
2679 |
||
2680 |
"order-6 dither: |
|
2681 |
||
2682 |
|i| |
|
2683 |
||
2684 |
i := Image fromFile:'garfield.gif'. |
|
2685 |
i |
|
2686 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8) |
|
2687 |
ditherWidth:8 |
|
2688 |
" |
|
2689 |
||
2690 |
||
2691 |
"thresholding at:0.5 (all above 0.5 becomes white): |
|
2692 |
||
2693 |
|i| |
|
2694 |
||
2695 |
i := Image fromFile:'garfield.gif'. |
|
2696 |
i |
|
2697 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8) |
|
2698 |
ditherWidth:4 |
|
2699 |
" |
|
2700 |
||
2701 |
"thresholding at: 0.25 (all above 0.25 becomes white): |
|
2702 |
||
2703 |
|i| |
|
2704 |
||
2705 |
i := Image fromFile:'garfield.gif'. |
|
2706 |
i |
|
2707 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3) |
|
2708 |
ditherWidth:4 |
|
2709 |
" |
|
2710 |
||
2711 |
"thresholding at: 0.75 (all above 0.75 becomes white): |
|
2712 |
||
2713 |
|i| |
|
2714 |
||
2715 |
i := Image fromFile:'garfield.gif'. |
|
2716 |
i |
|
2717 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11) |
|
2718 |
ditherWidth:4 |
|
2719 |
" |
|
2720 |
||
2721 |
"Modified: 7.6.1996 / 17:23:47 / cg" |
|
2722 |
! |
|
2723 |
||
873 | 2724 |
asPseudoFormQuickOn:aDevice |
2725 |
"return a pseudo-deviceForm from the image. |
|
878 | 2726 |
Fail if any color is not available (i.e. do not dither)." |
873 | 2727 |
|
2728 |
|f d dDev temp temp8 bits anyMissing clr cMap idMap |
|
878 | 2729 |
nClr "{ Class: SmallInteger }" |
2730 |
usedColors | |
|
873 | 2731 |
|
2732 |
d := self depth. |
|
2733 |
(d == 1 |
|
2734 |
or:[d == 2 |
|
2735 |
or:[d == 4 |
|
2736 |
or:[d == 8]]]) ifFalse:[^ nil]. |
|
2737 |
||
2738 |
"/ |
|
2739 |
"/ see if all of the images colors are representable |
|
2740 |
"/ on the device |
|
2741 |
||
2742 |
bits := self bitsPerPixel. |
|
2743 |
nClr := (1 bitShift:bits). |
|
2744 |
cMap := Array new:nClr. |
|
2745 |
idMap := ByteArray new:nClr. |
|
2746 |
||
2747 |
photometric == #palette ifTrue:[ |
|
2748 |
nClr := nClr min:(colorMap size) |
|
2749 |
]. |
|
2750 |
||
878 | 2751 |
d == 8 ifTrue:[ |
2752 |
usedColors := bytes usedValues. "gets us an array filled with used values" |
|
2753 |
1 to:nClr do:[:pixel | |
|
2754 |
(usedColors includes:(pixel - 1)) ifFalse:[ |
|
2755 |
clr := Color black |
|
2756 |
] ifTrue:[ |
|
2757 |
clr := self colorFromValue:pixel-1. |
|
2758 |
clr := clr exactOn:aDevice. |
|
2759 |
clr isNil ifTrue:[^ nil]. |
|
2760 |
]. |
|
2761 |
cMap at:(pixel) put:clr. |
|
2762 |
idMap at:(pixel) put:(clr colorId). |
|
2763 |
]. |
|
2764 |
] ifFalse:[ |
|
2765 |
1 to:nClr do:[:pixel | |
|
2766 |
clr := self colorFromValue:pixel-1. |
|
2767 |
clr := clr exactOn:aDevice. |
|
2768 |
clr isNil ifTrue:[^ nil]. |
|
2769 |
||
2770 |
cMap at:(pixel) put:clr. |
|
2771 |
idMap at:(pixel) put:(clr colorId). |
|
2772 |
]. |
|
873 | 2773 |
]. |
2774 |
||
2775 |
"/ got all colors; good - simply change depth & translate pixels |
|
2776 |
||
2777 |
dDev := aDevice depth. |
|
2778 |
||
2779 |
(d == 8 and:[dDev == 8]) ifTrue:[ |
|
2780 |
"/ only translate |
|
2781 |
temp := ByteArray uninitializedNew:(width * height). |
|
2782 |
bytes expandPixels:8 "xlate only" |
|
2783 |
width:width |
|
2784 |
height:height |
|
2785 |
into:temp |
|
2786 |
mapping:idMap. |
|
2787 |
] ifFalse:[ |
|
2788 |
||
2789 |
"/ stupid: expandPixels can only handle any-to-8 |
|
2790 |
"/ compressPixels can only handle 8-to-any |
|
2791 |
||
2792 |
d ~~ 8 ifTrue:[ |
|
2793 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
2794 |
||
2795 |
bytes expandPixels:d |
|
2796 |
width:width |
|
2797 |
height:height |
|
2798 |
into:temp8 |
|
2799 |
mapping:idMap. |
|
2800 |
idMap := nil. |
|
2801 |
] ifFalse:[ |
|
2802 |
temp8 := bytes. |
|
2803 |
]. |
|
2804 |
||
2805 |
dDev ~~ 8 ifTrue:[ |
|
2806 |
temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height). |
|
2807 |
||
2808 |
temp8 compressPixels:dDev |
|
2809 |
width:width |
|
2810 |
height:height |
|
2811 |
into:temp |
|
2812 |
mapping:idMap. |
|
2813 |
] ifFalse:[ |
|
2814 |
temp := temp8 |
|
2815 |
]. |
|
2816 |
]. |
|
2817 |
||
2818 |
f := Form width:width height:height depth:dDev on:aDevice. |
|
2819 |
f isNil ifTrue:[^ nil]. |
|
2820 |
||
2821 |
f colorMap:cMap. |
|
2822 |
f initGC. |
|
2823 |
||
2824 |
aDevice |
|
2825 |
drawBits:temp |
|
2826 |
depth:dDev |
|
2827 |
width:width |
|
2828 |
height:height |
|
2829 |
x:0 y:0 |
|
2830 |
into:(f id) x:0 y:0 |
|
2831 |
width:width |
|
2832 |
height:height |
|
2833 |
with:(f gcId). |
|
2834 |
||
2835 |
^ f |
|
2836 |
||
2837 |
" |
|
2838 |
( |
|
2839 |
(((Depth4Image |
|
2840 |
width:4 |
|
2841 |
height:4 |
|
2842 |
fromArray:#[ |
|
2843 |
16r01 16r23 |
|
2844 |
16r45 16r67 |
|
2845 |
16r89 16rab |
|
2846 |
16rcd 16ref |
|
2847 |
])) |
|
2848 |
magnifiedBy:30 |
|
2849 |
) |
|
2850 |
asPseudoFormQuickOn:Display |
|
2851 |
) inspect |
|
2852 |
" |
|
2853 |
||
878 | 2854 |
"Modified: 17.6.1996 / 17:31:49 / cg" |
873 | 2855 |
! |
2856 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2857 |
asStevensonArceDitheredMonochromeImage |
837 | 2858 |
"return a stevenson-arce dithered monochrome image from the receiver image. |
2859 |
Depending on the images contents, this may or may not look better than |
|
2860 |
a floyd-steinberg dithered image. |
|
2861 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
2862 |
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
|
2863 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2864 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2865 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2866 |
monoBits := self stevensonArceDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2867 |
^ (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
|
2868 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2869 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2870 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2871 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2872 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2873 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2874 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2875 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2876 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2877 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2878 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2879 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2880 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2881 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2882 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2883 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2884 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2885 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2886 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2887 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2888 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2889 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2890 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2891 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2892 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2893 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2894 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2895 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2896 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2897 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2898 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2899 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2900 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2901 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2902 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2903 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2904 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2905 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2906 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2907 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2908 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2909 |
"Created: 10.6.1996 / 12:38:29 / cg" |
837 | 2910 |
"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
|
2911 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2912 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2913 |
asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2914 |
"return a thresholded grey form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2915 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2916 |
|depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2917 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2918 |
(depth := aDevice depth) == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2919 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2920 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2921 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2922 |
^ self |
816 | 2923 |
makeDeviceGrayPixmapOn:aDevice |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2924 |
depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2925 |
fromArray:(self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2926 |
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
|
2927 |
ditherWidth:4 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2928 |
depth:depth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2929 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2930 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2931 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2932 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2933 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2934 |
(i asThresholdGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2935 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2936 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2937 |
"Created: 10.6.1996 / 18:38:31 / cg" |
816 | 2938 |
"Modified: 10.6.1996 / 20:10:26 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2939 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2940 |
|
798 | 2941 |
asThresholdGrayImageDepth:depth |
2942 |
"return a thresholded depth-x grey image from the receiver image." |
|
2943 |
||
800 | 2944 |
depth == 1 ifTrue:[ |
2945 |
"/ for monochrome, there is highly specialized |
|
2946 |
"/ monochrome dither code available |
|
2947 |
||
2948 |
^ Depth1Image |
|
2949 |
width:width |
|
2950 |
height:height |
|
2951 |
fromArray:( |
|
2952 |
self |
|
2953 |
orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2954 |
ditherWidth:4) |
|
2955 |
]. |
|
2956 |
||
798 | 2957 |
^ (self class implementorForDepth:depth) |
2958 |
width:width |
|
2959 |
height:height |
|
2960 |
fromArray:( |
|
2961 |
self |
|
2962 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2963 |
ditherWidth:4 |
|
2964 |
depth:depth) |
|
2965 |
||
2966 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2967 |
|i| |
798 | 2968 |
|
2969 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2970 |
(i asThresholdGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2971 |
(i asThresholdGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2972 |
(i asThresholdGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2973 |
(i asThresholdGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2974 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2975 |
(i asOrderedDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2976 |
(i asOrderedDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2977 |
(i asOrderedDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2978 |
(i asOrderedDitheredGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2979 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2980 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2981 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2982 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2983 |
(i asFloydSteinbergDitheredGrayImageDepth:8) inspect. |
798 | 2984 |
" |
2985 |
||
2986 |
"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
|
2987 |
"Modified: 10.6.1996 / 14:20:56 / cg" |
798 | 2988 |
! |
2989 |
||
2990 |
asThresholdMonochromeFormOn:aDevice |
|
2991 |
"return a threshold monochrome form from the image." |
|
2992 |
||
2993 |
^ self |
|
2994 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2995 |
ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2996 |
ditherWidth:4 |
|
2997 |
||
2998 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2999 |
|i| |
798 | 3000 |
|
3001 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3002 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3003 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3004 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3005 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3006 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3007 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3008 |
i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3009 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3010 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3011 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3012 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3013 |
|i| |
798 | 3014 |
|
3015 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3016 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3017 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3018 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3019 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3020 |
|i| |
798 | 3021 |
|
3022 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3023 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3024 |
(i asThresholdMonochromeFormOn:Display) inspect |
798 | 3025 |
" |
3026 |
||
3027 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3028 |
"Modified: 10.6.1996 / 17:44:29 / cg" |
798 | 3029 |
! |
3030 |
||
3031 |
asThresholdMonochromeImage |
|
3032 |
"return a threshold monochrome image from the image. |
|
3033 |
Threshold means: brightness < 0.5 -> black / otherwise white" |
|
3034 |
||
3035 |
^ self |
|
3036 |
asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3037 |
ditherWidth:4 |
|
3038 |
||
3039 |
" |
|
3040 |
|i i2| |
|
3041 |
||
3042 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3043 |
i2 := i asThresholdMonochromeImage |
|
3044 |
||
3045 |
||
3046 |
|i i2| |
|
3047 |
||
3048 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
3049 |
i2 := i asThresholdMonochromeImage |
|
3050 |
||
3051 |
||
3052 |
|i i2| |
|
3053 |
||
3054 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
3055 |
i2 := i asThresholdMonochromeImage |
|
3056 |
||
3057 |
||
3058 |
|i i2| |
|
3059 |
||
3060 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
3061 |
i2 := i asThresholdMonochromeImage |
|
3062 |
" |
|
3063 |
||
3064 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3065 |
"Modified: 7.6.1996 / 17:16:10 / cg" |
|
3066 |
! |
|
3067 |
||
808 | 3068 |
asThresholdMonochromeImage:thresholdBrighness |
3069 |
"return a threshold monochrome image from the image. |
|
3070 |
The argument (0..1) gives the threshold value; |
|
3071 |
Threshold means: brightness < threshold -> black / otherwise white" |
|
3072 |
||
3073 |
|value ditherMatrix| |
|
3074 |
||
3075 |
value := thresholdBrighness * 255. |
|
3076 |
ditherMatrix := ByteArray new:256 withAll:(value truncated). |
|
3077 |
||
3078 |
^ self |
|
3079 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix |
|
3080 |
ditherWidth:16 |
|
3081 |
||
3082 |
" |
|
3083 |
|i| |
|
3084 |
||
3085 |
i := Image width:4 height:4 depth:4 |
|
3086 |
fromArray:#[ 16r01 16r23 |
|
3087 |
16r45 16r67 |
|
3088 |
16r89 16rab |
|
3089 |
16rcd 16ref ]. |
|
3090 |
i := i magnifiedBy:30. |
|
3091 |
i inspect. |
|
3092 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3093 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3094 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3095 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3096 |
(i asThresholdMonochromeImage:1) inspect. |
|
3097 |
" |
|
3098 |
||
3099 |
" |
|
3100 |
|i| |
|
3101 |
||
3102 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3103 |
i inspect. |
|
3104 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3105 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3106 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3107 |
(i asThresholdMonochromeImage:0.625) inspect. |
|
3108 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3109 |
" |
|
3110 |
||
3111 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3112 |
"Modified: 8.6.1996 / 14:51:57 / cg" |
|
3113 |
! |
|
3114 |
||
283 | 3115 |
fromForm:aForm |
592 | 3116 |
"setup the receiver from a form" |
283 | 3117 |
|
3118 |
|map c0 c1| |
|
3119 |
||
3120 |
width := aForm width. |
|
3121 |
height := aForm height. |
|
3122 |
bytes := aForm bits. |
|
3123 |
bitsPerSample := self bitsPerSample. |
|
3124 |
samplesPerPixel := self samplesPerPixel. |
|
3125 |
map := aForm colorMap. |
|
3126 |
||
3127 |
aForm depth == 1 ifTrue:[ |
|
592 | 3128 |
map isNil ifTrue:[ |
3129 |
photometric := #whiteIs0 |
|
3130 |
] ifFalse:[ |
|
3131 |
c0 := map at:1. |
|
3132 |
c1 := map at:2. |
|
3133 |
((c0 = Color white) |
|
3134 |
and:[c1 = Color black]) ifTrue:[ |
|
3135 |
photometric := #whiteIs0 |
|
3136 |
] ifFalse:[ |
|
3137 |
((c0 = Color black) |
|
3138 |
and:[c1 = Color white]) ifTrue:[ |
|
3139 |
photometric := #blackIs0 |
|
3140 |
] ifFalse:[ |
|
3141 |
photometric := #palette. |
|
3142 |
colorMap := Array with:c0 with:c1. |
|
3143 |
] |
|
3144 |
] |
|
3145 |
] |
|
283 | 3146 |
] ifFalse:[ |
592 | 3147 |
map notNil ifTrue:[ |
3148 |
photometric := #palette. |
|
3149 |
colorMap := map copy. |
|
3150 |
] ifFalse:[ |
|
3151 |
" |
|
3152 |
photometric stays at default |
|
3153 |
(which is rgb for d24, greyscale for others) |
|
3154 |
" |
|
3155 |
] |
|
283 | 3156 |
]. |
592 | 3157 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3158 |
"Modified: 8.6.1996 / 16:02:03 / cg" |
283 | 3159 |
! |
3160 |
||
89 | 3161 |
fromImage:anImage |
3162 |
"setup the receiver from another image. |
|
3163 |
Color precision may be lost, if conversion is from a higher depth |
|
191 | 3164 |
image. |
3165 |
WARNING: |
|
3166 |
This implementation is a slow fallback (the loop over the |
|
89 | 3167 |
source pixels is very slow). If this method is used heavily, you |
3168 |
may want to redefine it in concrete subclasses for common source images." |
|
3169 |
||
3170 |
width := anImage width. |
|
3171 |
height := anImage height. |
|
3172 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3173 |
bitsPerSample := self bitsPerSample. |
|
3174 |
samplesPerPixel := self samplesPerPixel. |
|
191 | 3175 |
self colormapFromImage:anImage. |
89 | 3176 |
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr | |
798 | 3177 |
self atX:x y:y put:clr |
89 | 3178 |
]. |
3179 |
||
3180 |
" |
|
798 | 3181 |
|i i2 i4 i8 i16 i24| |
89 | 3182 |
|
3183 |
i := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
3184 |
i inspect. |
|
3185 |
i2 := Depth2Image fromImage:i. |
|
3186 |
i2 inspect. |
|
3187 |
i4 := Depth4Image fromImage:i. |
|
3188 |
i4 inspect. |
|
3189 |
i8 := Depth8Image fromImage:i. |
|
3190 |
i8 inspect. |
|
3191 |
i24 := Depth24Image fromImage:i. |
|
3192 |
i24 inspect. |
|
3193 |
" |
|
191 | 3194 |
|
3195 |
"Created: 20.9.1995 / 00:59:03 / claus" |
|
798 | 3196 |
"Modified: 7.6.1996 / 16:23:03 / cg" |
191 | 3197 |
! |
3198 |
||
3199 |
fromSubImage:anImage in:aRectangle |
|
3200 |
"setup the receiver from another image, extracting a rectangular |
|
3201 |
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
|
3202 |
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
|
3203 |
represented. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3204 |
|
191 | 3205 |
WARNING: |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3206 |
This implementation is a slow fallback (the loop over the |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3207 |
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
|
3208 |
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
|
3209 |
of creating a subImage with the same depth & palette." |
191 | 3210 |
|
3211 |
|x0 y0| |
|
3212 |
||
3213 |
width := aRectangle width + 1. |
|
3214 |
height := aRectangle height + 1. |
|
3215 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3216 |
bitsPerSample := self bitsPerSample. |
|
3217 |
samplesPerPixel := self samplesPerPixel. |
|
3218 |
self colormapFromImage:anImage. |
|
3219 |
x0 := aRectangle left. |
|
3220 |
y0 := aRectangle top. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3221 |
|
191 | 3222 |
((photometric == anImage photometric) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3223 |
and:[self bitsPerPixel = anImage bitsPerPixel |
191 | 3224 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3225 |
"/ can do it by value |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3226 |
anImage valuesFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3227 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3228 |
do:[:x :y :pixelValue | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3229 |
self atX:x-x0 y:y-y0 putValue:pixelValue. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3230 |
] |
191 | 3231 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3232 |
"/ must do it by colors |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3233 |
anImage colorsFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3234 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3235 |
do:[:x :y :clr | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3236 |
self atX:x-x0 y:y-y0 put:clr. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3237 |
] |
191 | 3238 |
]. |
3239 |
||
3240 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3241 |
|i i2 i4 i8 i16 i24| |
191 | 3242 |
|
3243 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3244 |
i inspect. |
|
3245 |
i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200). |
|
3246 |
i4 inspect. |
|
3247 |
i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200). |
|
3248 |
i8 inspect. |
|
3249 |
i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200). |
|
3250 |
i24 inspect. |
|
3251 |
" |
|
3252 |
||
3253 |
"Created: 20.9.1995 / 01:06:02 / claus" |
|
3254 |
"Modified: 20.9.1995 / 10:15:37 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3255 |
"Modified: 10.6.1996 / 18:30:17 / cg" |
89 | 3256 |
! |
3257 |
||
283 | 3258 |
monochromeOn:aDevice |
3259 |
"return a monochrome device image of the receiver for aDevice. |
|
3260 |
(monochrome, even if device supports colors)" |
|
3261 |
||
3262 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self]. |
|
3263 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
|
3264 |
"oops, I am already accociated to another device |
|
3265 |
- need a copy ... |
|
3266 |
" |
|
3267 |
^ self copy monochromeOn:aDevice |
|
3268 |
]. |
|
3269 |
monoDeviceForm := self asMonochromeFormOn:aDevice. |
|
3270 |
! |
|
3271 |
||
3272 |
on:aDevice |
|
3273 |
"return an image with the same pixels as the receiver, but |
|
3274 |
associated to aDevice. If the receiver is not yet bound to |
|
3275 |
a device, this will be the receiver. Otherwise, a new image |
|
3276 |
is returned." |
|
3277 |
||
3278 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self]. |
|
852 | 3279 |
|
283 | 3280 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
852 | 3281 |
"oops, I am already accociated to another device |
3282 |
- need a copy ... |
|
3283 |
" |
|
3284 |
^ self copy on:aDevice |
|
283 | 3285 |
]. |
3286 |
deviceForm := self asFormOn:aDevice. |
|
3287 |
device := aDevice |
|
852 | 3288 |
|
3289 |
"Modified: 14.6.1996 / 15:28:30 / cg" |
|
283 | 3290 |
! ! |
3291 |
||
3292 |
!Image methodsFor:'converting greyscale images'! |
|
3293 |
||
3294 |
greyImageAsFormOn:aDevice |
|
3295 |
"return a thresholded grey-deviceForm from the grey image." |
|
3296 |
||
3297 |
|pictureDepth nPlanes f| |
|
3298 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3299 |
|
283 | 3300 |
nPlanes := samplesPerPixel. |
3301 |
(nPlanes == 2) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3302 |
'IMAGE: alpha plane ignored' errorPrintNL. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3303 |
nPlanes := 1 |
283 | 3304 |
]. |
3305 |
||
3306 |
pictureDepth := bitsPerSample at:1. |
|
3307 |
||
3308 |
"monochrome is very easy ..." |
|
3309 |
||
3310 |
(pictureDepth == 1) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3311 |
^ Form width:width height:height fromArray:bytes on:aDevice |
283 | 3312 |
]. |
3313 |
||
3314 |
(aDevice visualType == #TrueColor) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3315 |
^ self greyImageAsTrueColorFormOn:aDevice |
283 | 3316 |
]. |
3317 |
||
858 | 3318 |
"/ (aDevice visualType == #PseudoColor |
3319 |
"/ or:[aDevice visualType == #GrayScale |
|
3320 |
"/ or:[aDevice visualType == #StaticColor]]) ifTrue:[ |
|
3321 |
||
3322 |
"/ PseudoColor conversion also works for StaticColor, |
|
3323 |
"/ GrayScale and DirectColor; although possibly with suboptimal results |
|
3324 |
||
3325 |
^ self greyImageAsPseudoFormOn:aDevice |
|
3326 |
||
3327 |
"Modified: 14.6.1996 / 19:32:01 / cg" |
|
283 | 3328 |
! |
3329 |
||
3330 |
greyImageAsPseudoFormOn:aDevice |
|
3331 |
"return an 8-bit pseudo Form from the grey image" |
|
3332 |
||
3333 |
|wideBits pictureDepth f map |
|
3334 |
colorMap usedColors nUsed aColor |
|
3335 |
nColors "{ Class: SmallInteger }" |
|
3336 |
range id| |
|
3337 |
||
3338 |
pictureDepth := bitsPerSample at:1. |
|
3339 |
||
3340 |
(#(2 4 8) includes:pictureDepth) ifFalse:[ |
|
746 | 3341 |
self error:'currently only depth-2, 4 or 8 supported'. |
3342 |
^ nil |
|
283 | 3343 |
]. |
3344 |
||
3345 |
wideBits := ByteArray uninitializedNew:(width * height). |
|
3346 |
||
3347 |
(pictureDepth == 8) ifTrue:[ |
|
746 | 3348 |
"for 8bits, we scan for used colors first; |
3349 |
to avoid allocating too many colors" |
|
3350 |
||
3351 |
usedColors := bytes usedValues. |
|
3352 |
nUsed := usedColors max + 1. |
|
3353 |
||
3354 |
colorMap := Array new:nUsed. |
|
3355 |
photometric == #blackIs0 ifTrue:[ |
|
3356 |
usedColors do:[:grey | |
|
3357 |
colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey)) |
|
3358 |
] |
|
3359 |
] ifFalse:[ |
|
3360 |
usedColors do:[:grey | |
|
3361 |
colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey))) |
|
3362 |
] |
|
3363 |
] |
|
89 | 3364 |
] ifFalse:[ |
746 | 3365 |
nColors := (1 bitShift:pictureDepth). |
3366 |
colorMap := Array new:nColors. |
|
3367 |
range := 100 / (nColors - 1) asFloat. |
|
3368 |
photometric == #blackIs0 ifTrue:[ |
|
3369 |
1 to:nColors do:[:i | |
|
3370 |
colorMap at:i put:(Color gray:(i - 1) * range). |
|
3371 |
]. |
|
3372 |
] ifFalse:[ |
|
3373 |
1 to:nColors do:[:i | |
|
3374 |
colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range). |
|
3375 |
]. |
|
3376 |
]. |
|
283 | 3377 |
]. |
3378 |
||
3379 |
"XXX should reduce 8->6->4->2 planes, if not all colors could be allocated" |
|
3380 |
||
3381 |
"setup the translation map" |
|
3382 |
map := ByteArray uninitializedNew:256. |
|
3383 |
nColors := colorMap size. |
|
3384 |
1 to:nColors do:[:i | |
|
746 | 3385 |
aColor := colorMap at:i. |
3386 |
aColor notNil ifTrue:[ |
|
3387 |
aColor := aColor on:aDevice. |
|
3388 |
colorMap at:i put:aColor. |
|
3389 |
id := aColor colorId. |
|
3390 |
id notNil ifTrue:[ |
|
3391 |
map at:i put:id |
|
3392 |
] ifFalse:[ |
|
3393 |
map at:i put:0 |
|
3394 |
] |
|
3395 |
] |
|
89 | 3396 |
]. |
283 | 3397 |
|
3398 |
"expand & translate" |
|
3399 |
bytes expandPixels:pictureDepth |
|
746 | 3400 |
width:width |
3401 |
height:height |
|
3402 |
into:wideBits |
|
3403 |
mapping:map. |
|
283 | 3404 |
|
3405 |
f := Form width:width height:height depth:8 on:aDevice. |
|
3406 |
f isNil ifTrue:[^ nil]. |
|
3407 |
f colorMap:colorMap. |
|
3408 |
f initGC. |
|
3409 |
aDevice drawBits:wideBits depth:8 width:width height:height |
|
746 | 3410 |
x:0 y:0 |
3411 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
283 | 3412 |
^ f |
746 | 3413 |
|
3414 |
"Modified: 28.5.1996 / 20:55:57 / cg" |
|
0 | 3415 |
! |
3416 |
||
283 | 3417 |
greyImageAsTrueColorFormOn:aDevice |
3418 |
"return a true-color device-form for the grey-image receiver. |
|
3419 |
TODO: the pixel loops ought to be implemented as inline primitive code ..." |
|
3420 |
||
3421 |
|depth |
|
3422 |
myDepth "{ Class: SmallInteger }" |
|
3423 |
nColors "{ Class: SmallInteger }" |
|
3424 |
colorValues |
|
3425 |
scaleDown scaleRed scaleGreen scaleBlue redShift blueShift greenShift |
|
3426 |
form imageBitsdestIndex |
|
3427 |
bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits destIndex |
|
3428 |
nPixels| |
|
3429 |
||
3430 |
"/ this is a slow fallback method; this ought to be |
|
3431 |
"/ redefined in DepthxImage for more performance. |
|
3432 |
||
3433 |
depth := aDevice depth. |
|
3434 |
myDepth := self depth. |
|
3435 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3436 |
self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3437 |
^ nil |
0 | 3438 |
]. |
3439 |
||
283 | 3440 |
"/ compute scale to map from my pixels into devices range |
3441 |
||
3442 |
scaleDown := 1 bitShift:myDepth. |
|
3443 |
scaleRed := (1 bitShift:aDevice bitsRed). |
|
3444 |
scaleGreen := (1 bitShift:aDevice bitsGreen). |
|
3445 |
scaleBlue := (1 bitShift:aDevice bitsBlue). |
|
3446 |
redShift := aDevice shiftRed. |
|
3447 |
greenShift := aDevice shiftGreen. |
|
3448 |
blueShift := aDevice shiftBlue. |
|
3449 |
||
3450 |
nColors := (1 bitShift:myDepth). |
|
3451 |
colorValues := Array new:nColors. |
|
3452 |
1 to:nColors do:[:i | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3453 |
|v gv bv rv nv| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3454 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3455 |
"/ scale down to 0..1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3456 |
v := (i-1) / scaleDown. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3457 |
rv := (v * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3458 |
gv := (v * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3459 |
bv := (v * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3460 |
nv := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3461 |
nv := nv bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3462 |
nv := nv bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3463 |
colorValues at:i put:nv |
0 | 3464 |
]. |
283 | 3465 |
photometric == #whiteIs0 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3466 |
"/ reverse the order; 0 is brightest |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3467 |
colorValues reverse |
283 | 3468 |
]. |
193 | 3469 |
|
3470 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3471 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3472 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3473 |
|
283 | 3474 |
"/ for now, only support some depths |
3475 |
||
3476 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3477 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3478 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3479 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3480 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3481 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3482 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3483 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3484 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3485 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3486 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3487 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3488 |
imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3489 |
destIndex := destIndex + 2. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3490 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3491 |
] |
283 | 3492 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3493 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3494 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3495 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3496 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3497 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3498 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3499 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3500 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3501 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3502 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3503 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3504 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3505 |
imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3506 |
destIndex := destIndex + 4. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3507 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3508 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3509 |
] |
193 | 3510 |
]. |
3511 |
||
283 | 3512 |
imageBits isNil ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3513 |
'IMAGE: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3514 |
^ self asMonochromeFormOn:aDevice |
283 | 3515 |
]. |
3516 |
||
3517 |
form := |
|
193 | 3518 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
283 | 3519 |
form isNil ifTrue:[^ nil]. |
193 | 3520 |
form initGC. |
3521 |
||
3522 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3523 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3524 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3525 |
x:0 y:0 toX:0 y:0. |
193 | 3526 |
|
3527 |
^ form |
|
3528 |
||
283 | 3529 |
"Created: 20.10.1995 / 22:05:10 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3530 |
"Modified: 10.6.1996 / 19:15:13 / cg" |
0 | 3531 |
! ! |
3532 |
||
3533 |
!Image methodsFor:'converting palette images'! |
|
3534 |
||
3535 |
paletteImageAsFormOn:aDevice |
|
72 | 3536 |
"return a device-form for the palette-image receiver" |
3537 |
||
380 | 3538 |
|type ddepth| |
193 | 3539 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3540 |
ddepth := aDevice depth. |
379 | 3541 |
|
193 | 3542 |
((type := aDevice visualType) == #StaticGray) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3543 |
ddepth == 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3544 |
^ self paletteImageAsGray8FormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3545 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3546 |
^ self asGrayFormOn:aDevice |
0 | 3547 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3548 |
|
193 | 3549 |
(type == #TrueColor) ifTrue:[ |
854 | 3550 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
3551 |
ddepth == 8 ifTrue:[ |
|
3552 |
self depth == 8 ifTrue:[ |
|
3553 |
"/ use fixColor dither algorithm |
|
3554 |
^ self asDitheredTrueColor8FormOn:aDevice |
|
3555 |
] |
|
3556 |
] |
|
3557 |
]. |
|
3558 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3559 |
^ self paletteImageAsTrueColorFormOn:aDevice |
193 | 3560 |
]. |
858 | 3561 |
|
3562 |
"/ the PseudoColor conversion also works for |
|
3563 |
"/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results |
|
3564 |
||
3565 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
3566 |
||
3567 |
"Modified: 14.6.1996 / 19:31:01 / cg" |
|
0 | 3568 |
! |
3569 |
||
3570 |
paletteImageAsPseudoFormOn:aDevice |
|
72 | 3571 |
"return a pseudo-deviceForm from the palette image." |
0 | 3572 |
|
89 | 3573 |
|tempImage d temp8| |
3574 |
||
3575 |
d := self depth. |
|
3576 |
(#(1 2 4 8) includes:d) ifTrue:[ |
|
3577 |
" |
|
3578 |
fallback code for some depth's: |
|
3579 |
create a temporary Depth8Image and use its conversion method |
|
3580 |
" |
|
3581 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
3582 |
||
3583 |
bytes expandPixels:d |
|
3584 |
width:width |
|
3585 |
height:height |
|
3586 |
into:temp8 |
|
3587 |
mapping:nil. |
|
3588 |
||
3589 |
tempImage := Image width:width height:height depth:8 fromArray:temp8. |
|
3590 |
tempImage colorMap:colorMap. |
|
3591 |
^ tempImage paletteImageAsPseudoFormOn:aDevice |
|
3592 |
]. |
|
2 | 3593 |
^ self subclassResponsibility |
0 | 3594 |
! |
3595 |
||
193 | 3596 |
paletteImageAsTrueColorFormOn:aDevice |
3597 |
"return a true-color device-form for the palette-image receiver." |
|
3598 |
||
209 | 3599 |
|depth |
3600 |
myDepth "{ Class: SmallInteger }" |
|
3601 |
nColors "{ Class: SmallInteger }" |
|
3602 |
colorValues |
|
193 | 3603 |
scaleRed scaleGreen scaleBlue redShift greenShift blueShift |
194 | 3604 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
854 | 3605 |
destIndex| |
193 | 3606 |
|
3607 |
"/ this is a slow fallback method; this ought to be |
|
3608 |
"/ redefined in DepthxImage for more performance. |
|
3609 |
||
3610 |
depth := aDevice depth. |
|
3611 |
myDepth := self bitsPerPixel. |
|
3612 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3613 |
'IMAGE: depth > 12 not supported' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3614 |
^ nil |
193 | 3615 |
]. |
3616 |
||
3617 |
"/ gather r/g/b values for all colors in the map ... |
|
3618 |
||
3619 |
nColors := colorMap size. |
|
3620 |
||
3621 |
"/ precompute scales to map from 0..100 into devices range |
|
3622 |
"/ (this may be different for the individual components) |
|
3623 |
||
3624 |
scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100. |
|
3625 |
scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100. |
|
3626 |
scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100. |
|
3627 |
redShift := aDevice shiftRed. |
|
3628 |
greenShift := aDevice shiftGreen. |
|
3629 |
blueShift := aDevice shiftBlue. |
|
3630 |
||
3631 |
colorValues := Array uninitializedNew:nColors. |
|
3632 |
||
3633 |
1 to:nColors do:[:index | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3634 |
|clr rv gv bv v "{ Class: SmallInteger }" | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3635 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3636 |
clr := colorMap at:index. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3637 |
clr notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3638 |
rv := (clr red * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3639 |
gv := (clr green * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3640 |
bv := (clr blue * scaleBlue) rounded. |
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 |
v := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3643 |
v := v bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3644 |
v := v bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3645 |
colorValues at:index put:v. |
193 | 3646 |
"/ clr print. ' ' print. |
3647 |
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print. |
|
3648 |
"/ ' -> ' print. v printNL. |
|
3649 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3650 |
] |
193 | 3651 |
]. |
3652 |
||
3653 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3654 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3655 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3656 |
|
3657 |
"/ for now, only support some depths |
|
3658 |
||
854 | 3659 |
"/ 16 bits/pixel |
3660 |
||
193 | 3661 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3662 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
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 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3665 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3666 |
|
854 | 3667 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3668 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3669 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3670 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3671 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3672 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3673 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3674 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3675 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3676 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3677 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3678 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3679 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3680 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3681 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3682 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3683 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3684 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3685 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3686 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3687 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3688 |
v = __intVal(clr); |
193 | 3689 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3690 |
((short *)dstPtr)[0] = v; |
193 | 3691 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3692 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3693 |
dstPtr[1] = (v) & 0xFF; |
193 | 3694 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3695 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3696 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3697 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3698 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3699 |
} |
193 | 3700 |
%}. |
3701 |
] ifFalse:[ |
|
854 | 3702 |
"/ 32 bits/pixel |
3703 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3704 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3705 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3706 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3707 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3708 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3709 |
|
854 | 3710 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3711 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3712 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3713 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3714 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3715 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3716 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3717 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3718 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3719 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3720 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3721 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3722 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3723 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3724 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3725 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3726 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3727 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3728 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3729 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3730 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3731 |
v = __intVal(clr); |
193 | 3732 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3733 |
((long *)dstPtr)[0] = v; |
193 | 3734 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3735 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3736 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3737 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3738 |
dstPtr[3] = (v) & 0xFF; |
193 | 3739 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3740 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3741 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3742 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3743 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3744 |
} |
193 | 3745 |
%}. |
854 | 3746 |
] ifFalse:[ |
3747 |
"/ 8 bits/pixel |
|
3748 |
||
3749 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
3750 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
3751 |
||
3752 |
"/ now, walk over the image and replace |
|
3753 |
"/ colorMap indices by color values in the bits array |
|
3754 |
||
3755 |
%{ |
|
3756 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
3757 |
&& __isArray(colorValues) |
|
3758 |
&& __isByteArray(_INST(bytes)) |
|
3759 |
&& (myDepth == __MKSMALLINT(8)) |
|
3760 |
&& __isByteArray(imageBits)) { |
|
3761 |
int x, y, w, h, nPix; |
|
3762 |
||
3763 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
3764 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
3765 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
|
3766 |
||
3767 |
w = __intVal(_INST(width)); |
|
3768 |
h = __intVal(_INST(height)); |
|
3769 |
nPix = w * h; |
|
3770 |
while (nPix > 0) { |
|
3771 |
unsigned idx, v; |
|
3772 |
OBJ clr; |
|
3773 |
||
3774 |
idx = *srcPtr; |
|
3775 |
clr = ap[idx]; |
|
3776 |
v = __intVal(clr); |
|
3777 |
||
3778 |
dstPtr[0] = v; |
|
3779 |
||
3780 |
dstPtr += 1; |
|
3781 |
srcPtr += 1; |
|
3782 |
nPix--; |
|
3783 |
} |
|
3784 |
} |
|
3785 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3786 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3787 |
] |
193 | 3788 |
]. |
3789 |
||
3790 |
imageBits isNil ifTrue:[ |
|
854 | 3791 |
'IMAGE: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintNL. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3792 |
^ self asMonochromeFormOn:aDevice |
193 | 3793 |
]. |
3794 |
||
3795 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
3796 |
form isNil ifTrue:[^ nil]. |
|
3797 |
form initGC. |
|
3798 |
||
3799 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3800 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3801 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3802 |
x:0 y:0 toX:0 y:0. |
193 | 3803 |
|
3804 |
^ form |
|
3805 |
||
3806 |
"Created: 20.10.1995 / 22:05:10 / cg" |
|
3807 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
|
0 | 3808 |
! ! |
3809 |
||
283 | 3810 |
!Image methodsFor:'converting rgb images'! |
3811 |
||
854 | 3812 |
asDitheredTrueColor8FormOn:aDevice |
3813 |
"convert an rgb image to a dithered depth8-form on aDevice. |
|
3814 |
Return the device-form." |
|
3815 |
||
3816 |
|fixColors pixel |
|
3817 |
dstIdx "{ Class: SmallInteger }" |
|
3818 |
shiftRed "{ Class: SmallInteger }" |
|
3819 |
shiftGreen "{ Class: SmallInteger }" |
|
3820 |
shiftBlue "{ Class: SmallInteger }" |
|
3821 |
nRed "{ Class: SmallInteger }" |
|
3822 |
nGreen "{ Class: SmallInteger }" |
|
3823 |
nBlue "{ Class: SmallInteger }"| |
|
3824 |
||
3825 |
shiftRed := aDevice shiftRed. |
|
3826 |
shiftGreen := aDevice shiftGreen. |
|
3827 |
shiftBlue := aDevice shiftBlue. |
|
3828 |
||
3829 |
nRed := (1 bitShift:aDevice bitsRed). |
|
3830 |
nGreen := (1 bitShift:aDevice bitsGreen). |
|
3831 |
nBlue := (1 bitShift:aDevice bitsBlue). |
|
3832 |
||
3833 |
fixColors := Array new:(nRed * nGreen * nBlue). |
|
3834 |
||
3835 |
dstIdx := 1. |
|
3836 |
0 to:nRed - 1 do:[:sR | |
|
3837 |
0 to:nGreen - 1 do:[:sG | |
|
3838 |
0 to:nBlue - 1 do:[:sB | |
|
3839 |
pixel := (sR bitShift:shiftRed) |
|
3840 |
+ (sG bitShift:shiftGreen) |
|
3841 |
+ (sB bitShift:shiftBlue). |
|
3842 |
fixColors at:dstIdx put:(Color colorId:(pixel)). |
|
3843 |
dstIdx := dstIdx + 1 |
|
3844 |
] |
|
3845 |
] |
|
3846 |
]. |
|
3847 |
||
3848 |
^ self |
|
3849 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
3850 |
colors:fixColors |
|
3851 |
nRed:nRed nGreen:nGreen nBlue:nBlue |
|
3852 |
||
3853 |
"Modified: 14.6.1996 / 17:18:57 / cg" |
|
3854 |
"Created: 14.6.1996 / 17:23:52 / cg" |
|
3855 |
! |
|
3856 |
||
283 | 3857 |
rgbImageAsFormOn:aDevice |
3858 |
"convert am rgb image to a device-form on aDevice. |
|
3859 |
Return the device-form." |
|
3860 |
||
3861 |
|visual| |
|
3862 |
||
3863 |
visual := aDevice visualType. |
|
3864 |
(visual == #StaticGray) ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3865 |
^ self asGrayFormOn:aDevice |
0 | 3866 |
]. |
283 | 3867 |
(visual == #TrueColor) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3868 |
^ self rgbImageAsTrueColorFormOn:aDevice |
0 | 3869 |
]. |
858 | 3870 |
|
3871 |
"/ PseudoColor conversion also works for StaticColor, GrayScale |
|
3872 |
"/ and DirectColor displays; although possibly with suboptimal results |
|
3873 |
||
283 | 3874 |
^ self rgbImageAsPseudoFormOn:aDevice |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3875 |
|
858 | 3876 |
"Modified: 14.6.1996 / 19:30:06 / cg" |
283 | 3877 |
! |
3878 |
||
3879 |
rgbImageAsPseudoFormOn:aDevice |
|
3880 |
"return a pseudocolor form from the rgb-picture" |
|
3881 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3882 |
|n "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3883 |
depth "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3884 |
palette f| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3885 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3886 |
(depth := self depth) <= 8 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3887 |
"/ 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
|
3888 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3889 |
palette := Array new:(1 bitShift:depth). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3890 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3891 |
n := (1 bitShift:depth)-1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3892 |
0 to:n do:[:pixelValue | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3893 |
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
|
3894 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3895 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3896 |
colorMap := palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3897 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3898 |
f := self paletteImageAsPseudoFormOn:aDevice. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3899 |
colorMap := nil. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3900 |
photometric := #rgb. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3901 |
^ f |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3902 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3903 |
|
283 | 3904 |
^ self subclassResponsibility |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3905 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3906 |
"Modified: 8.6.1996 / 10:58:25 / cg" |
283 | 3907 |
! |
3908 |
||
3909 |
rgbImageAsTrueColorFormOn:aDevice |
|
3910 |
"return a truecolor form from the rgb-picture." |
|
3911 |
||
3912 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
3913 |
form| |
|
193 | 3914 |
|
3915 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3916 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3917 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3918 |
|
854 | 3919 |
"/ 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
|
3920 |
usedDeviceBitsPerPixel == 15 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3921 |
usedDeviceBitsPerPixel := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3922 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3923 |
|
283 | 3924 |
"/ |
3925 |
"/ only the trivial case, where the depths match |
|
3926 |
"/ is handled here; conversions are supposed to |
|
3927 |
"/ be done in concrete subclasses (see D24Image) |
|
3928 |
"/ |
|
3929 |
self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[ |
|
854 | 3930 |
'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
|
3931 |
^ self asMonochromeFormOn:aDevice |
193 | 3932 |
]. |
3933 |
||
283 | 3934 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
3935 |
form isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3936 |
'IMAGE: display bitmap creation failed' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3937 |
^ nil |
193 | 3938 |
]. |
3939 |
form initGC. |
|
3940 |
||
3941 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3942 |
copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3943 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3944 |
x:0 y:0 toX:0 y:0. |
193 | 3945 |
|
3946 |
^ form |
|
3947 |
||
854 | 3948 |
"Modified: 14.6.1996 / 16:57:47 / cg" |
283 | 3949 |
! ! |
3950 |
||
3951 |
!Image methodsFor:'copying'! |
|
3952 |
||
3953 |
postCopy |
|
592 | 3954 |
"redefined to also copy the pixels and the colorMap |
3955 |
and clear out any device handles in the copy." |
|
3956 |
||
283 | 3957 |
bytes := bytes copy. |
3958 |
colorMap := colorMap deepCopy. |
|
3959 |
device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil |
|
592 | 3960 |
|
3961 |
"Modified: 23.4.1996 / 11:12:03 / cg" |
|
283 | 3962 |
! ! |
3963 |
||
3964 |
!Image methodsFor:'displaying'! |
|
3965 |
||
758 | 3966 |
displayFilledOn:aGC |
759 | 3967 |
"display the receiver as an opaque image. |
758 | 3968 |
This allows Images to be wrapped by a FillingWrapper" |
3969 |
||
3970 |
aGC displayOpaqueForm:self x:0 y:0. |
|
3971 |
||
3972 |
"Created: 29.5.1996 / 10:34:18 / cg" |
|
759 | 3973 |
"Modified: 29.5.1996 / 10:52:36 / cg" |
758 | 3974 |
! |
3975 |
||
283 | 3976 |
displayOn:aGC at:aPoint |
592 | 3977 |
"draw the receiver in the graphicsContext, aGC. |
283 | 3978 |
Smalltalk-80 compatibility" |
3979 |
||
672 | 3980 |
self displayOn:aGC x:aPoint x y:aPoint y. |
3981 |
||
3982 |
"Modified: 12.5.1996 / 20:16:38 / cg" |
|
3983 |
! |
|
3984 |
||
3985 |
displayOn:aGC x:x y:y |
|
3986 |
"draw the receiver in the graphicsContext, aGC. |
|
3987 |
Smalltalk-80 compatibility" |
|
3988 |
||
3989 |
aGC displayForm:self x:x y:y. |
|
592 | 3990 |
|
3991 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
|
672 | 3992 |
"Created: 12.5.1996 / 20:14:31 / cg" |
758 | 3993 |
! |
3994 |
||
3995 |
displayStrokedOn:aGC |
|
759 | 3996 |
"display the receiver as an non opaque image. |
758 | 3997 |
This allows Images to be wrapped by a StrokingWrapper" |
3998 |
||
3999 |
aGC displayForm:self x:0 y:0. |
|
4000 |
||
759 | 4001 |
"Created: 29.5.1996 / 10:34:18 / cg" |
4002 |
"Modified: 29.5.1996 / 10:52:30 / cg" |
|
283 | 4003 |
! ! |
4004 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4005 |
!Image methodsFor:'dither helpers'! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4006 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4007 |
burkesDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4008 |
"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
|
4009 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4010 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4011 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4012 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4013 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4014 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4015 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4016 |
errorArray1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4017 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4018 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4019 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4020 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4021 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4022 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4023 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4024 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4025 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4026 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4027 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4028 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4029 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4030 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4031 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4032 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4033 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4034 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4035 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4036 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4037 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4038 |
errorArray := Array new:(w+4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4039 |
errorArray1 := Array new:(w+4) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4040 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4041 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4042 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4043 |
"/ 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
|
4044 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4045 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4046 |
greyValues := self greyMapForRange:(255*1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4047 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4048 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4049 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4050 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4051 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4052 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4053 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4054 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4055 |
errorArray1 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4056 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4057 |
errorArray1 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4058 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4059 |
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
|
4060 |
|eP "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4061 |
eD |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4062 |
eI "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4063 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4064 |
xN "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4065 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4066 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4067 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4068 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4069 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4070 |
xE := x + 2 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4071 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4072 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4073 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4074 |
grey > (127*1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4075 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4076 |
e := grey - (255*1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4077 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4078 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4079 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4080 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4081 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4082 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4083 |
"/ XX 8 4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4084 |
"/ 2 4 8 4 2 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4085 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4086 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4087 |
eI := e // 32. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4088 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4089 |
eP := eI * 8. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4090 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4091 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4092 |
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
|
4093 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4094 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4095 |
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
|
4096 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4097 |
eP := eI * 4. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4098 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4099 |
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
|
4100 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4101 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4102 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4103 |
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
|
4104 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4105 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4106 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4107 |
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
|
4108 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4109 |
eP := eI * 2. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4110 |
xN := xE - 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4111 |
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
|
4112 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4113 |
eD := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4114 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4115 |
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
|
4116 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4117 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4118 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4119 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4120 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4121 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4122 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4123 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4124 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4125 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4126 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4127 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4128 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4129 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4130 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4131 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4132 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4133 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4134 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4135 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4136 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4137 |
"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
|
4138 |
"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
|
4139 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4140 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4141 |
floydSteinbergDitheredBitsDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4142 |
"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
|
4143 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4144 |
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
|
4145 |
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
|
4146 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4147 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4148 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4149 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4150 |
outBits greyValues greyErrors greyPixels greyLevels |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4151 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4152 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4153 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4154 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4155 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4156 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4157 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4158 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4159 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4160 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4161 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4162 |
self error:'unimplemented conversion'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4163 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4164 |
]. |
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 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4167 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4168 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4169 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4170 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4171 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4172 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4173 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4174 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4175 |
greyLevels := (1 bitShift:depth) - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4176 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4177 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4178 |
nextErrorArray := Array new:w+2. |
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 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4181 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4182 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4183 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4184 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4185 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4186 |
"/ 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
|
4187 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4188 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4189 |
greyValues := self greyMapForRange:(greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4190 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4191 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4192 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4193 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4194 |
v truncated]]. |
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 |
greyPixels := ByteArray withAll:greyPixels. |
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 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4199 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4200 |
] ifFalse:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4201 |
((v - v truncated) * 1024) truncated |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4204 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4205 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4206 |
byte := 0. |
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 := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4210 |
nextErrorArray := 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 |
nextErrorArray 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 :value | |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4215 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4216 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4217 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4218 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4219 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4220 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4221 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4222 |
pixel := greyPixels at:(value + 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. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4226 |
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
|
4227 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4228 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4229 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4230 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4231 |
e := error - 1024 "1.0" |
809
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 := error |
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 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4236 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4237 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4238 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4239 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4240 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4241 |
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
|
4242 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4243 |
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
|
4244 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4245 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4246 |
eR ~= 0 ifTrue:[ |
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) + eR. |
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 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4250 |
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
|
4251 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4252 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4253 |
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
|
4254 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4255 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4256 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4257 |
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
|
4258 |
]. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4261 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4262 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4263 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4264 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4265 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4266 |
bitCnt := 8. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4269 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4270 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4271 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4272 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4273 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4274 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4275 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4276 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4277 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4278 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4279 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4280 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4281 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4282 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4283 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4284 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4285 |
nextErrorArray := t. |
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 |
nextErrorArray atAllPut:0. |
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 |
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
|
4290 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4291 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4292 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4293 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4294 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4295 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4296 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4297 |
grey := (clr brightness * greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4298 |
pixel := grey truncated. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4299 |
error := ((grey - pixel) * 1024) truncated. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4300 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4301 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4302 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4303 |
error := error + (errorArray at:xE). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4304 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4305 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4306 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4307 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4308 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4309 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4310 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4311 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4312 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4313 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4314 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4315 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4316 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4317 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4318 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4319 |
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
|
4320 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4321 |
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
|
4322 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4323 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4324 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4325 |
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
|
4326 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4327 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4328 |
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
|
4329 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4330 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4331 |
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
|
4332 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4333 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4334 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4335 |
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
|
4336 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4337 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4338 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4339 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4340 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4341 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4342 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4343 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4344 |
bitCnt := 8. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4347 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4348 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4349 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4350 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4351 |
bitCnt := 8. |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4354 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4355 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4356 |
]. |
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 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4359 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4360 |
"Created: 10.6.1996 / 13:28:22 / cg" |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4361 |
"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
|
4362 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4363 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4364 |
floydSteinbergDitheredDepth8BitsColors:colors |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4365 |
"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
|
4366 |
which must be a depth-8 image. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4367 |
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
|
4368 |
(which need not be a colorCubes colors)." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4369 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4370 |
|pseudoBits |
882 | 4371 |
rgbBytes |
4372 |
ditherRGBBytes ditherColors |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4373 |
w "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4374 |
h "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4375 |
index "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4376 |
fixR "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4377 |
fixG "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4378 |
fixB "{Class: SmallInteger }" |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4379 |
ditherIds failed map lastColor colorsByDistance qScramble |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4380 |
clrLookup lookupPos |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4381 |
error clr| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4382 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4383 |
self depth ~~ 8 ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4384 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4385 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4386 |
"/ 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
|
4387 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4388 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4389 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4390 |
photometric == #palette ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4391 |
lastColor := colorMap size - 1 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4392 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4393 |
lastColor := 255. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4394 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4395 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4396 |
0 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4397 |
clr := self colorFromValue:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4398 |
rgbBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4399 |
rgbBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4400 |
rgbBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4401 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4402 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4403 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4404 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4405 |
"/ collect valid ditherColors ... |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4406 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4407 |
ditherColors := colors select:[:clr | clr notNil]. |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4408 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4409 |
"/ ... and sort by manhatten distance from black |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4410 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4411 |
qScramble := #( |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4412 |
"/ 2rX00X00X00X00 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4413 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4414 |
2r000000000000 "/ 0 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4415 |
2r000000000100 "/ 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4416 |
2r000000100000 "/ 2 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4417 |
2r000000100100 "/ 3 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4418 |
2r000100000000 "/ 4 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4419 |
2r000100000100 "/ 5 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4420 |
2r000100100000 "/ 6 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4421 |
2r000100100100 "/ 7 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4422 |
2r100000000000 "/ 8 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4423 |
2r100000000100 "/ 9 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4424 |
2r100000100000 "/ a |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4425 |
2r100000100100 "/ b |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4426 |
2r100100000000 "/ c |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4427 |
2r100100000100 "/ d |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4428 |
2r100100100000 "/ e |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4429 |
2r100100100100 "/ f |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4430 |
). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4431 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4432 |
ditherColors := ditherColors sort:[:a :b | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4433 |
|cr "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4434 |
cg "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4435 |
cb "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4436 |
i1 "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4437 |
i2 "{Class: SmallInteger }"| |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4438 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4439 |
cr := a redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4440 |
cg := a greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4441 |
cb := a blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4442 |
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
|
4443 |
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
|
4444 |
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
|
4445 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4446 |
cr := b redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4447 |
cg := b greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4448 |
cb := b blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4449 |
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
|
4450 |
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
|
4451 |
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
|
4452 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4453 |
i1 < i2 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4454 |
]. |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4455 |
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
|
4456 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4457 |
"/ 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
|
4458 |
"/ to the position in the colorList |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4459 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4460 |
clrLookup := ByteArray new:(4096). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4461 |
index := 0. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4462 |
ditherColors keysAndValuesDo:[:clrPosition :clr | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4463 |
|r g b i| |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4464 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4465 |
r := clr redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4466 |
g := clr greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4467 |
b := clr blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4468 |
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
|
4469 |
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
|
4470 |
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
|
4471 |
lookupPos := i. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4472 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4473 |
[index < lookupPos] whileTrue:[ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4474 |
clrLookup at:(index+1) put:(clrPosition-1-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4475 |
index := index + 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4476 |
] |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4477 |
]. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4478 |
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
|
4479 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4480 |
"/ [index <= (4095)] whileTrue:[ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4481 |
"/ clrLookup at:(index+1) put:(ditherColors size - 1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4482 |
"/ index := index + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4483 |
"/ ]. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4484 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4485 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4486 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4487 |
lastColor := ditherColors size. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4488 |
ditherIds := ByteArray uninitializedNew:lastColor. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4489 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4490 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4491 |
1 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4492 |
clr := ditherColors at:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4493 |
ditherRGBBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4494 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4495 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4496 |
ditherIds at:pix put:clr colorId. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4497 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4498 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4499 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4500 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4501 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4502 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4503 |
w := width + 2. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4504 |
error := ByteArray uninitializedNew:w*(3*2). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4505 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4506 |
w := width. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4507 |
h := height. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4508 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4509 |
failed := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4510 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4511 |
%{ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4512 |
int __x, __y; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4513 |
int __eR, __eG, __eB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4514 |
unsigned char *srcP, *dstP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4515 |
unsigned char *rgbP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4516 |
unsigned char *idP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4517 |
unsigned char *dp; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4518 |
unsigned char *__clrLookup; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4519 |
short *errP, *eP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4520 |
int __fR, __fG, __fB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4521 |
int iR, iG, iB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4522 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4523 |
int __w = __intVal(w); |
882 | 4524 |
int __h = __intVal(h); |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4525 |
int __nColors = __intVal(lastColor); |
882 | 4526 |
int __wR = -1, __wG, __wB; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4527 |
static int __qScramble[16] = { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4528 |
0x000 /* 2r000000000000 0 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4529 |
0x004 /* 2r000000000100 1 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4530 |
0x020 /* 2r000000100000 2 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4531 |
0x024 /* 2r000000100100 3 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4532 |
0x100 /* 2r000100000000 4 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4533 |
0x104 /* 2r000100000100 5 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4534 |
0x120 /* 2r000100100000 6 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4535 |
0x124 /* 2r000100100100 7 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4536 |
0x800 /* 2r100000000000 8 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4537 |
0x804 /* 2r100000000100 9 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4538 |
0x820 /* 2r100000100000 a */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4539 |
0x824 /* 2r100000100100 b */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4540 |
0x900 /* 2r100100000000 c */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4541 |
0x904 /* 2r100100000100 d */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4542 |
0x920 /* 2r100100100000 e */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4543 |
0x924 /* 2r100100100100 f */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4544 |
}; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4545 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4546 |
if (__isByteArray(__INST(bytes)) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4547 |
&& __isByteArray(pseudoBits) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4548 |
&& __isByteArray(rgbBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4549 |
&& __isByteArray(ditherRGBBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4550 |
&& __isByteArray(ditherIds) |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4551 |
&& __isByteArray(clrLookup) |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4552 |
&& __isByteArray(error)) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4553 |
failed = false; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4554 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4555 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4556 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4557 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4558 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4559 |
__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4560 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
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 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4563 |
* clear error accumulator |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4564 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4565 |
eP = errP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4566 |
bzero(eP, (__w+2) * 2 * 3); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4567 |
|
882 | 4568 |
for (__y=__h; __y>0; __y--) { |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4569 |
__eR = __eG = __eB = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4570 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4571 |
eP = &(errP[3]); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4572 |
__eR = eP[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4573 |
__eG = eP[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4574 |
__eB = eP[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4575 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4576 |
for (__x=__w; __x>0; __x--) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4577 |
int __want; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4578 |
int pix; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4579 |
int __wantR, __wantG, __wantB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4580 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4581 |
int tR, tG, tB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4582 |
int nR, nG, nB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4583 |
int dR, dG, dB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4584 |
int minDelta, bestIdx; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4585 |
int cnt; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4586 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4587 |
pix = *srcP++; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4588 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4589 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4590 |
* 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
|
4591 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4592 |
idx = pix+pix+pix; /* pix * 3 */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4593 |
|
882 | 4594 |
__wantR = rgbP[idx] + __eR; |
4595 |
__wantG = rgbP[idx+1] + __eG; |
|
4596 |
__wantB = rgbP[idx+2] + __eB; |
|
4597 |
||
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4598 |
#define RED_SCALE 30 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4599 |
#define GREEN_SCALE 59 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4600 |
#define BLUE_SCALE 11 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4601 |
#define GOOD_DELTA 30 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4602 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4603 |
#define xRED_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4604 |
#define xGREEN_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4605 |
#define xBLUE_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4606 |
#define xGOOD_DELTA 3 |
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 |
#define FAST_LOOKUP |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4609 |
/* #define ONE_SHOT */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4610 |
#define NPROBE 8 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4611 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4612 |
#ifndef FAST_LOOKUP |
882 | 4613 |
if ((__wantR == __wR) |
4614 |
&& (__wantG == __wG) |
|
4615 |
&& (__wantB == __wB)) { |
|
4616 |
/* |
|
4617 |
* same color again - reuse last bestMatch |
|
4618 |
*/ |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4619 |
} else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4620 |
#endif |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4621 |
{ |
882 | 4622 |
__wR = __wantR; |
4623 |
__wG = __wantG; |
|
4624 |
__wB = __wantB; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4625 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4626 |
#ifdef FAST_LOOKUP |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4627 |
if(__wR > 255) __wR = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4628 |
else if (__wR < 0) __wR = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4629 |
if(__wG > 255) __wG = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4630 |
else if (__wG < 0) __wG = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4631 |
if(__wB > 255) __wB = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4632 |
else if (__wB < 0) __wB = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4633 |
|
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 |
int lookupIndex; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4636 |
int idx, idx0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4637 |
int d, delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4638 |
unsigned char *dp0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4639 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4640 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4641 |
lookupIndex = __qScramble[((__wR & 0xF0)>>4)]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4642 |
lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4643 |
lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4644 |
idx = bestIdx =__clrLookup[lookupIndex]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4645 |
dp += (idx+idx+idx); |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4646 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4647 |
/* try color at lookupIndex */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4648 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4649 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4650 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4651 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4652 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4653 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4654 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4655 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4656 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4657 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4658 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4659 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4660 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4661 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4662 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4663 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4664 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4665 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4666 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4667 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4668 |
# ifndef ONE_SHOT |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4669 |
idx0 = idx; dp0 = dp; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4670 |
cnt = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4671 |
while ((++cnt <= NPROBE) && (idx > 0)) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4672 |
/* try previous color(s) */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4673 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4674 |
idx--; dp -= 3; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4675 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4676 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4677 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4678 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4679 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4680 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4681 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4682 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4683 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4684 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4685 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4686 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4687 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4688 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4689 |
if (delta < minDelta) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4690 |
bestIdx = idx; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4691 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4692 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4693 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4694 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4695 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4696 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4697 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4698 |
idx = idx0; dp = dp0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4699 |
cnt = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4700 |
while ((++cnt <= NPROBE) && (++idx < __nColors)) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4701 |
/* try next color */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4702 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4703 |
dp += 3; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4704 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4705 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4706 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4707 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4708 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4709 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4710 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4711 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4712 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4713 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4714 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4715 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4716 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4717 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4718 |
if (delta < minDelta) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4719 |
bestIdx = idx; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4720 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4721 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4722 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4723 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4724 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4725 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4726 |
# endif |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4727 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4728 |
foundBest: ; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4729 |
#else |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4730 |
/* |
882 | 4731 |
if(__wR > 255) __wR = 255; |
4732 |
else if (__wR < 0) __wR = 0; |
|
4733 |
if(__wG > 255) __wG = 255; |
|
4734 |
else if (__wG < 0) __wG = 0; |
|
4735 |
if(__wB > 255) __wB = 255; |
|
4736 |
else if (__wB < 0) __wB = 0; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4737 |
*/ |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4738 |
|
882 | 4739 |
/* find the best matching color */ |
4740 |
||
4741 |
minDelta = 99999; |
|
4742 |
bestIdx = -1; |
|
4743 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
4744 |
for (idx = 0; idx<__nColors; idx++) { |
|
4745 |
int d, delta; |
|
4746 |
||
4747 |
d = dp[0]; |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4748 |
delta = (__wR - d) * RED_SCALE; |
882 | 4749 |
if (delta < 0) delta = -delta; |
878 | 4750 |
if (delta < minDelta) { |
882 | 4751 |
d = dp[1]; |
4752 |
if (__wG > d) |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4753 |
delta += (__wG - d) * GREEN_SCALE; |
878 | 4754 |
else |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4755 |
delta += (d - __wG) * GREEN_SCALE; |
878 | 4756 |
if (delta < minDelta) { |
882 | 4757 |
d = dp[2]; |
4758 |
if (__wB > d) |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4759 |
delta += (__wB - d) * BLUE_SCALE; |
882 | 4760 |
else |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4761 |
delta += (d - __wB) * BLUE_SCALE; |
882 | 4762 |
|
4763 |
if (delta < minDelta) { |
|
4764 |
bestIdx = idx; |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4765 |
if (delta <= GOOD_DELTA) { |
882 | 4766 |
break; |
4767 |
} |
|
4768 |
minDelta = delta; |
|
878 | 4769 |
} |
4770 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4771 |
} |
882 | 4772 |
dp += 3; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4773 |
} |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
4774 |
#endif |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4775 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4776 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4777 |
dp += bestIdx * 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4778 |
dR = dp[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4779 |
dG = dp[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4780 |
dB = dp[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4781 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4782 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4783 |
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
|
4784 |
__wantR, __wantG, __wantB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4785 |
__wR, __wG, __wB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4786 |
dR, dG, dB); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4787 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4788 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4789 |
* store the corresponding dither colors colorId |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4790 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4791 |
*dstP++ = idP[bestIdx]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4792 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4793 |
/* |
882 | 4794 |
* the new error & distribute the error |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4795 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4796 |
__eR = __wantR - dR; |
882 | 4797 |
if (__eR) { |
4798 |
tR = __eR >> 4; /* 16th of error */ |
|
4799 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
4800 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
4801 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
4802 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
4803 |
__eR = nR; |
|
4804 |
} else { |
|
4805 |
__eR = eP[3]; |
|
4806 |
eP[0] = eP[-3] = eP[3] = 0; |
|
4807 |
} |
|
4808 |
||
4809 |
__eG = __wantG - dG; |
|
4810 |
if (__eG) { |
|
4811 |
tG = __eG >> 4; |
|
4812 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
4813 |
eP[1] = tG*5; |
|
4814 |
eP[-2] = tG*3; |
|
4815 |
eP[4] = __eG - (tG*15); |
|
4816 |
__eG = nG; |
|
4817 |
} else { |
|
4818 |
__eG = eP[4]; |
|
4819 |
eP[1] = eP[-2] = eP[4] = 0; |
|
4820 |
} |
|
4821 |
||
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4822 |
__eB = __wantB - dB; |
882 | 4823 |
if (__eB) { |
4824 |
tB = __eB >> 4; |
|
4825 |
nB = eP[5] + (tB * 7); |
|
4826 |
eP[2] = tB*5; |
|
4827 |
eP[-1] = tB*3; |
|
4828 |
eP[5] = __eB - (tB*15); |
|
4829 |
__eB = nB; |
|
4830 |
} else { |
|
4831 |
__eB = eP[5]; |
|
4832 |
eP[2] = eP[-1] = eP[5] = 0; |
|
4833 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4834 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4835 |
eP += 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4836 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4837 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4838 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4839 |
%}. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4840 |
failed ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4841 |
self primitiveFailed. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4842 |
^ nil |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4843 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4844 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4845 |
^ pseudoBits |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4846 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4847 |
|
854 | 4848 |
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
858 | 4849 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
4850 |
which must be a depth-8 image. |
|
4851 |
This is a special-cased dither method for 8-bit palette images being displayed on |
|
4852 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
|
854 | 4853 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
4854 |
colors assigned to aDevice, such as the preallocated colors of the |
|
4855 |
Color class. |
|
4856 |
By passing the ditherColors as extra array, this method can |
|
4857 |
also be used to dither an 8bit image into a smaller number of colors, |
|
4858 |
for example to create dithered Depth4Images from Depth8Images." |
|
4859 |
||
858 | 4860 |
|pseudoBits |
854 | 4861 |
rgbBytes |
4862 |
w "{Class: SmallInteger }" |
|
4863 |
h "{Class: SmallInteger }" |
|
4864 |
index "{Class: SmallInteger }" |
|
4865 |
fixR "{Class: SmallInteger }" |
|
4866 |
fixG "{Class: SmallInteger }" |
|
4867 |
fixB "{Class: SmallInteger }" |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4868 |
fixGfixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4869 |
fixIds failed map lastColor |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4870 |
rgbIDX "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4871 |
idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes |
854 | 4872 |
error clr| |
4873 |
||
858 | 4874 |
self depth ~~ 8 ifTrue:[^ nil]. |
4875 |
||
854 | 4876 |
fixR := nRed. |
4877 |
fixR == 0 ifTrue:[ ^ nil]. |
|
4878 |
fixG := nGreen. |
|
4879 |
fixG == 0 ifTrue:[ ^ nil]. |
|
4880 |
fixB := nBlue. |
|
4881 |
fixB == 0 ifTrue:[ ^ nil]. |
|
4882 |
||
4883 |
"/ simple check |
|
4884 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
4885 |
self error:'invalid color array passed'. |
|
4886 |
^ nil |
|
4887 |
]. |
|
4888 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
4889 |
||
4890 |
"/ |
|
4891 |
"/ collect color components as integer values (for integer arithmetic) |
|
4892 |
"/ |
|
4893 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
|
4894 |
||
4895 |
index := 1. |
|
4896 |
||
4897 |
photometric == #palette ifTrue:[ |
|
4898 |
lastColor := colorMap size - 1 |
|
4899 |
] ifFalse:[ |
|
4900 |
lastColor := 255. |
|
4901 |
]. |
|
4902 |
0 to:lastColor do:[:pix | |
|
4903 |
clr := self colorFromValue:pix. |
|
4904 |
rgbBytes at:index put:(clr redByte). |
|
4905 |
rgbBytes at:index+1 put:(clr greenByte). |
|
4906 |
rgbBytes at:index+2 put:(clr blueByte). |
|
4907 |
||
4908 |
index := index + 3. |
|
4909 |
]. |
|
4910 |
||
4911 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
4912 |
||
4913 |
w := width + 2. |
|
4914 |
error := ByteArray uninitializedNew:w*(3*2). |
|
4915 |
||
4916 |
w := width. |
|
4917 |
h := height. |
|
4918 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4919 |
idxAndErrRBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4920 |
idxAndErrGBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4921 |
idxAndErrBBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4922 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4923 |
fixGfixB := fixG * fixB. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4924 |
index := 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4925 |
0 to:255 do:[:i | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4926 |
rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4927 |
idxAndErrRBytes at:index put:(rgbIDX * fixGfixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4928 |
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
|
4929 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4930 |
rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4931 |
idxAndErrGBytes at:index put:(rgbIDX * fixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4932 |
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
|
4933 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4934 |
rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4935 |
idxAndErrBBytes at:index put:(rgbIDX ). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4936 |
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
|
4937 |
index := index + 2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4938 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4939 |
|
854 | 4940 |
failed := true. |
4941 |
||
4942 |
%{ |
|
4943 |
int __x, __y; |
|
4944 |
int __eR, __eG, __eB; |
|
4945 |
unsigned char *srcP, *dstP; |
|
4946 |
unsigned char *rgbP; |
|
4947 |
unsigned char *idP; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4948 |
unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes; |
854 | 4949 |
short *errP, *eP; |
4950 |
int idx; |
|
4951 |
int __w = __intVal(w); |
|
4952 |
||
4953 |
if (__isByteArray(__INST(bytes)) |
|
4954 |
&& __isByteArray(pseudoBits) |
|
4955 |
&& __isByteArray(rgbBytes) |
|
4956 |
&& __isByteArray(fixIds) |
|
4957 |
&& __isByteArray(error) |
|
4958 |
&& __bothSmallInteger(fixR, fixG) |
|
4959 |
&& __isSmallInteger(fixB)) { |
|
4960 |
failed = false; |
|
4961 |
||
4962 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
4963 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
4964 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
|
4965 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4966 |
__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4967 |
__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4968 |
__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element; |
854 | 4969 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
4970 |
||
4971 |
/* |
|
4972 |
* clear error accumulator |
|
4973 |
*/ |
|
4974 |
eP = errP; |
|
4975 |
bzero(eP, (__w+2) * 2 * 3); |
|
4976 |
||
4977 |
for (__y=__intVal(h); __y>0; __y--) { |
|
4978 |
__eR = __eG = __eB = 0; |
|
4979 |
||
4980 |
eP = &(errP[3]); |
|
4981 |
__eR = eP[0]; |
|
4982 |
__eG = eP[1]; |
|
4983 |
__eB = eP[2]; |
|
4984 |
||
4985 |
for (__x=__w; __x>0; __x--) { |
|
4986 |
int __want; |
|
4987 |
int pix; |
|
4988 |
int idx; |
|
4989 |
int tR, tG, tB; |
|
4990 |
int nR, nG, nB; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4991 |
int iRGB; |
854 | 4992 |
|
4993 |
pix = *srcP++; |
|
4994 |
||
4995 |
/* |
|
4996 |
* wR, wG and wB is the wanted r/g/b value; |
|
4997 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4998 |
pix = pix+pix+pix; /* pix * 3 */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4999 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5000 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5001 |
* compute indexR/G/B and the new error: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5002 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5003 |
__want = rgbP[pix] + __eR; |
854 | 5004 |
if (__want > 255) __want = 255; |
5005 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5006 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5007 |
idx = __idxAndErrRBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5008 |
__eR = __idxAndErrRBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5009 |
__eR -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5010 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5011 |
__want = rgbP[pix+1] + __eG; |
854 | 5012 |
if (__want > 255) __want = 255; |
5013 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5014 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5015 |
idx += __idxAndErrGBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5016 |
__eG = __idxAndErrGBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5017 |
__eG -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5018 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5019 |
__want = rgbP[pix+2] + __eB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5020 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5021 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5022 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5023 |
idx += __idxAndErrBBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5024 |
__eB = __idxAndErrBBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5025 |
__eB -= 128; |
854 | 5026 |
|
5027 |
/* |
|
5028 |
* store the corresponding dither colors colorId |
|
5029 |
*/ |
|
5030 |
*dstP++ = idP[idx]; |
|
5031 |
||
5032 |
/* |
|
5033 |
* distribute the error |
|
5034 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5035 |
if (__eR) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5036 |
tR = __eR >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5037 |
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
|
5038 |
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
|
5039 |
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
|
5040 |
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
|
5041 |
__eR = nR; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5042 |
} else { |
882 | 5043 |
__eR = eP[3]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5044 |
eP[0] = eP[-3] = eP[3] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5045 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5046 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5047 |
if (__eG) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5048 |
tG = __eG >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5049 |
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
|
5050 |
eP[1] = tG*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5051 |
eP[-2] = tG*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5052 |
eP[4] = __eG - (tG*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5053 |
__eG = nG; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5054 |
} else { |
882 | 5055 |
__eG = eP[4]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5056 |
eP[1] = eP[-2] = eP[4] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5057 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5058 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5059 |
if (__eB) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5060 |
tB = __eB >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5061 |
nB = eP[5] + (tB * 7); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5062 |
eP[2] = tB*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5063 |
eP[-1] = tB*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5064 |
eP[5] = __eB - (tB*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5065 |
__eB = nB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5066 |
} else { |
882 | 5067 |
__eB = eP[5]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5068 |
eP[2] = eP[-1] = eP[5] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5069 |
} |
854 | 5070 |
|
5071 |
eP += 3; |
|
5072 |
} |
|
5073 |
} |
|
5074 |
} |
|
5075 |
%}. |
|
5076 |
failed ifTrue:[ |
|
5077 |
self primitiveFailed. |
|
5078 |
^ nil |
|
5079 |
]. |
|
5080 |
||
5081 |
^ pseudoBits |
|
5082 |
||
5083 |
||
5084 |
! |
|
5085 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5086 |
floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5087 |
"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
|
5088 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5089 |
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
|
5090 |
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
|
5091 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5092 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5093 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5094 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5095 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5096 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5097 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5098 |
e eD t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5099 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5100 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5101 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5102 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5103 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5104 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5105 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5106 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5107 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5108 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5109 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5110 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5111 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5112 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5113 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5114 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5115 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5116 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5117 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5118 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5119 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5120 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5121 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5122 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5123 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5124 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5125 |
"/ 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
|
5126 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5127 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5128 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5129 |
greyValues := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5130 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5131 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5132 |
v rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5133 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5134 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5135 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5136 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5137 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5138 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5139 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5140 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5141 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5142 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5143 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5144 |
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
|
5145 |
%{ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5146 |
int __grey, __e; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5147 |
int __byte = __intVal(byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5148 |
OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5149 |
OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5150 |
int __x = __intVal(x); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5151 |
int __eR, __eB, __eRB, __eLB, __eI; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5152 |
int __bitCnt = __intVal(bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5153 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5154 |
__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5155 |
__grey += __intVal(__errorArray[__x+1]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5156 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5157 |
__byte <<= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5158 |
if (__grey > 127*1024) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5159 |
__e = __grey - (255*1024); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5160 |
__byte |= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5161 |
} else { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5162 |
__e = __grey; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5163 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5164 |
if (__e) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5165 |
__eI = __e >> 4; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5166 |
__eR = __eI * 7; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5167 |
__eRB = __eI * 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5168 |
__eB = __eI * 5; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5169 |
__eLB = __e - __eR - __eRB - __eB; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5170 |
__errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5171 |
__nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5172 |
__nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5173 |
__nextErrorArray[__x ] = __MKSMALLINT(__intVal(__nextErrorArray[__x ]) + __eLB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5174 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5175 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5176 |
__bitCnt--; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5177 |
if (__bitCnt == 0) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5178 |
int __dstIndex = __intVal(dstIndex); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5179 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5180 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5181 |
dstIndex = __MKSMALLINT(__dstIndex + 1); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5182 |
__byte = 0; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5183 |
__bitCnt = 8; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5184 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5185 |
byte = __MKSMALLINT(__byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5186 |
bitCnt = __MKSMALLINT(__bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5187 |
%}. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5188 |
|
829 | 5189 |
"/ |eI "{ Class: SmallInteger }" |
5190 |
"/ xE "{ Class: SmallInteger }" |
|
5191 |
"/ xN "{ Class: SmallInteger }" | |
|
5192 |
"/ |
|
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5193 |
"/ "/ get the colors grey value [0 .. 1] |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5194 |
"/ grey := greyValues at:(pixel + 1). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5195 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5196 |
"/ "/ adjust error |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5197 |
"/ xE := x + 2. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5198 |
"/ grey := (grey + (errorArray at:xE)). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5199 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5200 |
"/ byte := byte bitShift:1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5201 |
"/ grey > (127*1024) ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5202 |
"/ byte := byte bitOr:1. "/ white |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5203 |
"/ e := grey - (255*1024) |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5204 |
"/ ] ifFalse:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5205 |
"/ e := grey "/ black |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5206 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5207 |
"/ e ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5208 |
"/ eD := e. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5209 |
"/ eI := e // 16. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5210 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5211 |
"/ eR := eI * 7. "/ 7/16 to right |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5212 |
"/ eRB := eI * 1. "/ 1/16 to right below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5213 |
"/ eB := eI * 5. "/ 5/16 to below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5214 |
"/ eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5215 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5216 |
"/ xN := xE + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5217 |
"/ eR ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5218 |
"/ errorArray at:xN put:(errorArray at:xN) + eR. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5219 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5220 |
"/ eRB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5221 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5222 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5223 |
"/ eB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5224 |
"/ nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5225 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5226 |
"/ eLB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5227 |
"/ xN := xE - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5228 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5229 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5230 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5231 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5232 |
"/ bitCnt := bitCnt - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5233 |
"/ bitCnt == 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5234 |
"/ monoBits at:dstIndex put:byte. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5235 |
"/ dstIndex := dstIndex + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5236 |
"/ byte := 0. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5237 |
"/ bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5238 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5239 |
0 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5240 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5241 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5242 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5243 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5244 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5245 |
byte := 0. |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5248 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5249 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5250 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5251 |
'IMAGE: slow floydSteinberg dither ..' infoPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5252 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5253 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5254 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5255 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5256 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5257 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5258 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5259 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5260 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5261 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5262 |
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
|
5263 |
|eI "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5264 |
xE "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5265 |
xN "{ Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5266 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5267 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5268 |
grey := (clr brightness * 255). |
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 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5271 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5272 |
grey := (grey + (errorArray at:xE)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5273 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5274 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5275 |
grey > 127 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5276 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5277 |
e := grey - 255 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5278 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5279 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5280 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5281 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5282 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5283 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5284 |
eI := e // 16. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5285 |
eR := eI * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5286 |
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
|
5287 |
eB := eI * 5. "/ 5/16 to below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5288 |
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
|
5289 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5290 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5291 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5292 |
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
|
5293 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5294 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5295 |
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
|
5296 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5297 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5298 |
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
|
5299 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5300 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5301 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5302 |
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
|
5303 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5304 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5305 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5306 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5307 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5308 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5309 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5310 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5311 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5312 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5313 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5314 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5315 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5316 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5317 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5318 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5319 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5320 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5321 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5322 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5323 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5324 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5325 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5326 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5327 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5328 |
"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
|
5329 |
"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
|
5330 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5331 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5332 |
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5333 |
"return a nearest paint bitmap from the receiver picture, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5334 |
which must be a depth-8 image. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5335 |
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
|
5336 |
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
|
5337 |
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
|
5338 |
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
|
5339 |
Color class." |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5340 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5341 |
|pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5342 |
fixR "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5343 |
fixG "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5344 |
fixB "{Class: SmallInteger }" |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5345 |
fixGfixB |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5346 |
r "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5347 |
g "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5348 |
b "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5349 |
idx "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5350 |
idMap lastColor |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5351 |
clr| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5352 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5353 |
self depth ~~ 8 ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5354 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5355 |
fixR := nRed. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5356 |
fixR == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5357 |
fixG := nGreen. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5358 |
fixG == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5359 |
fixB := nBlue. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5360 |
fixB == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5361 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5362 |
"/ simple check |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5363 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5364 |
self error:'invalid color array passed'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5365 |
^ nil |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5366 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5367 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5368 |
"/ |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5369 |
"/ collect colorIds |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5370 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5371 |
photometric == #palette ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5372 |
lastColor := colorMap size - 1 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5373 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5374 |
lastColor := 255. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5375 |
]. |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5376 |
fixGfixB := fixG * fixB. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5377 |
|
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5378 |
idMap := ByteArray uninitializedNew:256. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5379 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5380 |
0 to:lastColor do:[:pix | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5381 |
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
|
5382 |
r := clr redByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5383 |
g := clr greenByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5384 |
b := clr blueByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5385 |
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
|
5386 |
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
|
5387 |
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
|
5388 |
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
|
5389 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5390 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5391 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5392 |
|
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5393 |
"/ translate |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5394 |
|
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5395 |
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
|
5396 |
width:width |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5397 |
height:height |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5398 |
into:pseudoBits |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5399 |
mapping:idMap. |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5400 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5401 |
^ pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5402 |
|
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
5403 |
"Modified: 18.6.1996 / 09:18:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5404 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5405 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5406 |
orderedDitheredBitsDepth:depth |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5407 |
"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
|
5408 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5409 |
^ self |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5410 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5411 |
ditherWidth:8 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5412 |
depth:depth. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5413 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5414 |
"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
|
5415 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5416 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5417 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5418 |
"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
|
5419 |
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
|
5420 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5421 |
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
|
5422 |
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
|
5423 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5424 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5425 |
greyLevels greyValues greyPixels greyErrors |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5426 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5427 |
nextDst |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5428 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5429 |
pixelsPerByte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5430 |
outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5431 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5432 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5433 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5434 |
byte "{Class: SmallInteger }" | |
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 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5437 |
'IMAGE: unimplemented orderedDither conversion' errorPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5438 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5439 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5440 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5441 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5442 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5443 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5444 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5445 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5446 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5447 |
greyLevels := 1 bitShift:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5448 |
pixelsPerByte := 8 / depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5449 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5450 |
bytesPerOutRow := (w * depth + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5451 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5452 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5453 |
^ nil |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5456 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5457 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5458 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5459 |
"/ 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
|
5460 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5461 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5462 |
greyValues := self greyMapForRange:(greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5463 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5464 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5465 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5466 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5467 |
greyPixels := ByteArray withAll:greyPixels. |
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 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5470 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5471 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5472 |
((v - v truncated) * nDither) rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5473 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5474 |
greyErrors := ByteArray withAll:greyErrors. |
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 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5477 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5478 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5479 |
bitCnt := 8. |
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 |
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
|
5482 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5483 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5484 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5485 |
int __value = __intVal(value); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5486 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5487 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5488 |
int __pixel, __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5489 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5490 |
unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5491 |
unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5492 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5493 |
__pixel = __greyPixels[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5494 |
__grey = __greyErrors[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5495 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5496 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5497 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5498 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5499 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5500 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5501 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5502 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5503 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5504 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5505 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5506 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5507 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5508 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5509 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5510 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5511 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5512 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5513 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5514 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5515 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5516 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5517 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5518 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5519 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5520 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5521 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5522 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5523 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5524 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5525 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5526 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5527 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5528 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5529 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5530 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5531 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5532 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5533 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5534 |
"/ this is the representaion independent (but slow) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5535 |
"/ 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
|
5536 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5537 |
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
|
5538 |
|dstClr grey dT pixel| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5539 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5540 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5541 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5542 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5543 |
"/ remap into [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5544 |
grey := grey * (greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5545 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5546 |
"/ get threshold pixel [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5547 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5548 |
pixel := grey truncated. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5549 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5550 |
"/ compute the error [0..1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5551 |
grey := grey - pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5552 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5553 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5554 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5555 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5556 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5557 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5558 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5559 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5560 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5561 |
int __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5562 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5563 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5564 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5565 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5566 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5567 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5568 |
__pixel = __intVal(pixel); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5569 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5570 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5571 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5572 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5573 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5574 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5575 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5576 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5577 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5578 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5579 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5580 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5581 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5582 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5583 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5584 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5585 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5586 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5587 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5588 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5589 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5590 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5591 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5592 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5593 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5594 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5595 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5596 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5597 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5598 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5599 |
|
831 | 5600 |
orderedDitheredMonochromeBits |
5601 |
"return the bitmap for a dithered monochrome bitmap from the image; |
|
5602 |
using a default ditherMatrix." |
|
5603 |
||
5604 |
^ self |
|
5605 |
orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
5606 |
ditherWidth:8 |
|
5607 |
||
5608 |
"Created: 11.6.1996 / 16:48:57 / cg" |
|
5609 |
! |
|
5610 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5611 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5612 |
"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
|
5613 |
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
|
5614 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5615 |
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
|
5616 |
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
|
5617 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5618 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5619 |
greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5620 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5621 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5622 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5623 |
monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5624 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5625 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5626 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5627 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5628 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5629 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5630 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5631 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5632 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5633 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5634 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5635 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5636 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5637 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5638 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5639 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5640 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5641 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5642 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5643 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5644 |
"/ 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
|
5645 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5646 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5647 |
greyValues := self greyByteMapForRange:nDither. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5648 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5649 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5650 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5651 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5652 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5653 |
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
|
5654 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5655 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5656 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5657 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5658 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5659 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5660 |
int __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5661 |
unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5662 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5663 |
__grey = __greyValues[__intVal(value)]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5664 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5665 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5666 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5667 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5668 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5669 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5670 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5671 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5672 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5673 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5674 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5675 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5676 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5677 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5678 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5679 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5680 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5681 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5682 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5683 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5684 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5685 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5686 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5687 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5688 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5689 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5690 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5691 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5692 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5693 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5694 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5695 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5696 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5697 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5698 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5699 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5700 |
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
|
5701 |
|dstClr grey dT| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5702 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5703 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5704 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5705 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5706 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5707 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5708 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5709 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5710 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5711 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5712 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5713 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5714 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5715 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5716 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5717 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5718 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5719 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5720 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5721 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5722 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5723 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5724 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5725 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5726 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5727 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5728 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5729 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5730 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5731 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5732 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5733 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5734 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5735 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5736 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5737 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5738 |
"/ 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
|
5739 |
"/ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5740 |
"/ byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5741 |
"/ grey < dT ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5742 |
"/ byte := byte bitOr:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5743 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5744 |
"/ bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5745 |
"/ bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5746 |
"/ monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5747 |
"/ dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5748 |
"/ byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5749 |
"/ bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5750 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5751 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5752 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5753 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5754 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5755 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5756 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5757 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5758 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5759 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5760 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5761 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5762 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5763 |
stevensonArceDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5764 |
"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
|
5765 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5766 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5767 |
|f last |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5768 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5769 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5770 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5771 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5772 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5773 |
errorArray1 errorArray2 errorArray3 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5774 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5775 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5776 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5777 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5778 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5779 |
direction "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5780 |
dstClr grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5781 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5782 |
xN "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5783 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5784 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5785 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5786 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5787 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5788 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5789 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5790 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5791 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5792 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5793 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5794 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5795 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5796 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5797 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5798 |
errorArray := Array new:(w+6). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5799 |
errorArray1 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5800 |
errorArray2 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5801 |
errorArray3 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5802 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5803 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5804 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5805 |
"/ 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
|
5806 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5807 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5808 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5809 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5810 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5811 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5812 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5813 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5814 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5815 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5816 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5817 |
errorArray1 := errorArray2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5818 |
errorArray2 := errorArray3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5819 |
errorArray3 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5820 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5821 |
errorArray3 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5822 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5823 |
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
|
5824 |
|eP eD| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5825 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5826 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5827 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5828 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5829 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5830 |
xE := x + 3 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5831 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5832 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5833 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5834 |
grey > (127 * 1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5835 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5836 |
e := grey - (255 * 1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5837 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5838 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5839 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5840 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5841 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5842 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5843 |
"/ XX 32 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5844 |
"/ 12 26 30 16 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5845 |
"/ 12 26 12 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5846 |
"/ 5 12 12 5 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5847 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5848 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5849 |
e := e // 200. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5850 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5851 |
eP := e * 32. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5852 |
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
|
5853 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5854 |
eP := e * 30. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5855 |
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
|
5856 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5857 |
eP := e * 16. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5858 |
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
|
5859 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5860 |
eP := e * 26. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5861 |
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
|
5862 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5863 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5864 |
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
|
5865 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5866 |
eP := e * 12. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5867 |
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
|
5868 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5869 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5870 |
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
|
5871 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5872 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5873 |
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
|
5874 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5875 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5876 |
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
|
5877 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5878 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5879 |
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
|
5880 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5881 |
eP := e * 5. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5882 |
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
|
5883 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5884 |
eP := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5885 |
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
|
5886 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5887 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5888 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5889 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5890 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5891 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5892 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5893 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5894 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5895 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5896 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5897 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5898 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5899 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5900 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5901 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5902 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5903 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5904 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5905 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5906 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5907 |
"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
|
5908 |
"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
|
5909 |
! ! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5910 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5911 |
!Image methodsFor:'drawing'! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5912 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5913 |
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
|
5914 |
|pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5915 |
xI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5916 |
yI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5917 |
wI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5918 |
hI "{ Class: SmallInteger }"| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5919 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5920 |
pixel := self valueFromColor:aColor. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5921 |
xI := x. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5922 |
yI := y. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5923 |
wI := w. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5924 |
hI := h. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5925 |
yI to:yI+hI-1 do:[:yRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5926 |
xI to:xI+wI-1 do:[:xRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5927 |
self atX:xRun y:yRun putValue:pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5928 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5929 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5930 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5931 |
"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
|
5932 |
"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
|
5933 |
! ! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5934 |
|
283 | 5935 |
!Image methodsFor:'enumerating'! |
5936 |
||
5937 |
atY:y from:x1 to:x2 do:aBlock |
|
5938 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5939 |
The block is passed the color at each pixel. |
|
5940 |
The code here provides a generic and slow implementation, and |
|
5941 |
should be redefined in concrete subclasses, to avoid some processing |
|
5942 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5943 |
and also the color allocation)." |
|
5944 |
||
798 | 5945 |
self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'. |
5946 |
self colorsAtY:y from:x1 to:x2 do:aBlock |
|
5947 |
||
5948 |
"Modified: 7.6.1996 / 19:13:30 / cg" |
|
5949 |
! |
|
5950 |
||
5951 |
colorsAtY:y from:x1 to:x2 do:aBlock |
|
5952 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5953 |
The block is passed the color at each pixel. |
|
5954 |
The code here provides a generic and slow implementation, and |
|
5955 |
should be redefined in concrete subclasses, to avoid some processing |
|
5956 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5957 |
and also the color allocation)." |
|
5958 |
||
283 | 5959 |
|xStart "{Class: SmallInteger }" |
5960 |
xEnd "{Class: SmallInteger }"| |
|
5961 |
||
5962 |
xStart := x1. |
|
5963 |
xEnd := x2. |
|
5964 |
xStart to:xEnd do:[:xRun | |
|
798 | 5965 |
aBlock value:xRun value:(self atX:xRun y:y) |
283 | 5966 |
] |
798 | 5967 |
|
5968 |
"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
|
5969 |
"Modified: 10.6.1996 / 10:27:29 / cg" |
283 | 5970 |
! |
5971 |
||
5972 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5973 |
"perform aBlock for each color in a rectangular area of the image. |
|
5974 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5975 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5976 |
The code here provides a generic and slow implementation, and |
|
5977 |
should be redefined in concrete subclasses, to avoid some processing |
|
5978 |
when going from pixel to pixel (i.e. the byte-index and mask computations, |
|
5979 |
and especially, the color allocations)." |
|
5980 |
||
5981 |
|xS "{Class: SmallInteger }" |
|
5982 |
xE "{Class: SmallInteger }"| |
|
5983 |
||
5984 |
xS := xStart. |
|
5985 |
xE := xEnd. |
|
5986 |
yStart to:yEnd do:[:yRun | |
|
798 | 5987 |
self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color | |
5988 |
aBlock value:xRun value:yRun value:color |
|
5989 |
] |
|
283 | 5990 |
] |
798 | 5991 |
|
5992 |
"Modified: 7.6.1996 / 19:11:39 / cg" |
|
283 | 5993 |
! |
5994 |
||
5995 |
valueAtY:y from:x1 to:x2 do:aBlock |
|
5996 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
798 | 5997 |
Obsolete - remains for backward compatibility." |
5998 |
||
5999 |
self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'. |
|
6000 |
self valuesAtY:y from:x1 to:x2 do:aBlock |
|
6001 |
||
6002 |
"Modified: 7.6.1996 / 19:11:06 / cg" |
|
6003 |
! |
|
6004 |
||
6005 |
valuesAtY:y from:x1 to:x2 do:aBlock |
|
6006 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
283 | 6007 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
6008 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
6009 |
(see also Image>>atY:from:to:do:). |
|
6010 |
The code here provides a generic and slow implementation, and |
|
6011 |
should be redefined in concrete subclasses, to avoid some processing |
|
6012 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
6013 |
||
6014 |
|xStart "{Class: SmallInteger }" |
|
6015 |
xEnd "{Class: SmallInteger }"| |
|
6016 |
||
6017 |
xStart := x1. |
|
6018 |
xEnd := x2. |
|
6019 |
xStart to:xEnd do:[:xRun | |
|
692 | 6020 |
aBlock value:xRun value:(self valueAtX:xRun y:y) |
283 | 6021 |
] |
692 | 6022 |
|
6023 |
"Modified: 17.5.1996 / 12:03:59 / cg" |
|
798 | 6024 |
"Created: 7.6.1996 / 19:09:51 / cg" |
283 | 6025 |
! |
6026 |
||
6027 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
6028 |
"perform aBlock for each pixelValue in a rectangular area of the image. |
|
6029 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
6030 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
6031 |
The code here provides a generic and slow implementation, and |
|
6032 |
should be redefined in concrete subclasses, to avoid some processing |
|
6033 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
6034 |
||
6035 |
|xS "{Class: SmallInteger }" |
|
6036 |
xE "{Class: SmallInteger }"| |
|
6037 |
||
6038 |
xS := xStart. |
|
6039 |
xE := xEnd. |
|
6040 |
yStart to:yEnd do:[:yRun | |
|
798 | 6041 |
self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel | |
6042 |
aBlock value:xRun value:yRun value:pixel |
|
6043 |
] |
|
283 | 6044 |
] |
798 | 6045 |
|
6046 |
"Modified: 7.6.1996 / 19:09:29 / cg" |
|
0 | 6047 |
! ! |
6048 |
||
6049 |
!Image methodsFor:'image manipulations'! |
|
6050 |
||
283 | 6051 |
colorMapProcessing:aBlock |
6052 |
"a helper for all kinds of colormap manipulations. |
|
592 | 6053 |
The argument, aBlock is called for every colormap entry, |
6054 |
and the returned value will replace the original entry in the map. |
|
283 | 6055 |
This will fail for non-palette images. |
592 | 6056 |
See examples in Image>>copyWithColorMapProcessing:" |
283 | 6057 |
|
6058 |
|nColors "{ Class: SmallInteger }"| |
|
6059 |
||
6060 |
colorMap isNil ifTrue:[ |
|
592 | 6061 |
^ self error:'image has no colormap' |
283 | 6062 |
]. |
6063 |
||
6064 |
nColors := colorMap size. |
|
6065 |
1 to:nColors do:[:index | |
|
592 | 6066 |
|clr| |
6067 |
||
6068 |
clr := colorMap at:index. |
|
6069 |
clr notNil ifTrue:[ |
|
6070 |
colorMap at:index put:(aBlock value:clr) |
|
6071 |
] |
|
283 | 6072 |
] |
592 | 6073 |
|
6074 |
"Modified: 23.4.1996 / 11:13:55 / cg" |
|
283 | 6075 |
! |
6076 |
||
89 | 6077 |
copyWithColorMapProcessing:aBlock |
81 | 6078 |
"a helper to create & return new images based on the receiver with |
89 | 6079 |
some colorMap processing. The receiver is copied, and the copied images |
6080 |
colormap is modified by replacing entries with the result of the processing block, |
|
6081 |
which is called with the original color values. The block is supposed to return |
|
6082 |
a color." |
|
81 | 6083 |
|
6084 |
|newImage| |
|
6085 |
||
6086 |
newImage := self copy. |
|
6087 |
newImage colorMap isNil ifTrue:[ |
|
6088 |
self error:'no colormap in image'. |
|
6089 |
^ nil |
|
6090 |
]. |
|
6091 |
||
6092 |
" |
|
6093 |
the code below manipulates the colormap. |
|
6094 |
For non-palette images, special code is required |
|
6095 |
" |
|
89 | 6096 |
newImage colorMapProcessing:aBlock. |
81 | 6097 |
^ newImage |
6098 |
||
6099 |
" |
|
6100 |
leave red component only: |
|
6101 |
||
6102 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6103 |
copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] |
81 | 6104 |
" |
89 | 6105 |
|
81 | 6106 |
" |
6107 |
make it reddish: |
|
6108 |
||
6109 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6110 |
copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] |
81 | 6111 |
" |
89 | 6112 |
|
81 | 6113 |
" |
6114 |
invert: |
|
6115 |
||
6116 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6117 |
copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] |
81 | 6118 |
" |
89 | 6119 |
|
81 | 6120 |
" |
6121 |
lighter: |
|
6122 |
||
6123 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6124 |
copyWithColorMapProcessing:[:clr | |r g b| |
6125 |
r := clr red. g := clr green. b := clr blue. |
|
6126 |
Color red:(r + (100-r//2)) |
|
6127 |
green:(g + (100-g//2)) |
|
6128 |
blue:(b + (100-b//2))] |
|
81 | 6129 |
" |
89 | 6130 |
|
81 | 6131 |
" |
6132 |
darker: |
|
6133 |
||
6134 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6135 |
copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] |
81 | 6136 |
" |
6137 |
! |
|
6138 |
||
283 | 6139 |
darkened |
6140 |
"return a new image which is slightly darker than the receiver. |
|
6141 |
The receiver must be a palette image (currently). |
|
592 | 6142 |
CAVEAT: Need an argument, which specifies by how much it should be darker." |
283 | 6143 |
|
6144 |
^ self |
|
592 | 6145 |
copyWithColorMapProcessing:[:clr | |
6146 |
Color red:(clr red // 2) |
|
6147 |
green:(clr green // 2) |
|
6148 |
blue:(clr blue // 2)] |
|
283 | 6149 |
|
6150 |
" |
|
6151 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
6152 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
6153 |
" |
|
592 | 6154 |
|
6155 |
"Modified: 23.4.1996 / 11:14:34 / cg" |
|
283 | 6156 |
! |
6157 |
||
6158 |
flipHorizontal |
|
6159 |
"inplace horizontal flip" |
|
6160 |
||
6161 |
|w "{Class: SmallInteger }" |
|
6162 |
h "{Class: SmallInteger }" |
|
6163 |
c2 "{Class: SmallInteger }" |
|
6164 |
value | |
|
6165 |
||
6166 |
w := width - 1. |
|
6167 |
h := height - 1. |
|
6168 |
||
6169 |
0 to:h do:[:row | |
|
6170 |
c2 := w. |
|
6171 |
0 to:(w // 2) do:[:col | |
|
6172 |
value := self valueAtX:col y:row. |
|
6173 |
self atX:col y:row putValue:(self valueAtX:c2 y:row). |
|
6174 |
self atX:c2 y:row putValue:value. |
|
6175 |
c2 := c2 - 1. |
|
6176 |
] |
|
81 | 6177 |
]. |
283 | 6178 |
"flush device info" |
6179 |
self restored |
|
6180 |
! |
|
6181 |
||
6182 |
flipVertical |
|
6183 |
"inplace vertical flip" |
|
6184 |
||
6185 |
|h "{Class: SmallInteger }" |
|
6186 |
bytesPerRow "{Class: SmallInteger }" |
|
6187 |
buffer |
|
6188 |
indexLow "{Class: SmallInteger }" |
|
6189 |
indexHi "{Class: SmallInteger }"| |
|
6190 |
||
6191 |
bytesPerRow := self bytesPerRow. |
|
6192 |
buffer := ByteArray new:bytesPerRow. |
|
6193 |
||
6194 |
h := height - 1. |
|
6195 |
||
6196 |
indexLow := 1. |
|
6197 |
indexHi := bytesPerRow * h + 1. |
|
6198 |
||
6199 |
0 to:(h // 2) do:[:row | |
|
6200 |
buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow. |
|
6201 |
bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi. |
|
6202 |
bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1. |
|
6203 |
indexLow := indexLow + bytesPerRow. |
|
6204 |
indexHi := indexHi - bytesPerRow. |
|
6205 |
]. |
|
6206 |
"flush device info" |
|
6207 |
self restored |
|
6208 |
! |
|
6209 |
||
6210 |
hardMagnifiedBy:scalePoint |
|
6211 |
"return a new image magnified by scalePoint, aPoint. |
|
6212 |
This is the general magnification method, handling non-integral values. |
|
6213 |
It is slower than the integral magnification method." |
|
6214 |
||
6215 |
|mX |
|
6216 |
mY |
|
6217 |
newWidth "{ Class: SmallInteger }" |
|
6218 |
newHeight "{ Class: SmallInteger }" |
|
6219 |
w "{ Class: SmallInteger }" |
|
6220 |
h "{ Class: SmallInteger }" |
|
6221 |
newImage newBits bitsPerPixel newBytesPerRow |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6222 |
value |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6223 |
srcRow| |
283 | 6224 |
|
6225 |
mX := scalePoint x. |
|
6226 |
mY := scalePoint y. |
|
6227 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
6228 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
6229 |
||
6230 |
newWidth := (width * mX) truncated. |
|
6231 |
newHeight := (height * mY) truncated. |
|
6232 |
||
6233 |
bitsPerPixel := self depth. |
|
6234 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
6235 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
6236 |
||
6237 |
newImage := self species new. |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6238 |
newImage |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6239 |
width:newWidth |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6240 |
height:newHeight |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6241 |
photometric:photometric |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6242 |
samplesPerPixel:samplesPerPixel |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6243 |
bitsPerSample:bitsPerSample |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6244 |
colorMap:colorMap copy |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6245 |
bits:newBits. |
283 | 6246 |
|
6247 |
"walk over destination image fetching pixels from source image" |
|
6248 |
||
6249 |
w := newWidth - 1. |
|
6250 |
h := newHeight - 1. |
|
6251 |
||
6252 |
0 to:h do:[:row | |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6253 |
srcRow := (row // mY). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6254 |
0 to:w do:[:col | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6255 |
value := self valueAtX:(col // mX) y:srcRow. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6256 |
newImage atX:col y:row putValue:value. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6257 |
] |
283 | 6258 |
]. |
6259 |
||
6260 |
^ newImage |
|
6261 |
||
6262 |
"((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
|
6263 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
6264 |
"Modified: 18.6.1996 / 16:08:31 / cg" |
283 | 6265 |
! |
6266 |
||
6267 |
hardRotated:degrees |
|
592 | 6268 |
"raise an error - rotation by arbitrary angles is not yet implemented" |
6269 |
||
283 | 6270 |
self error:'not yet implemented' |
592 | 6271 |
|
6272 |
"Modified: 23.4.1996 / 11:15:33 / cg" |
|
81 | 6273 |
! |
6274 |
||
54 | 6275 |
lightened |
89 | 6276 |
"return a new image which is slightly brighter than the receiver. |
6277 |
The receiver must be a palette image (currently). |
|
592 | 6278 |
CAVEAT: Need an argument, which specifies by how much it should be lighter." |
54 | 6279 |
|
81 | 6280 |
^ self |
592 | 6281 |
copyWithColorMapProcessing:[:clr | |r g b| |
6282 |
r := clr red. |
|
6283 |
g := clr green. |
|
6284 |
b := clr blue. |
|
6285 |
Color red:(r + (100-r//2)) |
|
6286 |
green:(g + (100-g//2)) |
|
6287 |
blue:(b + (100-b//2))] |
|
81 | 6288 |
|
6289 |
" |
|
6290 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
6291 |
(Image fromFile:'bitmaps/claus.gif') lightened inspect |
|
6292 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
6293 |
(Image fromFile:'bitmaps/claus.gif') darkened darkened inspect |
|
6294 |
" |
|
592 | 6295 |
|
6296 |
"Modified: 23.4.1996 / 11:14:41 / cg" |
|
54 | 6297 |
! |
6298 |
||
134 | 6299 |
magnifiedBy:scale |
81 | 6300 |
"return a new image magnified by scalePoint, aPoint. |
72 | 6301 |
If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:' |
6302 |
while simple (integral) magnifications are handled here." |
|
0 | 6303 |
|
81 | 6304 |
|scalePoint mX mY |
46 | 6305 |
magX "{ Class: SmallInteger }" "new version of stc can find this out itself..." |
6306 |
magY "{ Class: SmallInteger }" |
|
6307 |
srcOffset "{ Class: SmallInteger }" |
|
6308 |
dstOffset "{ Class: SmallInteger }" |
|
6309 |
w "{ Class: SmallInteger }" |
|
6310 |
h "{ Class: SmallInteger }" |
|
6311 |
first |
|
81 | 6312 |
newWidth newHeight newImage newBits |
6313 |
bitsPerPixel newBytesPerRow oldBytesPerRow| |
|
0 | 6314 |
|
81 | 6315 |
scalePoint := scale asPoint. |
6316 |
mX := scalePoint asPoint x. |
|
6317 |
mY := scalePoint asPoint y. |
|
46 | 6318 |
((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil]. |
0 | 6319 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
6320 |
||
12 | 6321 |
((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[ |
134 | 6322 |
^ self hardMagnifiedBy:scalePoint |
0 | 6323 |
]. |
6324 |
||
2 | 6325 |
bitsPerPixel := self depth. |
0 | 6326 |
oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8. |
6327 |
||
46 | 6328 |
w := width. |
6329 |
h := height. |
|
6330 |
magX := mX. |
|
6331 |
magY := mY. |
|
6332 |
||
6333 |
newWidth := w * mX. |
|
6334 |
newHeight := h * mY. |
|
0 | 6335 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
6336 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
6337 |
||
6338 |
newImage := self species new. |
|
2 | 6339 |
newImage bits:newBits. |
0 | 6340 |
newImage width:newWidth. |
6341 |
newImage height:newHeight. |
|
6342 |
newImage photometric:photometric. |
|
6343 |
newImage samplesPerPixel:samplesPerPixel. |
|
6344 |
newImage bitsPerSample:bitsPerSample. |
|
6345 |
newImage colorMap:colorMap copy. |
|
6346 |
||
6347 |
mX = 1 ifTrue:[ |
|
72 | 6348 |
"expand rows only" |
6349 |
srcOffset := 1. |
|
6350 |
dstOffset := 1. |
|
0 | 6351 |
|
72 | 6352 |
1 to:h do:[:row | |
6353 |
1 to:mY do:[:i | |
|
6354 |
newBits replaceFrom:dstOffset |
|
6355 |
to:(dstOffset + oldBytesPerRow - 1) |
|
6356 |
with:bytes |
|
6357 |
startingAt:srcOffset. |
|
6358 |
dstOffset := dstOffset + newBytesPerRow |
|
6359 |
]. |
|
6360 |
srcOffset := srcOffset + oldBytesPerRow. |
|
6361 |
]. |
|
0 | 6362 |
] ifFalse:[ |
72 | 6363 |
"expand cols" |
6364 |
(mX > 1) ifTrue:[ |
|
6365 |
dstOffset := 1. |
|
6366 |
srcOffset := 1. |
|
6367 |
1 to:h do:[:row | |
|
6368 |
self magnifyRowFrom:bytes |
|
6369 |
offset:srcOffset |
|
6370 |
into:newBits |
|
6371 |
offset:dstOffset |
|
6372 |
factor:mX. |
|
0 | 6373 |
|
72 | 6374 |
first := dstOffset. |
6375 |
dstOffset := dstOffset + newBytesPerRow. |
|
6376 |
" and copy for row expansion " |
|
6377 |
2 to:mY do:[:i | |
|
6378 |
newBits replaceFrom:dstOffset |
|
6379 |
to:(dstOffset + newBytesPerRow - 1) |
|
6380 |
with:newBits |
|
6381 |
startingAt:first. |
|
6382 |
dstOffset := dstOffset + newBytesPerRow |
|
6383 |
]. |
|
6384 |
srcOffset := srcOffset + oldBytesPerRow. |
|
6385 |
]. |
|
6386 |
] |
|
0 | 6387 |
]. |
6388 |
^ newImage |
|
6389 |
||
134 | 6390 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)" |
2 | 6391 |
! |
6392 |
||
154 | 6393 |
magnifiedPreservingRatioTo:anExtent |
6394 |
"return a new image magnified to fit into anExtent, |
|
6395 |
preserving the receivers width/height ratio. |
|
6396 |
(i.e. not distorting the image). |
|
6397 |
See also #magnifiedTo: and #magnifiedBy:" |
|
6398 |
||
6399 |
|rX rY| |
|
6400 |
||
6401 |
rX := anExtent x / self width. |
|
6402 |
rY := anExtent y / self height. |
|
6403 |
^ self magnifiedBy:(rX min:rY) |
|
6404 |
||
6405 |
" |
|
6406 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
6407 |
||
6408 |
in contrast to: |
|
6409 |
||
6410 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
|
6411 |
" |
|
6412 |
! |
|
6413 |
||
134 | 6414 |
magnifiedTo:anExtent |
154 | 6415 |
"return a new image magnified to have the size specified by extent. |
6416 |
This may distort the image if the arguments ratio is not the images ratio. |
|
6417 |
See also #magnifiedPreservingRatioTo: and #magnifiedBy:" |
|
89 | 6418 |
|
134 | 6419 |
^ self magnifiedBy:(anExtent / self extent) |
89 | 6420 |
|
6421 |
" |
|
134 | 6422 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
154 | 6423 |
|
6424 |
in contrast to: |
|
6425 |
||
6426 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
89 | 6427 |
" |
6428 |
! |
|
6429 |
||
12 | 6430 |
rotated:degrees |
6431 |
"return a new image from the old one, by rotating the image |
|
46 | 6432 |
degrees clockwise. |
592 | 6433 |
CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented." |
12 | 6434 |
|
46 | 6435 |
|w "{Class: SmallInteger }" |
6436 |
h "{Class: SmallInteger }" |
|
12 | 6437 |
c2 "{Class: SmallInteger }" |
692 | 6438 |
r2 "{Class: SmallInteger }" |
6439 |
nW "{Class: SmallInteger }" |
|
6440 |
nH "{Class: SmallInteger }" |
|
24 | 6441 |
newImage newBits newBytesPerRow d| |
12 | 6442 |
|
6443 |
d := degrees. |
|
6444 |
[d < 0] whileTrue:[d := d + 360]. |
|
6445 |
d >= 360 ifTrue:[d := d \\ 360]. |
|
46 | 6446 |
d := d truncated. |
6447 |
d == 0 ifTrue:[^ self]. |
|
6448 |
((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[ |
|
592 | 6449 |
^ self hardRotated:d |
12 | 6450 |
]. |
6451 |
||
692 | 6452 |
d == 180 ifTrue:[ |
6453 |
nW := width. |
|
6454 |
nH := height. |
|
6455 |
] ifFalse:[ |
|
6456 |
nW := height. |
|
6457 |
nH := width. |
|
6458 |
]. |
|
6459 |
||
6460 |
newBytesPerRow := ((nW * self depth) + 7) // 8. |
|
6461 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * nH). |
|
12 | 6462 |
|
6463 |
newImage := self species new. |
|
6464 |
newImage bits:newBits. |
|
692 | 6465 |
newImage width:nW. |
6466 |
newImage height:nH. |
|
12 | 6467 |
newImage photometric:photometric. |
6468 |
newImage samplesPerPixel:samplesPerPixel. |
|
6469 |
newImage bitsPerSample:bitsPerSample. |
|
6470 |
newImage colorMap:colorMap copy. |
|
6471 |
||
6472 |
w := width - 1. |
|
6473 |
h := height - 1. |
|
6474 |
||
6475 |
d == 90 ifTrue:[ |
|
592 | 6476 |
0 to:h do:[:row | |
6477 |
c2 := h-row. |
|
798 | 6478 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6479 |
newImage atX:c2 y:col putValue:pixel. |
592 | 6480 |
] |
692 | 6481 |
"/ 0 to:w do:[:col | |
6482 |
"/ newImage atX:c2 y:col putValue:(self valueAtX:col y:row). |
|
6483 |
"/ ] |
|
592 | 6484 |
] |
12 | 6485 |
]. |
46 | 6486 |
d == 180 ifTrue:[ |
592 | 6487 |
0 to:h do:[:row | |
692 | 6488 |
r2 := h - row. |
798 | 6489 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6490 |
newImage atX:(w-col) y:r2 putValue:pixel. |
592 | 6491 |
] |
692 | 6492 |
"/ 0 to:w do:[:col | |
6493 |
"/ newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row). |
|
6494 |
"/ ] |
|
592 | 6495 |
] |
46 | 6496 |
]. |
12 | 6497 |
d == 270 ifTrue:[ |
592 | 6498 |
0 to:h do:[:row | |
798 | 6499 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6500 |
newImage atX:row y:(w-col) putValue:pixel. |
592 | 6501 |
] |
692 | 6502 |
"/ 0 to:w do:[:col | |
6503 |
"/ newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row). |
|
6504 |
"/ ] |
|
592 | 6505 |
] |
12 | 6506 |
]. |
6507 |
^ newImage |
|
592 | 6508 |
|
692 | 6509 |
" |
6510 |
|i| |
|
6511 |
||
6512 |
i := Image fromFile:'claus.gif'. |
|
6513 |
i inspect. |
|
6514 |
(i rotated:90) inspect. |
|
6515 |
(i rotated:180) inspect. |
|
6516 |
(i rotated:270) inspect. |
|
6517 |
" |
|
6518 |
||
798 | 6519 |
"Modified: 7.6.1996 / 19:09:22 / cg" |
692 | 6520 |
! |
6521 |
||
6522 |
withPixelFunctionApplied:pixelFunctionBlock |
|
6523 |
"return a new image from the old one, by applying a pixel processor |
|
6524 |
(read `Behond photography, by Gerard J. Holzmann; |
|
6525 |
ISBM 0-13-074410-7) |
|
6526 |
See blurred / oilPointed as examples ...)" |
|
6527 |
||
6528 |
|w "{Class: SmallInteger }" |
|
6529 |
h "{Class: SmallInteger }" |
|
6530 |
newImage newBits newBytesPerRow d| |
|
6531 |
||
6532 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
6533 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
6534 |
||
6535 |
newImage := self species new. |
|
6536 |
newImage bits:newBits. |
|
6537 |
newImage width:width. |
|
6538 |
newImage height:height. |
|
6539 |
newImage photometric:photometric. |
|
6540 |
newImage samplesPerPixel:samplesPerPixel. |
|
6541 |
newImage bitsPerSample:bitsPerSample. |
|
6542 |
newImage colorMap:colorMap copy. |
|
6543 |
||
6544 |
w := width - 1. |
|
6545 |
h := height - 1. |
|
6546 |
||
6547 |
0 to:h do:[:y | |
|
6548 |
0 to:w do:[:x | |
|
6549 |
newImage atX:x y:y put:(pixelFunctionBlock |
|
6550 |
value:self |
|
6551 |
value:x |
|
6552 |
value:y) |
|
6553 |
] |
|
6554 |
]. |
|
6555 |
^ newImage |
|
6556 |
||
6557 |
" |
|
6558 |
|i| |
|
6559 |
||
6560 |
i := Image fromFile:'claus.gif'. |
|
6561 |
i inspect. |
|
6562 |
(i withPixelFunctionApplied:[:oldImage :x :y | |
|
6563 |
((x between:100 and:200) |
|
6564 |
and:[y between:100 and:200]) ifTrue:[ |
|
6565 |
oldImage atX:x y:y |
|
6566 |
] ifFalse:[ |
|
6567 |
Color black. |
|
6568 |
] |
|
6569 |
]) inspect. |
|
6570 |
" |
|
6571 |
||
6572 |
"Modified: 17.5.1996 / 12:31:44 / cg" |
|
283 | 6573 |
! ! |
6574 |
||
6575 |
!Image methodsFor:'inspecting'! |
|
6576 |
||
6577 |
inspectorClass |
|
6578 |
"redefined to launch an ImageInspector |
|
6579 |
(instead of the default InspectorView)." |
|
6580 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6581 |
(width notNil and:[height notNil]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6582 |
^ ImageInspectorView |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6583 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6584 |
^ super inspectorClass |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6585 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6586 |
"Modified: 10.6.1996 / 18:23:55 / cg" |
283 | 6587 |
! ! |
6588 |
||
6589 |
!Image methodsFor:'instance release'! |
|
6590 |
||
6591 |
disposed |
|
6592 |
"some Image has been collected - nothing to do" |
|
12 | 6593 |
! |
6594 |
||
283 | 6595 |
release |
6596 |
"release device resources" |
|
6597 |
||
6598 |
device := nil. |
|
6599 |
deviceForm := nil. |
|
6600 |
monoDeviceForm := nil. |
|
6601 |
fullColorDeviceForm := nil. |
|
6602 |
Lobby unregister:self |
|
46 | 6603 |
! |
6604 |
||
283 | 6605 |
restored |
6606 |
"flush device specifics after a snapin or binary restore" |
|
6607 |
||
6608 |
self release |
|
6609 |
! ! |
|
6610 |
||
592 | 6611 |
!Image methodsFor:'obsolete'! |
6612 |
||
6613 |
magnifyBy:scale |
|
6614 |
"obsolete: has been renamed to magnifiedBy: for ST-80 compatibility |
|
6615 |
and name consistency ..." |
|
6616 |
||
6617 |
self obsoleteMethodWarning. |
|
6618 |
^ self magnifiedBy:scale |
|
6619 |
! ! |
|
6620 |
||
283 | 6621 |
!Image methodsFor:'pixel copying'! |
6622 |
||
6623 |
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
6624 |
"replace a rectangulat area by pixels from another image. |
|
6625 |
WARNING: |
|
6626 |
This implementation is a slow fallback (the loop over the |
|
6627 |
source pixels is very slow). If this method is used heavily, you |
|
6628 |
may want to redefine it in concrete subclasses for the common case of |
|
6629 |
of copying from an Image with the same depth & palette." |
|
6630 |
||
6631 |
|dX dY| |
|
6632 |
||
6633 |
dX := srcX-dstX. |
|
6634 |
dY := srcY-dstY. |
|
6635 |
((photometric == anImage photometric) |
|
6636 |
and:[self bitsPerPixel == anImage bitsPerPixel |
|
6637 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
|
6638 |
"/ can loop over values |
|
6639 |
anImage valuesFromX:srcX y:srcY |
|
6640 |
toX:srcX+w-1 y:srcY+h-1 |
|
6641 |
do:[:x :y :pixelValue | |
|
6642 |
self atX:x-dX y:y-dY putValue:pixelValue. |
|
6643 |
] |
|
6644 |
] ifFalse:[ |
|
6645 |
"/ must loop over colors |
|
6646 |
anImage colorsFromX:srcX y:srcY |
|
6647 |
toX:srcX+w-1 y:srcY+h-1 |
|
6648 |
do:[:x :y :clr | |
|
6649 |
self atX:x-dX y:y-dY put:clr. |
|
6650 |
] |
|
6651 |
] |
|
6652 |
||
6653 |
" |
|
6654 |
|i1 i8 i4| |
|
6655 |
||
6656 |
i8 := Image fromFile:'bitmaps/garfield.gif'. |
|
6657 |
i8 inspect. |
|
6658 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
6659 |
i1 inspect. |
|
6660 |
||
6661 |
i4 := Depth4Image fromImage:i8. |
|
6662 |
i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30. |
|
6663 |
i4 inspect. |
|
6664 |
" |
|
6665 |
||
6666 |
"Created: 20.9.1995 / 10:14:01 / claus" |
|
6667 |
"Modified: 20.9.1995 / 10:25:31 / claus" |
|
6668 |
! |
|
6669 |
||
6670 |
subImageIn:aRectangle |
|
6671 |
"create and return a new image consisting of a subArea of myself" |
|
6672 |
||
6673 |
^ self class fromSubImage:self in:aRectangle |
|
6674 |
||
6675 |
" |
|
6676 |
|i| |
|
6677 |
||
6678 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
6679 |
i inspect. |
|
6680 |
(i subImageIn:(300@160 corner:340@200)) inspect |
|
6681 |
" |
|
6682 |
||
6683 |
"Created: 20.9.1995 / 01:24:20 / claus" |
|
6684 |
! ! |
|
6685 |
||
6686 |
!Image methodsFor:'printing & storing'! |
|
6687 |
||
6688 |
storeOn:aStream |
|
592 | 6689 |
"append a printed representation of the receiver to aStream, |
6690 |
from which a copy of it can be reconstructed." |
|
6691 |
||
283 | 6692 |
aStream nextPutAll:'(' , self class name , ' new)'. |
6693 |
aStream nextPutAll:' width: '. width storeOn:aStream. |
|
6694 |
aStream nextPutAll:'; height: '. height storeOn:aStream. |
|
6695 |
aStream nextPutAll:'; photometric:('. photometric storeOn:aStream. |
|
6696 |
aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream. |
|
6697 |
aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. |
|
6698 |
aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '. |
|
6699 |
colorMap notNil ifTrue:[ |
|
592 | 6700 |
aStream nextPutAll:'; colorMap:('. |
6701 |
colorMap storeOn:aStream. |
|
6702 |
aStream nextPutAll:')'. |
|
283 | 6703 |
]. |
6704 |
aStream nextPutAll:'; yourself' |
|
592 | 6705 |
|
6706 |
"Modified: 23.4.1996 / 11:18:05 / cg" |
|
0 | 6707 |
! ! |
6708 |
||
6709 |
!Image methodsFor:'private'! |
|
6710 |
||
193 | 6711 |
bestSupportedImageFormatFor:aDevice |
6712 |
"scan through the image formats as supported by aDevice, |
|
6713 |
and return the best to use when the receiver is to be represented |
|
6714 |
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
|
6715 |
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
|
6716 |
|
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6717 |
|bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel | |
193 | 6718 |
|
6719 |
myDepth := self bitsPerPixel. |
|
6720 |
maxBitsPerPixel := 0. |
|
6721 |
||
6722 |
aDevice supportedImageFormats do:[:entry | |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6723 |
|deviceImageDepth deviceImageBitsPerPixel| |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6724 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6725 |
deviceImageDepth := entry at:#depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6726 |
deviceImageBitsPerPixel := entry at:#bitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6727 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6728 |
deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6729 |
maxInfo := entry. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6730 |
"/ maxBitsPerPixel := deviceImageBitsPerPixel. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6731 |
"/ maxDepth := deviceImageDepth. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6732 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6733 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6734 |
deviceImageDepth >= myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6735 |
deviceImageDepth == myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6736 |
"/ take the better one ... |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6737 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6738 |
or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth) |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6739 |
and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6740 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6741 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6742 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6743 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6744 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6745 |
"/ take the next-larger depth |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6746 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6747 |
or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6748 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6749 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6750 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6751 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6752 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6753 |
]. |
193 | 6754 |
]. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6755 |
|
193 | 6756 |
bestDeviceDepth isNil ifTrue:[ |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6757 |
maxBitsPerPixel == 0 ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6758 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6759 |
"/ oops - nothing appropriate |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6760 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6761 |
maxInfo notNil ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6762 |
^ maxInfo |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6763 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6764 |
bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6765 |
bestInfo := IdentityDictionary new. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6766 |
bestInfo at:#depth put:bestDeviceDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6767 |
bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6768 |
bestInfo at:#padding put:32. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6769 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6770 |
bestInfo := maxInfo. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6771 |
] |
193 | 6772 |
]. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6773 |
^ bestInfo |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6774 |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6775 |
"Modified: 14.6.1996 / 14:46:40 / cg" |
283 | 6776 |
! |
6777 |
||
6778 |
colormapFromImage:anImage |
|
6779 |
"setup the receivers colormap from another image. |
|
6780 |
Color precision may be lost, if conversion is from a higher depth |
|
6781 |
image. This does not convert any pixel values; it is non-public helper |
|
6782 |
for fromImage:/fromSubImake:" |
|
6783 |
||
6784 |
samplesPerPixel == 3 ifTrue:[ |
|
6785 |
photometric := #rgb |
|
6786 |
] ifFalse:[ |
|
6787 |
photometric := anImage photometric. |
|
6788 |
photometric == #palette ifTrue:[ |
|
6789 |
colorMap := anImage colorMap copy. |
|
6790 |
" |
|
6791 |
must compress the colormap, if source image has higher depth |
|
6792 |
than myself. |
|
6793 |
" |
|
6794 |
anImage bitsPerPixel > self bitsPerPixel ifTrue:[ |
|
6795 |
" |
|
6796 |
get used colors are extracted into our colorMap |
|
6797 |
(the at-put below will set the pixelValue according the |
|
6798 |
new colorIndex |
|
6799 |
" |
|
6800 |
colorMap := anImage usedColors asArray. |
|
6801 |
colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[ |
|
6802 |
'IMAGE: possibly too many colors in image' errorPrintNL |
|
6803 |
] |
|
6804 |
] |
|
6805 |
] |
|
6806 |
]. |
|
6807 |
||
6808 |
"Created: 20.9.1995 / 00:58:42 / claus" |
|
6809 |
! |
|
6810 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6811 |
greyByteMapForRange:range |
798 | 6812 |
"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
|
6813 |
in the range 0..range. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6814 |
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
|
6815 |
The values are rounded towards the nearest pixel." |
798 | 6816 |
|
808 | 6817 |
|d n greyMap r| |
6818 |
||
6819 |
r := range. |
|
6820 |
r == 256 ifTrue:[ |
|
6821 |
r := 255 |
|
798 | 6822 |
]. |
6823 |
||
6824 |
photometric == #palette ifTrue:[ |
|
808 | 6825 |
n := colorMap size. |
6826 |
greyMap := ByteArray new:n. |
|
6827 |
||
6828 |
1 to:n do:[:i | |
|
6829 |
greyMap at:i put:(r * (colorMap at:i) brightness) rounded |
|
798 | 6830 |
]. |
6831 |
] ifFalse:[ |
|
808 | 6832 |
d := self bitsPerPixel. |
6833 |
n := 1 bitShift:d. |
|
6834 |
n >= 4096 ifTrue:[ |
|
6835 |
self error:'size not supported - too large'. |
|
6836 |
^ nil |
|
6837 |
]. |
|
6838 |
greyMap := ByteArray new:n. |
|
6839 |
||
6840 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6841 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6842 |
1 to:n do:[:i | |
808 | 6843 |
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
|
6844 |
]. |
798 | 6845 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6846 |
1 to:n do:[:i | |
808 | 6847 |
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
|
6848 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6849 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6850 |
"/ we are done |
798 | 6851 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6852 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6853 |
greyMap reverse |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6854 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6855 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6856 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6857 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6858 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6859 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6860 |
]. |
808 | 6861 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6862 |
^ greyMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6863 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6864 |
" |
808 | 6865 |
Depth8Image new greyByteMapForRange:256 |
6866 |
||
6867 |
Depth8Image new greyByteMapForRange:64 |
|
6868 |
Depth4Image new greyByteMapForRange:64 |
|
6869 |
||
6870 |
Depth4Image new greyByteMapForRange:1 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6871 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6872 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6873 |
"Created: 8.6.1996 / 08:34:14 / cg" |
808 | 6874 |
"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
|
6875 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6876 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6877 |
greyMapForRange:range |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6878 |
"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
|
6879 |
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
|
6880 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6881 |
|d r |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6882 |
n "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6883 |
greyArray| |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6884 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6885 |
d := self bitsPerPixel. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6886 |
n := 1 bitShift:d. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6887 |
n >= 4096 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6888 |
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
|
6889 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6890 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6891 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6892 |
greyArray := Array new:n. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6893 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6894 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6895 |
1 to:(colorMap size) do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6896 |
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
|
6897 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6898 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6899 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6900 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6901 |
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
|
6902 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6903 |
] ifFalse:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6904 |
r := range asFloat. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6905 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6906 |
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
|
6907 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6908 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6909 |
"/ we are done |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6910 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6911 |
photometric == #whiteIs0 ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6912 |
greyArray reverse |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6913 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6914 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6915 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6916 |
] |
798 | 6917 |
] |
6918 |
] |
|
6919 |
]. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6920 |
^ greyArray |
798 | 6921 |
|
6922 |
" |
|
6923 |
Depth8Image new greyMapForRange:64 |
|
6924 |
Depth4Image new greyMapForRange:64 |
|
6925 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6926 |
Depth16Image new greyMapForRange:1 |
798 | 6927 |
Depth4Image new greyMapForRange:1 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6928 |
Depth2Image new greyMapForRange:1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6929 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6930 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6931 |
"Modified: 10.6.1996 / 10:37:40 / cg" |
798 | 6932 |
! |
6933 |
||
283 | 6934 |
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels |
6935 |
into:dstBytes offset:dstStart factor:mX |
|
6936 |
||
6937 |
"magnify a single pixel row - can only magnify by integer factors, |
|
6938 |
can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast." |
|
6939 |
||
6940 |
^ self subclassResponsibility |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6941 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6942 |
|
816 | 6943 |
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
6944 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6945 |
pixels interpreted as greyValues, 0 is black, |
|
6946 |
create a device form for it" |
|
6947 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6948 |
|f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6949 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6950 |
f := Form width:width height:height depth:depth on:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6951 |
f isNil ifTrue:[^ nil]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6952 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6953 |
f bits:bits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6954 |
f initGC. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6955 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6956 |
(aDevice blackpixel ~~ 0) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6957 |
"/ have to invert bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6958 |
f function:#copyInverted |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6959 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6960 |
aDevice drawBits:bits depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6961 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6962 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6963 |
into:(f id) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6964 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6965 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6966 |
with:(f gcId). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6967 |
^ f |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6968 |
|
816 | 6969 |
"Created: 10.6.1996 / 20:10:31 / cg" |
6970 |
! |
|
6971 |
||
6972 |
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
6973 |
"given the bits of a monochrome bitmap, 8-bit padded and |
|
6974 |
0-bits as black, create a device form for it" |
|
6975 |
||
6976 |
monoBits invert. |
|
6977 |
^ (Form width:width height:height fromArray:monoBits on:aDevice) |
|
6978 |
colorMap:(Array with:Color black with:Color white). |
|
6979 |
||
6980 |
"Created: 10.6.1996 / 20:18:09 / cg" |
|
6981 |
"Modified: 10.6.1996 / 20:31:24 / cg" |
|
6982 |
! |
|
6983 |
||
6984 |
makeDevicePixmapOn:aDevice depth:depth fromArray:bits |
|
6985 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6986 |
pixels interpreted as in the devices colormap, |
|
6987 |
create a device form for it" |
|
6988 |
||
6989 |
|f| |
|
6990 |
||
6991 |
f := Form width:width height:height depth:depth on:aDevice. |
|
6992 |
f isNil ifTrue:[^ nil]. |
|
6993 |
||
6994 |
f bits:bits. |
|
6995 |
f initGC. |
|
6996 |
||
6997 |
aDevice drawBits:bits depth:depth |
|
6998 |
width:width height:height |
|
6999 |
x:0 y:0 |
|
7000 |
into:(f id) |
|
7001 |
x:0 y:0 |
|
7002 |
width:width height:height |
|
7003 |
with:(f gcId). |
|
7004 |
^ f |
|
7005 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
7006 |
"Created: 10.6.1996 / 17:56:08 / cg" |
816 | 7007 |
"Modified: 10.6.1996 / 20:11:27 / cg" |
2 | 7008 |
! ! |
0 | 7009 |
|
283 | 7010 |
!Image methodsFor:'queries'! |
7011 |
||
7012 |
averageColor |
|
7013 |
"return the average color of the image. |
|
7014 |
This usually only makes sense for textures and patterns |
|
7015 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
7016 |
Notice, that for the above purpose, it is usually ok to process |
|
7017 |
a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle" |
|
7018 |
||
7019 |
^ self averageColorIn:(0@0 corner:(width-1)@(height-1)) |
|
7020 |
! |
|
7021 |
||
7022 |
averageColorIn:aRectangle |
|
7023 |
"return the images average color in an area. |
|
7024 |
The implementation below is slow - so you may want to |
|
7025 |
create tuned versions for DepthXImage if you plan to do |
|
7026 |
heavy image processing ... |
|
7027 |
(also, creating tuned versions of the enumeration messages helps a lot)" |
|
7028 |
||
7029 |
|x0 "{ Class:SmallInteger }" |
|
7030 |
y0 "{ Class:SmallInteger }" |
|
7031 |
x1 "{ Class:SmallInteger }" |
|
7032 |
y1 "{ Class:SmallInteger }" |
|
7033 |
sumRed sumGreen sumBlue n| |
|
7034 |
||
7035 |
sumRed := sumGreen := sumBlue := 0. |
|
7036 |
y0 := aRectangle top. |
|
7037 |
y1 := aRectangle bottom. |
|
7038 |
x0 := aRectangle left. |
|
7039 |
x1 := aRectangle right. |
|
7040 |
||
7041 |
self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY | |
|
7042 |
sumRed := sumRed + colorAtXY red. |
|
7043 |
sumGreen := sumGreen + colorAtXY green. |
|
7044 |
sumBlue := sumBlue + colorAtXY blue. |
|
7045 |
]. |
|
7046 |
n := (x1 - x0 + 1) * (y1 - y0 + 1). |
|
7047 |
^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n) |
|
7048 |
! |
|
7049 |
||
7050 |
bitsPerPixel |
|
7051 |
"return the number of bits per pixel" |
|
7052 |
||
7053 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
|
7054 |
! |
|
7055 |
||
7056 |
bitsPerRow |
|
7057 |
"return the number of bits in one scanline of the image" |
|
7058 |
||
7059 |
^ width * (self bitsPerPixel). |
|
7060 |
! |
|
7061 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7062 |
blueBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7063 |
"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
|
7064 |
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
|
7065 |
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
|
7066 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7067 |
|blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7068 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7069 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7070 |
"/ 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
|
7071 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7072 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7073 |
blueBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7074 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7075 |
^ pixel bitAnd:(1 bitShift:blueBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7076 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7077 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7078 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7079 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7080 |
"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
|
7081 |
"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
|
7082 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7083 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7084 |
blueComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7085 |
"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
|
7086 |
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
|
7087 |
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
|
7088 |
|
854 | 7089 |
|blueBits "{ Class: SmallInteger }" |
7090 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7091 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7092 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7093 |
"/ 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
|
7094 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7095 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7096 |
blueBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7097 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7098 |
s := (1 bitShift:blueBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7099 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7100 |
^ 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
|
7101 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7102 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7103 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7104 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7105 |
"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
|
7106 |
"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
|
7107 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7108 |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7109 |
bounds |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7110 |
"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
|
7111 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7112 |
^ 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
|
7113 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7114 |
"Created: 13.5.1996 / 10:27:06 / cg" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7115 |
! |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7116 |
|
283 | 7117 |
brightness |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7118 |
"return the (average) brightness of the image. |
283 | 7119 |
This usually only makes sense for textures and patterns |
7120 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
7121 |
Notice, that for the above purpose, only a subimage is inspected here" |
|
7122 |
||
7123 |
^ (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
|
7124 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7125 |
"Modified: 8.6.1996 / 08:46:46 / cg" |
283 | 7126 |
! |
7127 |
||
7128 |
bytesPerRow |
|
7129 |
"return the number of bytes in one scanline of the image" |
|
7130 |
||
7131 |
|bitsPerRow bytesPerRow| |
|
7132 |
||
7133 |
bitsPerRow := width * (self bitsPerPixel). |
|
7134 |
bytesPerRow := bitsPerRow // 8. |
|
7135 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
7136 |
bytesPerRow := bytesPerRow + 1 |
|
7137 |
]. |
|
7138 |
^ bytesPerRow |
|
7139 |
! |
|
7140 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7141 |
colorFromValue:pixelValue |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7142 |
"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
|
7143 |
Pixel values start with 0." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7144 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7145 |
|maxPixel r g b| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7146 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7147 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7148 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7149 |
^ Color gray:(pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7150 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7151 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7152 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7153 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7154 |
^ Color gray:100 - (pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7155 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7156 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7157 |
photometric == #palette ifTrue:[ |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7158 |
pixelValue >= colorMap size ifTrue:[ |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7159 |
^ Color black |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7160 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7161 |
^ colorMap at:(pixelValue + 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7162 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7163 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7164 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7165 |
r := self redComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7166 |
g := self greenComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7167 |
b := self blueComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7168 |
^ 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
|
7169 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7170 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7171 |
self error:'invalid photometric' |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7172 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7173 |
"Created: 8.6.1996 / 08:46:18 / cg" |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7174 |
"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
|
7175 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7176 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7177 |
greenBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7178 |
"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
|
7179 |
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
|
7180 |
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
|
7181 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7182 |
|blueBits greenBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7183 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7184 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7185 |
"/ 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
|
7186 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7187 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7188 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7189 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7190 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7191 |
^ (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
|
7192 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7193 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7194 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7195 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7196 |
"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
|
7197 |
"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
|
7198 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7199 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7200 |
greenComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7201 |
"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
|
7202 |
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
|
7203 |
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
|
7204 |
|
854 | 7205 |
|greenBits "{ Class: SmallInteger }" |
7206 |
blueBits "{ Class: SmallInteger }" |
|
7207 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7208 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7209 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7210 |
"/ 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
|
7211 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7212 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7213 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7214 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7215 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7216 |
s := (1 bitShift:greenBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7217 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7218 |
^ 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
|
7219 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7220 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7221 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7222 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7223 |
"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
|
7224 |
"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
|
7225 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7226 |
|
674 | 7227 |
heightOn:aGC |
7228 |
"return my height, if displayed on aGC; |
|
7229 |
since my height is independent of the device (the number of pixels), |
|
7230 |
return the pixel-height" |
|
7231 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7232 |
^ height |
674 | 7233 |
|
7234 |
"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
|
7235 |
"Modified: 13.5.1996 / 10:26:36 / cg" |
674 | 7236 |
! |
7237 |
||
283 | 7238 |
isImage |
7239 |
"return true, if the receiver is some kind of image; |
|
7240 |
true is returned here - the method is redefined from Object." |
|
7241 |
||
7242 |
^ true |
|
7243 |
! |
|
7244 |
||
7245 |
isImageOrForm |
|
7246 |
"return true, if the receiver is some kind of image or form; |
|
7247 |
true is returned here - the method is redefined from Object." |
|
7248 |
||
7249 |
^ true |
|
7250 |
! |
|
7251 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7252 |
redBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7253 |
"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
|
7254 |
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
|
7255 |
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
|
7256 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7257 |
|redBits greenBits blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7258 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7259 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7260 |
"/ 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
|
7261 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7262 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7263 |
redBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7264 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7265 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7266 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7267 |
^ (pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7268 |
bitAnd:(1 bitShift:redBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7269 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7270 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7271 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7272 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7273 |
"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
|
7274 |
"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
|
7275 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7276 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7277 |
redComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7278 |
"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
|
7279 |
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
|
7280 |
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
|
7281 |
|
854 | 7282 |
|redBits "{ Class: SmallInteger }" |
7283 |
greenBits "{ Class: SmallInteger }" |
|
7284 |
blueBits "{ Class: SmallInteger }" |
|
7285 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7286 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7287 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7288 |
"/ 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
|
7289 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7290 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7291 |
redBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7292 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7293 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7294 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7295 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7296 |
s := (1 bitShift:redBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7297 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7298 |
^ 100.0 / s * |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7299 |
((pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7300 |
bitAnd:(1 bitShift:redBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7301 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7302 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7303 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7304 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7305 |
"Created: 8.6.1996 / 08:45:30 / cg" |
854 | 7306 |
"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
|
7307 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7308 |
|
283 | 7309 |
usedColors |
7310 |
"return a collection of colors used in the receiver." |
|
7311 |
||
7312 |
|usedValues max| |
|
7313 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7314 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7315 |
"/ 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
|
7316 |
"/ 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
|
7317 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7318 |
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
|
7319 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7320 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7321 |
|
283 | 7322 |
usedValues := self usedValues asArray. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7323 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7324 |
^ usedValues collect:[:val | (colorMap at:val+1)] |
283 | 7325 |
]. |
7326 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7327 |
"/ (photometric == #blackIs0 or:[photometric == #whiteIs0]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7328 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7329 |
max := (1 bitShift:self depth) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7330 |
^ usedValues collect:[:val | (Color gray:(100 * val / max ))] |
283 | 7331 |
|
7332 |
" |
|
7333 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
7334 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
7335 |
(Image fromFile:'ttt.tiff') usedColors |
|
7336 |
" |
|
746 | 7337 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7338 |
"Modified: 8.6.1996 / 09:04:56 / cg" |
283 | 7339 |
! |
7340 |
||
7341 |
usedValues |
|
7342 |
"return a collection of color values used in the receiver. |
|
7343 |
Notice, that the interpretation of the pixels depends on the photometric |
|
7344 |
of the image. |
|
7345 |
This is a general and therefore slow implementation; subclasses |
|
7346 |
may want to redefine this method for more performance." |
|
7347 |
||
7348 |
|set| |
|
7349 |
||
7350 |
set := IdentitySet new. |
|
7351 |
self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel | |
|
7352 |
set add:pixel |
|
7353 |
]. |
|
7354 |
^ set |
|
7355 |
||
7356 |
" |
|
7357 |
(Image fromFile:'bitmaps/garfield.gif') usedValues |
|
7358 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedValues |
|
7359 |
(Image fromFile:'ttt.tiff') usedValues |
|
7360 |
" |
|
674 | 7361 |
! |
7362 |
||
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7363 |
valueFromColor:color |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7364 |
"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
|
7365 |
Non-representable colors return nil." |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7366 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7367 |
|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
|
7368 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7369 |
photometric == #whiteIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7370 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7371 |
^ maxPixel - (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7372 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7373 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7374 |
photometric == #blackIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7375 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7376 |
^ (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7377 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7378 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7379 |
photometric == #palette ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7380 |
pixel := colorMap indexOf:color. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7381 |
pixel == 0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7382 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7383 |
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
|
7384 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7385 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7386 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7387 |
^ pixel - 1 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7388 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7389 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7390 |
photometric == #rgb ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7391 |
samplesPerPixel >= 3 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7392 |
redBits := bitsPerSample at:1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7393 |
greenBits := bitsPerSample at:2. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7394 |
blueBits := bitsPerSample at:3. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7395 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7396 |
"/ map r/g/b to 0..255 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7397 |
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
|
7398 |
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
|
7399 |
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
|
7400 |
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
|
7401 |
^ pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7402 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7403 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7404 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7405 |
self error:'format not supported'. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7406 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7407 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7408 |
"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
|
7409 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7410 |
|
674 | 7411 |
widthOn:aGC |
7412 |
"return my width, if displayed on aGC; |
|
7413 |
since my width is independent of the device (the number of pixels), |
|
7414 |
return the pixel-width" |
|
7415 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7416 |
^ width |
674 | 7417 |
|
7418 |
"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
|
7419 |
"Modified: 13.5.1996 / 10:26:42 / cg" |
283 | 7420 |
! ! |
7421 |
||
7422 |
!Image methodsFor:'saving on file'! |
|
7423 |
||
7424 |
saveOn:aFileName |
|
7425 |
"save the image in a aFileName. The suffix of the filename |
|
7426 |
controls the format. Currently, not all formats may be supported |
|
7427 |
(see ImageReader subclasses implementing save:onFile:)" |
|
7428 |
||
7429 |
" |
|
7430 |
from the extension, get the imageReader class |
|
7431 |
(which should know how to write images as well) |
|
7432 |
" |
|
7433 |
FileFormats associationsDo:[:a | |
|
7434 |
(aFileName endsWith:(a key)) ifTrue:[ |
|
7435 |
^ (a value) save:self onFile:aFileName |
|
7436 |
] |
|
7437 |
]. |
|
7438 |
||
7439 |
" |
|
7440 |
no known extension - could ask user for the format here. |
|
7441 |
currently default to tiff format. |
|
7442 |
" |
|
7443 |
'IMAGE: unknown extension - cannot figure out format - using tiff' errorPrintNL. |
|
7444 |
^ self saveOn:aFileName using:TIFFReader |
|
89 | 7445 |
! |
7446 |
||
283 | 7447 |
saveOn:aFileName using:readerClass |
7448 |
"save the receiver using the representation class" |
|
7449 |
||
7450 |
readerClass save:self onFile:aFileName |
|
7451 |
||
7452 |
" |
|
7453 |
anImage saveOn:'myImage' using:TIFFReader |
|
7454 |
anImage saveOn:'myImage' using:XBMReader |
|
7455 |
" |
|
0 | 7456 |
! ! |
283 | 7457 |
|
7458 |
!Image methodsFor:'screen capture'! |
|
7459 |
||
7460 |
fromScreen:aRectangle |
|
7461 |
"read an image from the display screen" |
|
7462 |
||
7463 |
^ self fromScreen:aRectangle on:Screen current |
|
7464 |
! |
|
7465 |
||
7466 |
fromScreen:aRectangle on:aDevice |
|
7467 |
"read an image from aDevices display screen. |
|
7468 |
Since I have no other displays, only the MonoChrome, StaticGrey |
|
7469 |
and PseudoColor cases have been tested ... |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7470 |
(especially True- and DirectColor may be wrong). |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7471 |
Late note: 24bit rgb now also works." |
283 | 7472 |
|
7473 |
|depth visType |
|
7474 |
x "{ Class: SmallInteger }" |
|
7475 |
y "{ Class: SmallInteger }" |
|
7476 |
w "{ Class: SmallInteger }" |
|
7477 |
h "{ Class: SmallInteger }" |
|
7478 |
dstIndex "{ Class: SmallInteger }" |
|
7479 |
srcIndex "{ Class: SmallInteger }" |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7480 |
srcRow "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7481 |
dstRow "{ Class: SmallInteger }" |
283 | 7482 |
inData tmpData usedPixels mapSize |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7483 |
map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7484 |
info bitsPerPixelIn bytesPerLineIn curs cid rootView |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7485 |
maskR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7486 |
maskG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7487 |
maskB "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7488 |
shR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7489 |
shG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7490 |
shB "{ Class: SmallInteger }" |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7491 |
shR2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7492 |
shG2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7493 |
shB2 "{ Class: SmallInteger }" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7494 |
r "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7495 |
g "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7496 |
b "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7497 |
word| |
283 | 7498 |
|
7499 |
curs := Cursor sourceForm:(Form fromFile:'Camera.xbm') |
|
518 | 7500 |
maskForm:(Form fromFile:'Camera_m.xbm') |
7501 |
hotSpot:16@16. |
|
283 | 7502 |
curs notNil ifTrue:[ |
518 | 7503 |
cid := (curs on:aDevice) id |
283 | 7504 |
]. |
7505 |
||
7506 |
" |
|
7507 |
get some attributes of the display device |
|
7508 |
" |
|
7509 |
visType := aDevice visualType. |
|
7510 |
depth := aDevice depth. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7511 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7512 |
"/ kludge for 15bit XFree server |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7513 |
depth == 15 ifTrue:[ |
518 | 7514 |
depth := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7515 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7516 |
|
283 | 7517 |
(visType == #StaticGray) ifTrue:[ |
518 | 7518 |
(aDevice blackpixel == 0) ifTrue:[ |
7519 |
photometric := #blackIs0 |
|
7520 |
] ifFalse:[ |
|
7521 |
photometric := #whiteIs0 |
|
7522 |
]. |
|
7523 |
samplesPerPixel := 1. |
|
7524 |
bitsPerPixel := depth. |
|
7525 |
bitsPerSample := Array with:bitsPerPixel. |
|
283 | 7526 |
] ifFalse:[ |
518 | 7527 |
((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[ |
7528 |
photometric := #palette. |
|
7529 |
samplesPerPixel := 1. |
|
7530 |
bitsPerPixel := depth. |
|
7531 |
bitsPerSample := Array with:bitsPerPixel. |
|
7532 |
] ifFalse:[ |
|
7533 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
7534 |
photometric := #rgb. |
|
7535 |
samplesPerPixel := 3. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7536 |
"/ bitsPerPixel := depth. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7537 |
"/ bitsPerSample := Array with:aDevice bitsRed |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7538 |
"/ with:aDevice bitsGreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7539 |
"/ with:aDevice bitsBlue |
518 | 7540 |
bitsPerPixel := 24. |
7541 |
bitsPerSample := #(8 8 8). |
|
7542 |
] ifFalse:[ |
|
7543 |
self error:'screen visual not supported'. |
|
7544 |
^ nil |
|
7545 |
] |
|
7546 |
] |
|
283 | 7547 |
]. |
7548 |
||
7549 |
" |
|
7550 |
dont know yet, how the display pads; assume worst case, |
|
7551 |
offering enough space for 32 bit padding |
|
7552 |
" |
|
7553 |
w := width := aRectangle width. |
|
7554 |
h := height := aRectangle height. |
|
7555 |
x := aRectangle left. |
|
7556 |
y := aRectangle top. |
|
7557 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7558 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7559 |
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
|
7560 |
(its too late when info is present ...) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7561 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7562 |
spaceBitsPerPixel := bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7563 |
(bitsPerPixel > 8) ifTrue:[ |
518 | 7564 |
spaceBitsPerPixel := 16. |
7565 |
(bitsPerPixel > 16) ifTrue:[ |
|
7566 |
spaceBitsPerPixel := 32. |
|
7567 |
(bitsPerPixel > 32) ifTrue:[ |
|
7568 |
spaceBitsPerPixel := bitsPerPixel. |
|
7569 |
] |
|
7570 |
] |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7571 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7572 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7573 |
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4. |
283 | 7574 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
7575 |
||
7576 |
" |
|
7577 |
actually have to grabServer ... but thats not yet available |
|
7578 |
" |
|
728 | 7579 |
rootView := aDevice rootView. |
283 | 7580 |
aDevice setActivePointerGrab:rootView. |
7581 |
aDevice grabPointerIn:rootView id |
|
518 | 7582 |
withCursor:cid pointerMode:#async keyboardMode:#sync confineTo:nil. |
283 | 7583 |
|
7584 |
" |
|
7585 |
get the pixels |
|
7586 |
" |
|
7587 |
info := aDevice getBitsFrom:rootView id x:x y:y width:w height:h into:inData. |
|
7588 |
||
7589 |
" |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7590 |
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
|
7591 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7592 |
byteOrder := info at:#byteOrder. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7593 |
bitsPerPixelIn := info at:#bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7594 |
byteOrder ~~ #msbFirst ifTrue:[ |
518 | 7595 |
bitsPerPixelIn == 16 ifTrue:[ |
7596 |
"/ must swap bytes |
|
7597 |
inData swapBytes |
|
7598 |
] ifFalse:[ |
|
7599 |
bitsPerPixelIn == 32 ifTrue:[ |
|
7600 |
"/ must swap longs |
|
7601 |
inData swapLongs |
|
7602 |
] |
|
7603 |
] |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7604 |
]. |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7605 |
|
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7606 |
" |
283 | 7607 |
check, if the devices padding is different .. |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7608 |
or if the bitsPerPixels are different |
283 | 7609 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7610 |
bytesPerLineIn := (info at:#bytesPerLine). "what I got" |
283 | 7611 |
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
|
7612 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7613 |
((bytesPerLine ~~ bytesPerLineIn) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7614 |
or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[ |
518 | 7615 |
tmpData := inData. |
7616 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
7617 |
||
7618 |
srcRow := 1. |
|
7619 |
dstRow := 1. |
|
7620 |
||
7621 |
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[ |
|
7622 |
"/ for now, only 32 -> 24 is supported |
|
7623 |
||
7624 |
maskR := (1 bitShift:aDevice bitsRed) - 1. |
|
7625 |
maskG := (1 bitShift:aDevice bitsGreen) - 1. |
|
7626 |
maskB := (1 bitShift:aDevice bitsBlue) - 1. |
|
7627 |
shR := aDevice shiftRed negated. |
|
7628 |
shG := aDevice shiftGreen negated. |
|
7629 |
shB := aDevice shiftBlue negated. |
|
7630 |
shR2 := (8 - aDevice bitsRed). |
|
7631 |
shG2 := (8 - aDevice bitsGreen). |
|
7632 |
shB2 := (8 - aDevice bitsBlue). |
|
7633 |
||
7634 |
((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[ |
|
7635 |
"/ 'reformatting 32->24...' printNL. |
|
7636 |
1 to:h do:[:hi | |
|
7637 |
srcIndex := srcRow. |
|
7638 |
dstIndex := dstRow. |
|
7639 |
||
7640 |
1 to:w do:[:wi | |
|
7641 |
word := tmpData doubleWordAt:srcIndex MSB:true. |
|
7642 |
r := (word bitShift:shR) bitAnd:maskR. |
|
7643 |
g := (word bitShift:shG) bitAnd:maskG. |
|
7644 |
b := (word bitShift:shB) bitAnd:maskB. |
|
7645 |
||
7646 |
inData at:dstIndex put:r. |
|
7647 |
inData at:dstIndex+1 put:g. |
|
7648 |
inData at:dstIndex+2 put:b. |
|
7649 |
srcIndex := srcIndex + 4. |
|
7650 |
dstIndex := dstIndex + 3. |
|
7651 |
]. |
|
7652 |
dstRow := dstRow + bytesPerLine. |
|
7653 |
srcRow := srcRow + bytesPerLineIn |
|
7654 |
] |
|
7655 |
] ifFalse:[ |
|
7656 |
((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[ |
|
7657 |
"/ 'reformatting 16->24...' printNL. |
|
7658 |
1 to:h do:[:hi | |
|
7659 |
srcIndex := srcRow. |
|
7660 |
dstIndex := dstRow. |
|
7661 |
||
7662 |
1 to:w do:[:wi | |
|
7663 |
word := tmpData wordAt:srcIndex MSB:true. |
|
7664 |
r := (word bitShift:shR) bitAnd:maskR. |
|
7665 |
g := (word bitShift:shG) bitAnd:maskG. |
|
7666 |
b := (word bitShift:shB) bitAnd:maskB. |
|
7667 |
||
7668 |
inData at:dstIndex put:(r bitShift:shR2). |
|
7669 |
inData at:dstIndex+1 put:(g bitShift:shG2). |
|
7670 |
inData at:dstIndex+2 put:(b bitShift:shB2). |
|
7671 |
srcIndex := srcIndex + 2. |
|
7672 |
dstIndex := dstIndex + 3. |
|
7673 |
]. |
|
7674 |
dstRow := dstRow + bytesPerLine. |
|
7675 |
srcRow := srcRow + bytesPerLineIn |
|
7676 |
] |
|
7677 |
] ifFalse:[ |
|
7678 |
('IMAGE: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' , |
|
7679 |
bitsPerPixel printString) errorPrintNL. |
|
7680 |
^ nil |
|
7681 |
] |
|
7682 |
]. |
|
7683 |
] ifFalse:[ |
|
7684 |
" |
|
7685 |
repad in the buffer |
|
7686 |
" |
|
7687 |
1 to:h do:[:hi | |
|
7688 |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1) |
|
7689 |
with:tmpData startingAt:srcRow. |
|
7690 |
dstRow := dstRow + bytesPerLine. |
|
7691 |
srcRow := srcRow + bytesPerLineIn |
|
7692 |
] |
|
7693 |
] |
|
283 | 7694 |
] ifFalse:[ |
518 | 7695 |
(bytesPerLine * height) ~~ inData size ifTrue:[ |
7696 |
tmpData := inData. |
|
7697 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
7698 |
inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1 |
|
7699 |
] |
|
283 | 7700 |
]. |
7701 |
bytes := inData. |
|
7702 |
||
7703 |
"info printNL." |
|
7704 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7705 |
((visType == #StaticGray) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7706 |
or:[visType == #TrueColor |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7707 |
or:[visType == #DirectColor]]) ifTrue:[ |
518 | 7708 |
" |
7709 |
were done, the pixel values are the rgb/grey values |
|
7710 |
" |
|
283 | 7711 |
] ifFalse:[ |
518 | 7712 |
" |
7713 |
what we have now are the color numbers - still need the r/g/b values. |
|
7714 |
find out, which colors are in the picture |
|
7715 |
" |
|
7716 |
usedPixels := inData usedValues. |
|
7717 |
mapSize := usedPixels max + 1. |
|
7718 |
||
7719 |
"get the palette" |
|
7720 |
map := Array new:mapSize. |
|
7721 |
usedPixels do:[:colorIndex | |
|
7722 |
|i| |
|
7723 |
||
7724 |
i := colorIndex + 1. |
|
7725 |
aDevice getRGBFrom:colorIndex into:[:r :g :b | |
|
7726 |
map at:i put:(Color red:r green:g blue:b) |
|
7727 |
] |
|
7728 |
]. |
|
7729 |
colorMap := map. |
|
283 | 7730 |
]. |
7731 |
||
7732 |
aDevice ungrabPointer. |
|
7733 |
||
7734 |
" |
|
7735 |
(Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display |
|
7736 |
(Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display |
|
7737 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7738 |
|
518 | 7739 |
"Modified: 7.3.1996 / 19:17:33 / cg" |
283 | 7740 |
! ! |
7741 |
||
7742 |
!Image class methodsFor:'documentation'! |
|
7743 |
||
7744 |
version |
|
891 | 7745 |
^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.108 1996-06-18 21:24:09 cg Exp $' |
650 | 7746 |
! ! |
283 | 7747 |
Image initialize! |