author | Claus Gittinger <cg@exept.de> |
Mon, 17 Jun 1996 11:48:22 +0200 | |
changeset 873 | f44d57cc8d05 |
parent 869 | 464ffa8c0c67 |
child 874 | cce9c1029d38 |
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 |
305
4ece2bdf1011
handle StaticColor visual (OS/2 server has this)
Claus Gittinger <cg@exept.de>
parents:
286
diff
changeset
|
15 |
photometric device deviceForm monoDeviceForm fullColorDeviceForm' |
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
16 |
classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors |
305
4ece2bdf1011
handle StaticColor visual (OS/2 server has this)
Claus Gittinger <cg@exept.de>
parents:
286
diff
changeset
|
17 |
CollectGarbageWhenRunningOutOfColors FileFormats' |
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
18 |
poolDictionaries:'' |
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
19 |
category:'Graphics-Images' |
0 | 20 |
! |
21 |
||
22 |
!Image class methodsFor:'documentation'! |
|
23 |
||
46 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
72 | 27 |
All Rights Reserved |
46 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
0 | 38 |
documentation |
39 |
" |
|
46 | 40 |
this class provides (some time in the future) representation |
41 |
for all kinds of images (monochrome, greyscale and color) |
|
592 | 42 |
and will finally replace Form. |
622 | 43 |
For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported. |
592 | 44 |
|
45 |
An Image keeps all of its information in a device independent way, |
|
46 |
but may be associated to a device. |
|
47 |
The data held keeps all information which was originally present, |
|
48 |
even if the display-device has lower resolution. |
|
46 | 49 |
Therefore, it is possible to process and manipulate images without loosing |
50 |
color information - even on low color resolution displays. |
|
51 |
||
52 |
Usually, you get a device specific representation of the image by |
|
592 | 53 |
sending the |
54 |
'on:aDevice' |
|
55 |
message to it, which will create a (possibly dithered) device-form, |
|
56 |
representing the image using the currently available colors. |
|
46 | 57 |
|
286 | 58 |
In rare cases, an explicit monochrome representation of the image is needed |
46 | 59 |
(X servers take monochrome icons only), this can be created by sending |
592 | 60 |
it the message |
61 |
'monochromeOn:aDevice'. |
|
0 | 62 |
|
46 | 63 |
Also, it is planned to generate another hi-color resolution version, |
286 | 64 |
which uses its own colormap and allows the use of all 256 colors on an 8bit display |
65 |
(this is not currently implemented). |
|
66 |
||
67 |
An images pixel interpretation is controlled by the photometric instance variable |
|
68 |
and (if that is #palette) a colorMap. |
|
69 |
This is in contrast to the ST-80 way, where all of this info is in the colorMap |
|
70 |
(and using specialized colorMaps for b&w / greyScale images). |
|
71 |
This may change in future versions for more application compatibility. |
|
72 |
||
73 |
To convert pictures from/to external file-formats, image readers are used |
|
592 | 74 |
which have the file-format knowledge built in. |
75 |
There are readers for most common formats available |
|
286 | 76 |
(see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.). |
77 |
||
78 |
File formats are handled by subclasses of ImageReader, which understand |
|
79 |
a specific format. You can add more readers, by adding an association |
|
80 |
such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats' |
|
81 |
(see the classes #initialize method, which dsets up some default, and the |
|
82 |
patches/display.rc files, which add more). |
|
83 |
||
84 |
Some algorithms used here (especially dithering & color allocation) are |
|
46 | 85 |
experimental and far from being perfect (some are very slow). |
592 | 86 |
For now, the most common cases have been optimized and perform reasonably |
87 |
fast - however, with uncommon depth/visualType combinations, you may |
|
88 |
run into slower fallback methods ... |
|
89 |
||
90 |
Much more work is needed if you plan to do heavy image processing and will |
|
91 |
(may) be done in the future if there is a demand for it ... |
|
92 |
Dithering can be controlled by the DitherAlgorithm classVariable: |
|
2 | 93 |
|
46 | 94 |
DitherAlgorithm: |
0 | 95 |
|
46 | 96 |
nil a simple threshold algorithm |
592 | 97 |
(i.e. for mono, p<0.5 -> black, p>=0.5 -> white) |
0 | 98 |
|
46 | 99 |
#pattern patterned dither |
592 | 100 |
(for p, take dithered color to fill pixel; |
101 |
uses dithering in color-class) |
|
0 | 102 |
|
46 | 103 |
#error error diffusion dither (Floyd-Steinberg) |
592 | 104 |
planned - not yet implemented. |
105 |
||
106 |
||
107 |
||
108 |
[instance variables:] |
|
109 |
||
110 |
width <Integer> the width in pixels |
|
111 |
height <Integer> the height in pixels |
|
112 |
bytes <ByteArray> the full image information |
|
113 |
photometric <Symbol> #rgb, #palette, #blackIs0 or #whiteIs0 |
|
114 |
samplesPerPixel <Integer> the number of planes |
|
115 |
bitsPerSample <Array> the number of bits per plane |
|
116 |
||
117 |
colorMap <Array> only if photometric is #pseudocolor; |
|
118 |
maps pixel values to r/g/b values. |
|
119 |
||
120 |
device <Workstation> the device on which deviceForm, |
|
121 |
monoDeviceForm and lowResDeviceForm are |
|
122 |
||
123 |
deviceForm <Form> the device form which gives the best |
|
124 |
possible aproximation of the image on |
|
125 |
device using standard colors. |
|
126 |
||
127 |
monoDeviceForm <Form> the device form which gives a monochrome |
|
128 |
aproximation of the image on device. |
|
129 |
||
130 |
fullColorDeviceForm <Form> the device form which gives the best |
|
131 |
possible aproximation of the image on |
|
132 |
device using private colors. |
|
133 |
||
134 |
[class variables:] |
|
135 |
||
136 |
Lobby <Registry> keeps track of known images |
|
137 |
(for resource freeing with garbage collector) |
|
138 |
||
139 |
DitherAlgorithm <Symbol> defines how to dither |
|
140 |
||
141 |
NumberOfDitherColors <Integer> defines, how many dither colors to use |
|
142 |
||
143 |
FileFormats <Dictionary> associates filename extensions to |
|
144 |
image reader classes (now set-up in startup-file) |
|
145 |
||
146 |
CollectGarbageWhenRunningOutOfColors |
|
147 |
<Boolean> if true, and we run out of available |
|
148 |
device colors during creation of a |
|
149 |
device image, collect garbage for |
|
150 |
possible image reclamation. |
|
151 |
If false, proceed immediately. |
|
152 |
Default is true. |
|
158 | 153 |
|
46 | 154 |
todo: |
592 | 155 |
there is currently no mask stored/available in the image itself; currently masks |
156 |
have to be stored as separate bitmaps. |
|
157 |
(which is bad for image-file formats, which provide a mask) |
|
158 |
Thus, currently, all images are completely opaque. |
|
159 |
||
160 |
[See also:] |
|
161 |
Form Icon ImageReader |
|
611 | 162 |
|
163 |
[author:] |
|
164 |
Claus Gittinger |
|
0 | 165 |
" |
649 | 166 |
! |
167 |
||
168 |
examples |
|
169 |
" |
|
170 |
reading from a file (many formats are supported): |
|
171 |
[exBegin] |
|
172 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
173 |
[exEnd] |
|
174 |
[exBegin] |
|
175 |
(Image fromFile:'bitmaps/SmalltalkX.xbm') inspect |
|
176 |
[exEnd] |
|
177 |
[exBegin] |
|
178 |
(Image fromFile:'bitmaps/okSmily_up.bmp') inspect |
|
179 |
[exEnd] |
|
180 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
181 |
inline image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
182 |
default: depth=1 & #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
183 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
184 |
(Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
185 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
186 |
2r10000001 |
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 |
2r11111111 )) inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
193 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
194 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
195 |
with #whiteIs0 photometric |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
196 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
197 |
((Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
198 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
199 |
2r10000001 |
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 |
2r11111111 )) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
206 |
photometric:#whiteIs0) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
207 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
208 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
209 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
210 |
with a colorMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
211 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
212 |
((Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
213 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
214 |
2r10000001 |
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 |
2r11111111 )) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
221 |
colorMap:(Array with:(Color red) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
222 |
with:(Color yellow))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
223 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
224 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
225 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
226 |
a depth4 greyScale image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
227 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
228 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
229 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
230 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
231 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
232 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
233 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
234 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
235 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
236 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
237 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
238 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
239 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
240 |
the following has the same effect: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
241 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
242 |
((Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
243 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
244 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
245 |
depth:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
246 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
247 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
248 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
249 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
250 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
251 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
252 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
253 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
254 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
255 |
with reverse grey-interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
256 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
257 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
258 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
259 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
260 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
261 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
262 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
263 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
264 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
265 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
266 |
photometric:#whiteIs0; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
267 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
268 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
269 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
270 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
271 |
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
|
272 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
273 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
274 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
275 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
276 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
277 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
278 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
279 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
280 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
281 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
282 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
283 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
284 |
bitsPerSample:#(1 1 1); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
285 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
286 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
287 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
288 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
289 |
with 1/2/1 rgb interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
290 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
291 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
292 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
293 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
294 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
295 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
296 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
297 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
298 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
299 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
300 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
301 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
302 |
bitsPerSample:#(1 2 1); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
303 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
304 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
305 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
306 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
307 |
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
|
308 |
[exBegin] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
309 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
310 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
311 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
312 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
313 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
314 |
fromArray:#[ 16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
315 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
316 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
317 |
16rcd 16ref ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
318 |
i photometric:#rgb. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
319 |
i samplesPerPixel:3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
320 |
i bitsPerSample:#(2 2 0). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
321 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
322 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
323 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
324 |
[exEnd] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
325 |
|
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 |
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
|
328 |
[exBegin] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
329 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
330 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
331 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
332 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
333 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
334 |
fromArray:#[ 16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
335 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
336 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
337 |
16rcd 16ref ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
338 |
i photometric:#rgb. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
339 |
i samplesPerPixel:3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
340 |
i bitsPerSample:#(0 0 4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
341 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
342 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
343 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
344 |
[exEnd] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
345 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
346 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
347 |
a 2plane greyscale image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
348 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
349 |
((Depth2Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
350 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
351 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
352 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
353 |
4r0123 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
354 |
4r1230 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
355 |
4r2301 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
356 |
4r3012 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
357 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
358 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
359 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
360 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
361 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
362 |
with colors: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
363 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
364 |
((Depth2Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
365 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
366 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
367 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
368 |
4r0123 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
369 |
4r1230 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
370 |
4r2301 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
371 |
4r3012 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
372 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
373 |
colorMap:(Array with:(Color black) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
374 |
with:(Color red) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
375 |
with:(Color green) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
376 |
with:(Color blue)); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
377 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
378 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
379 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
380 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
381 |
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
|
382 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
383 |
((Depth8Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
384 |
width:16 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
385 |
height:16 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
386 |
fromArray:(ByteArray withAll:(0 to:16rFF))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
387 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
388 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
389 |
bitsPerSample:#(3 3 2); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
390 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
391 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
392 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
393 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
394 |
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
|
395 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
396 |
((Depth8Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
397 |
width:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
398 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
399 |
fromArray:(ByteArray withAll:(0 to:16r3F))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
400 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
401 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
402 |
bitsPerSample:#(2 2 2); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
403 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
404 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
405 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
406 |
|
649 | 407 |
storing (only a few formats are currently supported): |
408 |
[exBegin] |
|
409 |
|img| |
|
410 |
||
411 |
img := Image fromFile:'bitmaps/okSmily_up.bmp'. |
|
412 |
img saveOn:'myImage.tiff'. |
|
413 |
(Image fromFile:'myImage.tiff') inspect |
|
414 |
[exEnd] |
|
415 |
magnifying (any factor): |
|
416 |
[exBegin] |
|
417 |
((Image fromFile:'bitmaps/claus.gif') |
|
418 |
magnifiedTo:(48@48)) |
|
419 |
inspect |
|
420 |
[exEnd] |
|
421 |
[exBegin] |
|
422 |
((Image fromFile:'bitmaps/claus.gif') |
|
423 |
magnifiedBy:0.7) |
|
424 |
inspect |
|
425 |
[exEnd] |
|
426 |
rotating (currently, only multiples of 90 degrees are supported): |
|
427 |
[exBegin] |
|
428 |
((Image fromFile:'bitmaps/claus.gif') |
|
429 |
rotated:90) |
|
430 |
inspect |
|
431 |
[exEnd] |
|
432 |
[exBegin] |
|
433 |
(((Image fromFile:'bitmaps/claus.gif') |
|
434 |
magnifiedBy:0.3@0.7) rotated:270) |
|
435 |
inspect |
|
436 |
[exEnd] |
|
437 |
" |
|
0 | 438 |
! ! |
439 |
||
283 | 440 |
!Image class methodsFor:'initialization'! |
441 |
||
442 |
fileFormats |
|
443 |
"return the collection of supported file formats. |
|
444 |
The returned dictionary maps file-extensions to image reader classes." |
|
445 |
||
446 |
FileFormats isNil ifTrue:[ |
|
447 |
self initializeFileFormatTable |
|
448 |
]. |
|
449 |
^ FileFormats |
|
450 |
||
451 |
" |
|
452 |
Image fileFormats |
|
453 |
" |
|
100 | 454 |
! |
455 |
||
283 | 456 |
flushDeviceImages |
869 | 457 |
"simply release all deviceForms" |
283 | 458 |
|
459 |
Lobby do:[:anImage | |
|
869 | 460 |
anImage restored |
283 | 461 |
] |
869 | 462 |
|
463 |
"Modified: 15.6.1996 / 15:45:02 / cg" |
|
0 | 464 |
! |
465 |
||
466 |
initialize |
|
2 | 467 |
"initialize class constants" |
468 |
||
0 | 469 |
"setup tracker of known pictures" |
24 | 470 |
Lobby isNil ifTrue:[ |
748 | 471 |
Lobby := Registry new. |
472 |
ObjectMemory addDependent:self. |
|
473 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
474 |
"/ define the algorithm to use for dithering - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
475 |
"/ supported values are: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
476 |
"/ #threshold |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
477 |
"/ #ordered |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
478 |
"/ #floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
479 |
"/ #burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
480 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
481 |
DitherAlgorithm := #floydSteinberg. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
482 |
|
748 | 483 |
(Display notNil and:[Display hasGrayscales]) ifFalse:[ |
484 |
NumberOfDitherColors := 64 |
|
485 |
] ifTrue:[ |
|
486 |
"as far as I remember, this is about the number of grey values, the eye can distinguish" |
|
487 |
NumberOfDitherColors := 100 |
|
488 |
]. |
|
489 |
||
490 |
"define reader classes" |
|
491 |
FileFormats isNil ifTrue:[ |
|
492 |
self initializeFileFormatTable |
|
493 |
]. |
|
494 |
||
495 |
CollectGarbageWhenRunningOutOfColors := false |
|
386 | 496 |
] |
748 | 497 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
498 |
"Modified: 10.6.1996 / 12:28:22 / cg" |
12 | 499 |
! |
500 |
||
24 | 501 |
initializeFileFormatTable |
46 | 502 |
"initialize a default table to map from file extension to reader class. |
503 |
The mapping here is a default needed for proper operation of ST/X; |
|
504 |
see the 'smalltalk.rc' startup file for a real (full) map." |
|
24 | 505 |
|
506 |
FileFormats := Dictionary new. |
|
507 |
FileFormats at:'.xbm' put:XBMReader. |
|
508 |
FileFormats at:'.tiff' put:TIFFReader. |
|
509 |
FileFormats at:'.gif' put:GIFReader. |
|
72 | 510 |
"/ FileFormats at:'.img' put:IMGReader. |
511 |
"/ FileFormats at:'.icon' put:SunRasterReader. |
|
24 | 512 |
|
72 | 513 |
" |
514 |
Image initializeFileFormatTable |
|
515 |
" |
|
24 | 516 |
! |
517 |
||
0 | 518 |
update:something |
519 |
"flush all device specific stuff when restarted from a snapshot" |
|
520 |
||
521 |
(something == #restarted) ifTrue:[ |
|
72 | 522 |
self flushDeviceImages |
0 | 523 |
] |
524 |
! ! |
|
525 |
||
283 | 526 |
!Image class methodsFor:'instance creation'! |
527 |
||
528 |
extent:ext depth:d bits:bits |
|
529 |
"ST-80 compatibility; assume 32-bit padding" |
|
530 |
||
531 |
^ self extent:ext depth:d bits:bits pad:32 |
|
24 | 532 |
! |
533 |
||
283 | 534 |
extent:ext depth:d bits:bits pad:padding |
535 |
"ST-80 compatibility" |
|
536 |
||
537 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
24 | 538 |
! |
539 |
||
283 | 540 |
extent:ext depth:d palette:aColormap bits:bits pad:padding |
541 |
"ST-80 compatibility" |
|
542 |
||
543 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
544 |
! |
|
545 |
||
546 |
extent:ext fromArray:bits offset:offset |
|
547 |
"ST-80 compatibility" |
|
548 |
||
549 |
^ self width:ext x height:ext y fromArray:bits |
|
89 | 550 |
! |
551 |
||
552 |
fromForm:aForm |
|
553 |
"create & return an Image given a form" |
|
554 |
||
555 |
|cls| |
|
556 |
||
557 |
cls := self. |
|
558 |
cls == Image ifTrue:[ |
|
559 |
cls := self implementorForDepth:aForm depth |
|
560 |
]. |
|
561 |
^ (cls new) fromForm:aForm. |
|
562 |
||
563 |
" |
|
564 |
|f| |
|
565 |
||
566 |
f := Form width:16 height:16. |
|
567 |
f clear. |
|
568 |
f displayLineFromX:0 y:0 toX:15 y:15. |
|
569 |
f inspect. |
|
570 |
(Image fromForm:f) inspect |
|
571 |
" |
|
572 |
! |
|
573 |
||
574 |
fromImage:anImage |
|
575 |
"create & return an Image given another image. This can be used to |
|
576 |
convert an image to another depth." |
|
577 |
||
578 |
(self == Image or:[anImage class == self]) ifTrue:[^ anImage]. |
|
579 |
^ self new fromImage:anImage. |
|
580 |
||
581 |
" |
|
582 |
|i1 i8| |
|
583 |
||
584 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
585 |
i8 := Depth8Image fromImage:i1. |
|
586 |
i8 inspect |
|
587 |
" |
|
588 |
! |
|
589 |
||
191 | 590 |
fromSubImage:anImage in:aRectangle |
591 |
"create & return an Image from a rectangular area in another image. |
|
592 |
This can also be used to get a subimage in another depth." |
|
593 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
594 |
|newImage| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
595 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
596 |
self == Image ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
597 |
newImage := self implementorForDepth:anImage depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
598 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
599 |
newImage := self new. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
600 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
601 |
^ newImage fromSubImage:anImage in:aRectangle. |
191 | 602 |
|
603 |
" |
|
604 |
|i1 i8| |
|
605 |
||
606 |
i1 := Image fromFile:'bitmaps/garfield.gif'. |
|
607 |
i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20). |
|
608 |
i8 inspect |
|
609 |
" |
|
650 | 610 |
" |
611 |
|i1 i8| |
|
612 |
||
613 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
|
614 |
i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50). |
|
615 |
i8 inspect |
|
616 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
617 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
618 |
|i1 i8| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
619 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
620 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
621 |
i8 := Image fromSubImage:i1 in:(70@50 extent:50@50). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
622 |
i8 inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
623 |
" |
191 | 624 |
|
625 |
"Created: 20.9.1995 / 01:05:43 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
626 |
"Modified: 10.6.1996 / 18:11:08 / cg" |
191 | 627 |
! |
628 |
||
283 | 629 |
new |
630 |
"create a new image. Redefined to set the photometric to |
|
631 |
greyScale with black being 0 as default." |
|
632 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
633 |
^ super new photometric:(self defaultPhotometric) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
634 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
635 |
"Modified: 10.6.1996 / 18:08:37 / cg" |
283 | 636 |
! |
637 |
||
89 | 638 |
width:w height:h |
639 |
"create a new image, given width, height. Assume a depth of 1." |
|
640 |
||
641 |
|cls| |
|
642 |
||
643 |
cls := self. |
|
644 |
cls == Image ifTrue:[ |
|
645 |
cls := self implementorForDepth:1 |
|
646 |
]. |
|
647 |
^ cls new width:w height:h depth:1 |
|
648 |
! |
|
649 |
||
82 | 650 |
width:w height:h depth:d |
89 | 651 |
"create a new image, given width, height and depth" |
652 |
||
191 | 653 |
^ (self implementorForDepth:d) new |
654 |
width:w height:h depth:d |
|
82 | 655 |
! |
656 |
||
657 |
width:w height:h depth:d fromArray:pixelData |
|
89 | 658 |
"create a new image, given width, height, depth and data. |
659 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
134 | 660 |
depth (8-bit padded)." |
82 | 661 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
662 |
^ (self implementorForDepth:d) new |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
663 |
width:w height:h depth:d fromArray:pixelData |
82 | 664 |
|
665 |
" |
|
666 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
667 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
668 |
depth:1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
669 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
670 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
671 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
672 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
673 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
674 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
675 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
676 |
2r00110011]. |
82 | 677 |
" |
678 |
||
679 |
" |
|
680 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
681 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
682 |
depth:2 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
683 |
fromArray:#[4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
684 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
685 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
686 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
687 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
688 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
689 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
690 |
4r0011 4r0011]. |
89 | 691 |
" |
692 |
||
693 |
" |
|
694 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
695 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
696 |
depth:4 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
697 |
fromArray:#[16r00 16r01 16rf0 16rf1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
698 |
16r02 16r03 16rf2 16rf3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
699 |
16r04 16r05 16rf4 16rf5 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
700 |
16r06 16r07 16rf6 16rf7 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
701 |
16r08 16r09 16rf8 16rf9 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
702 |
16r0a 16r0b 16rfa 16rfb |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
703 |
16r0c 16r0d 16rfc 16rfd |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
704 |
16r0e 16r0f 16rfe 16rff]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
705 |
" |
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 |
"Modified: 10.6.1996 / 18:18:10 / cg" |
132 | 708 |
! |
709 |
||
134 | 710 |
width:w height:h depth:d fromArray:pixelData pad:padding |
711 |
"create a new image, given width, height, depth and data. |
|
712 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
713 |
depth." |
|
714 |
||
715 |
|img newBits srcRowBytes dstRowBytes srcIndex dstIndex| |
|
716 |
||
717 |
img := (self implementorForDepth:d) new width:w height:h depth:d . |
|
718 |
||
719 |
padding ~~ 8 ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
720 |
"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
|
721 |
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
|
722 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
723 |
dstRowBytes := img bytesPerRow. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
724 |
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
|
725 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
726 |
newBits := ByteArray new:(dstRowBytes * h). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
727 |
srcIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
728 |
dstIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
729 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
730 |
1 to:h do:[:row | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
731 |
newBits replaceFrom:dstIndex |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
732 |
to:(dstIndex + dstRowBytes - 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
733 |
with:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
734 |
startingAt:srcIndex. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
735 |
srcIndex := srcIndex + srcRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
736 |
dstIndex := dstIndex + dstRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
737 |
]. |
134 | 738 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
739 |
pixelData class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
740 |
newBits := ByteArray withAll:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
741 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
742 |
newBits := pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
743 |
] |
134 | 744 |
]. |
745 |
img bits:newBits. |
|
746 |
^ img |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
747 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
748 |
"Modified: 8.6.1996 / 10:07:47 / cg" |
134 | 749 |
! |
750 |
||
283 | 751 |
width:w height:h fromArray:anArray |
752 |
"create a new image, given width, height. Assume a depth of 1 of the |
|
753 |
receiving class is Image. |
|
754 |
Data must be a ByteArray containing correctly aligned bits for depth 1 |
|
755 |
(i.e. 8 bits per byte)." |
|
756 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
757 |
|cls d pixels| |
283 | 758 |
|
759 |
cls := self. |
|
760 |
cls == Image ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
761 |
cls := self implementorForDepth:1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
762 |
d := 1. |
283 | 763 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
764 |
d := cls imageDepth |
283 | 765 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
766 |
anArray class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
767 |
pixels := ByteArray withAll:anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
768 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
769 |
pixels := anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
770 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
771 |
^ cls new width:w height:h depth:d fromArray:pixels |
191 | 772 |
|
773 |
" |
|
283 | 774 |
Image width:8 |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
775 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
776 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
777 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
778 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
779 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
780 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
781 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
782 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
783 |
2r00110011]. |
191 | 784 |
" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
785 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
786 |
"Modified: 8.6.1996 / 10:07:26 / cg" |
283 | 787 |
! ! |
788 |
||
650 | 789 |
!Image class methodsFor:'file reading'! |
790 |
||
791 |
fromFile:aFileName |
|
792 |
"read an image from a file - this methods tries to find |
|
793 |
out the file format itself (by the extension and by contents) |
|
794 |
and lets the appropriate reader read the file." |
|
795 |
||
796 |
|image name nm inStream suffixLen| |
|
797 |
||
798 |
" |
|
799 |
before trying each reader, check if file is readable |
|
800 |
" |
|
801 |
name := aFileName. |
|
802 |
inStream := Smalltalk systemFileStreamFor:name. |
|
803 |
inStream isNil ifTrue:[ |
|
804 |
inStream := Smalltalk bitmapFileStreamFor:name. |
|
805 |
inStream isNil ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
806 |
('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintCR. |
650 | 807 |
^ nil |
808 |
]. |
|
809 |
name := 'bitmaps/' , name. |
|
810 |
]. |
|
811 |
inStream close. |
|
812 |
||
813 |
" |
|
814 |
get the imageReader class from the files extension |
|
815 |
" |
|
816 |
nm := name. |
|
817 |
(name endsWith:'.Z') ifTrue:[ |
|
818 |
suffixLen := 2 |
|
819 |
] ifFalse:[ |
|
820 |
(name endsWith:'.gz') ifTrue:[ |
|
821 |
suffixLen := 3 |
|
822 |
] ifFalse:[ |
|
823 |
suffixLen := 0 |
|
824 |
] |
|
825 |
]. |
|
826 |
suffixLen ~~ 0 ifTrue:[ |
|
827 |
nm := name copyWithoutLast:suffixLen |
|
828 |
]. |
|
829 |
||
830 |
" |
|
831 |
ask the corresponding readerclass first |
|
832 |
" |
|
833 |
FileFormats keysAndValuesDo:[:suffix :readerClass | |
|
834 |
(nm endsWith:suffix) ifTrue:[ |
|
835 |
readerClass notNil ifTrue:[ |
|
836 |
image := readerClass fromFile:name. |
|
837 |
image notNil ifTrue:[^ image]. |
|
838 |
] |
|
839 |
] |
|
840 |
]. |
|
841 |
||
842 |
" |
|
843 |
no known extension - ask all readers if they know |
|
844 |
this format ... |
|
845 |
" |
|
846 |
FileFormats do:[:readerClass | |
|
847 |
readerClass notNil ifTrue:[ |
|
848 |
(readerClass isValidImageFile:name) ifTrue:[ |
|
849 |
^ readerClass fromFile:name |
|
850 |
] |
|
851 |
] |
|
852 |
]. |
|
853 |
||
854 |
" |
|
855 |
nope - unknown format |
|
856 |
" |
|
857 |
'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL. |
|
858 |
^ nil |
|
859 |
||
860 |
" |
|
861 |
Image fromFile:'bitmaps/dano.tiff' |
|
862 |
Image fromFile:'bitmaps/test.fax' |
|
863 |
Image fromFile:'bitmaps/voice.tiff' |
|
864 |
Image fromFile:'voice.tiff' |
|
865 |
||
866 |
Image fromFile:'../fileIn/bitmaps/claus.gif' |
|
867 |
Image fromFile:'../fileIn/bitmaps/garfield.gif' |
|
868 |
||
869 |
Image fromFile:'../fileIn/bitmaps/founders.im8' |
|
870 |
Image fromFile:'../goodies/faces/next.com/steve.face' |
|
871 |
||
872 |
Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico' |
|
873 |
Image fromFile:'bitmaps/globe1.xbm' |
|
874 |
Image fromFile:'bitmaps/globe1.xbm.Z' |
|
875 |
Image fromFile:'bitmaps/hello_world.icon' |
|
876 |
" |
|
877 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
878 |
"Modified: 10.6.1996 / 14:36:18 / cg" |
650 | 879 |
! ! |
880 |
||
283 | 881 |
!Image class methodsFor:'misc'! |
882 |
||
883 |
dither:aSymbol |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
884 |
"define how to dither - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
885 |
#threshold, or nil -> no dither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
886 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
887 |
#error or #floydSteinberg -> errorDiffusion; much better |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
888 |
#burkes -> errorDiffusion; even better." |
283 | 889 |
|
890 |
DitherAlgorithm := aSymbol |
|
891 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
892 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
893 |
Image dither:#pattern |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
894 |
Image dither:#floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
895 |
Image dither:#burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
896 |
Image dither:nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
897 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
898 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
899 |
"Modified: 10.6.1996 / 12:27:09 / cg" |
283 | 900 |
! |
901 |
||
902 |
numberOfDitherColors:n |
|
903 |
"define how many colors (i.e. patterns) to use when |
|
904 |
doing a pattern dither" |
|
905 |
||
906 |
NumberOfDitherColors := n |
|
798 | 907 |
! |
908 |
||
909 |
orderedDitherMatrixOfSize:sz |
|
910 |
sz == 2 ifTrue:[ |
|
911 |
^ #[ |
|
912 |
0 2 |
|
913 |
3 1 |
|
914 |
]. |
|
915 |
]. |
|
916 |
||
917 |
sz == 4 ifTrue:[ |
|
918 |
^ #[ |
|
919 |
0 8 2 10 |
|
920 |
12 4 14 6 |
|
921 |
3 11 1 9 |
|
922 |
15 7 13 5 |
|
923 |
]. |
|
924 |
]. |
|
925 |
||
926 |
sz == 8 ifTrue:[ |
|
927 |
^ #[ |
|
928 |
0 32 8 40 2 34 10 42 |
|
929 |
48 16 56 24 50 18 58 26 |
|
930 |
12 44 4 36 14 46 6 38 |
|
931 |
60 28 52 20 62 30 54 22 |
|
932 |
||
933 |
3 35 11 43 1 33 9 41 |
|
934 |
51 19 59 27 49 17 57 25 |
|
935 |
15 47 7 39 13 45 5 37 |
|
936 |
63 31 55 23 61 29 53 21 |
|
937 |
]. |
|
938 |
]. |
|
939 |
||
940 |
^ nil |
|
941 |
||
942 |
"Created: 7.6.1996 / 14:15:05 / cg" |
|
283 | 943 |
! ! |
944 |
||
945 |
!Image class methodsFor:'queries'! |
|
946 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
947 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
948 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
949 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
950 |
^ #blackIs0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
951 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
952 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
953 |
"Created: 10.6.1996 / 18:08:12 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
954 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
955 |
|
283 | 956 |
imageDepth |
579 | 957 |
"return the depth of images represented by instances of |
958 |
this class. |
|
959 |
Must be redefined in concrete subclasses" |
|
960 |
||
961 |
^ self shouldNotImplement |
|
962 |
||
963 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
|
191 | 964 |
! |
965 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
966 |
implementorForDepth:depth |
283 | 967 |
"return the class, which best implements images of depth" |
968 |
||
969 |
depth == 1 ifTrue:[^ Depth1Image]. |
|
970 |
depth == 2 ifTrue:[^ Depth2Image]. |
|
971 |
depth == 4 ifTrue:[^ Depth4Image]. |
|
972 |
depth == 8 ifTrue:[^ Depth8Image]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
973 |
depth == 15 ifTrue:[^ Depth16Image]. "/ kludge for 15bit XFree |
283 | 974 |
depth == 16 ifTrue:[^ Depth16Image]. |
975 |
depth == 24 ifTrue:[^ Depth24Image]. |
|
976 |
^ self |
|
977 |
! ! |
|
978 |
||
979 |
!Image class methodsFor:'screen capture'! |
|
980 |
||
981 |
fromScreen |
|
982 |
"return an image of the full screen" |
|
983 |
||
984 |
|display| |
|
985 |
||
986 |
display := Screen current. |
|
987 |
^ 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
|
988 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
989 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
990 |
Image fromScreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
991 |
" |
283 | 992 |
! |
993 |
||
994 |
fromScreen:aRectangle |
|
995 |
"return an image of a part of the screen" |
|
996 |
||
997 |
^ self fromScreen:aRectangle on:Screen current |
|
998 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
999 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1000 |
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
|
1001 |
" |
283 | 1002 |
! |
1003 |
||
1004 |
fromScreen:aRectangle on:aDisplay |
|
1005 |
"return an image of a part of the screen, which may be on |
|
1006 |
another Display." |
|
1007 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1008 |
|depth vis img| |
283 | 1009 |
|
1010 |
depth := aDisplay depth. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1011 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1012 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1013 |
"/ 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
|
1014 |
"/ (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
|
1015 |
"/ 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
|
1016 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1017 |
vis := aDisplay visualType. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1018 |
(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
|
1019 |
depth > 8 ifTrue:[ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1020 |
depth := 24. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1021 |
] |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1022 |
]. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1023 |
|
283 | 1024 |
img := (self implementorForDepth: depth) new. |
1025 |
^ img fromScreen:aRectangle on:aDisplay |
|
1026 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1027 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1028 |
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
|
1029 |
" |
283 | 1030 |
! |
1031 |
||
1032 |
fromScreenArea |
|
1033 |
"return an image of a part of the screen; |
|
1034 |
let user specify screen area." |
|
1035 |
||
1036 |
^ self fromScreen:(Rectangle fromUser) |
|
1037 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1038 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1039 |
Image fromScreenArea |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1040 |
" |
283 | 1041 |
! |
1042 |
||
1043 |
fromUser |
|
1044 |
"return an image of a part of the screen; let user specify screen area. |
|
1045 |
Same as fromScreenArea, for ST-80 compatibility" |
|
1046 |
||
1047 |
^ self fromScreenArea |
|
1048 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1049 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1050 |
Image fromUser |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1051 |
" |
283 | 1052 |
! |
1053 |
||
1054 |
fromView:aView |
|
1055 |
"return an image taken from a views contents as currently |
|
1056 |
on the screen. The returned image has the same depth and photometric |
|
1057 |
as the Display. Notice, that for invisible or partial covered |
|
1058 |
views, the returned Image is NOT correct. You may want to raise |
|
1059 |
the view before using this method." |
|
1060 |
||
1061 |
|org dev| |
|
1062 |
||
744 | 1063 |
dev := aView graphicsDevice. |
283 | 1064 |
org := dev translatePoint:(0@0) |
744 | 1065 |
from:(aView id) |
1066 |
to:dev rootWindowId. |
|
283 | 1067 |
^ self fromScreen:(org extent:aView extent) on:dev |
191 | 1068 |
|
1069 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1070 |
Image fromView:(NewLauncher allInstances first topView) |
283 | 1071 |
Image fromView:(SystemBrowser allInstances first topView) |
191 | 1072 |
" |
744 | 1073 |
|
1074 |
"Modified: 28.5.1996 / 20:23:32 / cg" |
|
157 | 1075 |
! ! |
1076 |
||
0 | 1077 |
!Image methodsFor:'accessing'! |
1078 |
||
592 | 1079 |
bitsPerSample |
1080 |
"return the number of bits per sample. |
|
1081 |
The return value is an array of bits-per-plane." |
|
1082 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1083 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1084 |
^ Array with:self depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1085 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1086 |
"Modified: 10.6.1996 / 18:04:21 / cg" |
592 | 1087 |
! |
1088 |
||
1089 |
colorMap |
|
1090 |
"return the colormap" |
|
1091 |
||
1092 |
^ colorMap |
|
1093 |
! |
|
1094 |
||
852 | 1095 |
colorMap:aColorMap |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1096 |
"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
|
1097 |
|
852 | 1098 |
|sz "{ Class: SmallInteger }" |
1099 |
sameColors| |
|
1100 |
||
1101 |
(aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self]. |
|
1102 |
photometric == #palette ifTrue:[ |
|
1103 |
"/ any change at all ? |
|
1104 |
(sz := aColorMap size) == colorMap size ifTrue:[ |
|
1105 |
sameColors := true. |
|
1106 |
||
1107 |
1 to:sz do:[:idx | |
|
1108 |
(aColorMap at:idx) = (colorMap at:idx) ifFalse:[ |
|
1109 |
sameColors := false. |
|
1110 |
] |
|
1111 |
]. |
|
1112 |
sameColors ifTrue:[^ self]. |
|
1113 |
] |
|
1114 |
]. |
|
1115 |
||
1116 |
colorMap := aColorMap. |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1117 |
colorMap notNil ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1118 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1119 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1120 |
(photometric == #palette) ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1121 |
photometric := #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1122 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1123 |
]. |
852 | 1124 |
deviceForm notNil ifTrue:[ |
1125 |
self release |
|
1126 |
] |
|
592 | 1127 |
|
1128 |
"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
|
1129 |
"Modified: 15.6.1996 / 09:32:09 / cg" |
592 | 1130 |
! |
1131 |
||
757 | 1132 |
container:aVisualContainer |
1133 |
"ignored here - added to allow images to be used like |
|
1134 |
VisualComponents (later, Image should inherit from it)" |
|
1135 |
||
1136 |
"Created: 28.5.1996 / 23:43:49 / cg" |
|
1137 |
"Modified: 29.5.1996 / 10:22:23 / cg" |
|
1138 |
! |
|
1139 |
||
592 | 1140 |
depth |
1141 |
"return the depth of the image" |
|
1142 |
||
1143 |
^ self bitsPerPixel |
|
1144 |
! |
|
1145 |
||
1146 |
device |
|
1147 |
"return the device, the receiver is associated with. |
|
1148 |
Return nil, if the image is unassigned." |
|
1149 |
||
1150 |
^ device |
|
1151 |
! |
|
1152 |
||
1153 |
extent |
|
1154 |
"return the images extent" |
|
1155 |
||
1156 |
^ width@height |
|
1157 |
! |
|
1158 |
||
1159 |
fullColorId |
|
1160 |
"return the id of the full color image on the device. |
|
1161 |
Return nil, if the image is unassigned." |
|
1162 |
||
1163 |
fullColorDeviceForm isNil ifTrue:[^ nil]. |
|
1164 |
^ fullColorDeviceForm id |
|
1165 |
! |
|
1166 |
||
728 | 1167 |
graphicsDevice |
1168 |
"same as #device - for ST-80 compatibility" |
|
1169 |
||
1170 |
^ device |
|
1171 |
! |
|
744 | 1172 |
|
592 | 1173 |
height |
1174 |
"return the height of the image" |
|
1175 |
||
1176 |
^ height |
|
1177 |
! |
|
1178 |
||
1179 |
id |
|
1180 |
"return the id of the image on the device. |
|
1181 |
Return nil, if the image is unassigned." |
|
1182 |
||
1183 |
deviceForm isNil ifTrue:[^ nil]. |
|
1184 |
^ deviceForm id |
|
1185 |
! |
|
1186 |
||
1187 |
monochromeId |
|
1188 |
"return the id of the monochrome image on the device. |
|
1189 |
Return nil, if the image is unassigned." |
|
1190 |
||
1191 |
monoDeviceForm isNil ifTrue:[^ nil]. |
|
1192 |
^ monoDeviceForm id |
|
1193 |
! |
|
1194 |
||
1195 |
palette |
|
1196 |
"return the colormap; ST-80 compatibility" |
|
1197 |
||
1198 |
^ colorMap |
|
1199 |
! |
|
1200 |
||
1201 |
palette:aColormap |
|
1202 |
"set the colormap; ST-80 compatibility" |
|
1203 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1204 |
self colorMap:aColormap |
592 | 1205 |
|
1206 |
"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
|
1207 |
"Modified: 8.6.1996 / 09:54:02 / cg" |
592 | 1208 |
! |
1209 |
||
1210 |
photometric |
|
1211 |
"return the photometric, a symbol such as #palette, #rgb etc." |
|
1212 |
||
1213 |
^ photometric |
|
1214 |
! |
|
1215 |
||
1216 |
samplesPerPixel |
|
1217 |
"return the number of samples per pixel in the image. |
|
1218 |
The return value is an array of bits-per-plane." |
|
1219 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1220 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1221 |
^ 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1222 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1223 |
"Modified: 10.6.1996 / 18:03:30 / cg" |
592 | 1224 |
! |
1225 |
||
1226 |
width |
|
1227 |
"return the width of the image" |
|
1228 |
||
1229 |
^ width |
|
1230 |
! ! |
|
1231 |
||
1232 |
!Image methodsFor:'accessing - pixels'! |
|
1233 |
||
0 | 1234 |
at:aPoint |
2 | 1235 |
"retrieve the pixel at aPoint; return a color. |
1236 |
Pixels start at 0@0 for upper left pixel, end at |
|
81 | 1237 |
(width-1)@(height-1) for lower right pixel. |
2 | 1238 |
You should not use this method for image-processing, its |
81 | 1239 |
very slow ... |
1240 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
0 | 1241 |
|
1242 |
^ self atX:aPoint x y:aPoint y |
|
1243 |
! |
|
1244 |
||
283 | 1245 |
at:aPoint put:aColor |
1246 |
"set the pixel at aPoint to aColor. |
|
1247 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1248 |
(width-1)@(height-1) for lower right pixel. |
|
1249 |
You should not use this method for image-processing, its |
|
1250 |
very slow ... |
|
1251 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1252 |
||
1253 |
^ self atX:aPoint x y:aPoint y put:aColor |
|
1254 |
! |
|
1255 |
||
1256 |
atPoint:aPoint |
|
1257 |
"ST-80 compatibility: return the pixelValue at:aPoint." |
|
1258 |
||
1259 |
^ self valueAtX:aPoint x y:aPoint y |
|
1260 |
! |
|
1261 |
||
0 | 1262 |
atX:x y:y |
2 | 1263 |
"retrieve a pixel at x/y; return a color. |
81 | 1264 |
Pixels start at 0@0 for upper left pixel, end at |
1265 |
(width-1)@(height-1) for lower right pixel. |
|
2 | 1266 |
You should not use this method for image-processing, its |
81 | 1267 |
very slow ... |
1268 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1269 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1270 |
|pixel maxPixel| |
89 | 1271 |
|
1272 |
pixel := self valueAtX:x y:y. |
|
1273 |
photometric == #blackIs0 ifTrue:[ |
|
746 | 1274 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1275 |
^ Color gray:(pixel * (100 / maxPixel)). |
|
89 | 1276 |
]. |
1277 |
photometric == #whiteIs0 ifTrue:[ |
|
746 | 1278 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1279 |
^ Color gray:100 - (pixel * (100 / maxPixel)). |
|
89 | 1280 |
]. |
1281 |
photometric == #palette ifTrue:[ |
|
746 | 1282 |
^ colorMap at:(pixel + 1) |
89 | 1283 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1284 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1285 |
^ self colorFromValue:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1286 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1287 |
"Modified: 8.6.1996 / 10:53:22 / cg" |
2 | 1288 |
! |
1289 |
||
1290 |
atX:x y:y put:aColor |
|
1291 |
"set the pixel at x/y to aColor. |
|
81 | 1292 |
Pixels start at 0@0 for the upper left pixel, end at |
1293 |
(width-1)@(height-1) for the lower right pixel. |
|
89 | 1294 |
This method checks if the color can be stored in the image. |
1295 |
(i.e. if the receiver is a palette image, the color must be present in there). |
|
1296 |
You should not use this method for image-processing, it is very slow ... |
|
81 | 1297 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
1298 |
||
89 | 1299 |
|pixel maxPixel| |
1300 |
||
1301 |
photometric == #whiteIs0 ifTrue:[ |
|
798 | 1302 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1303 |
pixel := maxPixel - (aColor brightness * maxPixel) rounded. |
|
89 | 1304 |
] ifFalse:[ |
798 | 1305 |
photometric == #blackIs0 ifTrue:[ |
1306 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
|
1307 |
pixel := (aColor brightness * maxPixel) rounded. |
|
1308 |
] ifFalse:[ |
|
1309 |
photometric ~~ #palette ifTrue:[ |
|
1310 |
self error:'format not supported'. |
|
1311 |
^ nil |
|
1312 |
]. |
|
1313 |
pixel := colorMap indexOf:aColor. |
|
1314 |
pixel == 0 ifTrue:[ |
|
1315 |
" |
|
1316 |
the color to be stored is not in the images colormap |
|
1317 |
" |
|
1318 |
self error:'invalid color - not in colorMap' |
|
1319 |
]. |
|
1320 |
pixel := pixel - 1 |
|
1321 |
] |
|
89 | 1322 |
]. |
1323 |
self atX:x y:y putValue:pixel. |
|
798 | 1324 |
|
1325 |
"Modified: 7.6.1996 / 19:17:48 / cg" |
|
81 | 1326 |
! |
1327 |
||
283 | 1328 |
atX:x y:y putValue:aPixelValue |
1329 |
"set the pixel at x/y to aPixelValue. |
|
1330 |
The interpretation of the pixelValue depends on the photometric |
|
1331 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1332 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1333 |
(width-1) @ (height-1) for the lower right pixel. |
|
1334 |
You should not use this method for image-processing, its |
|
1335 |
very slow ... |
|
1336 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1337 |
||
1338 |
^ self subclassResponsibility |
|
1339 |
! |
|
1340 |
||
1341 |
bits |
|
1342 |
"return the raw image data; depending on the photometric, |
|
1343 |
this has to be interpreted as monochrome, greyscale, |
|
1344 |
palette or rgb data. It is also packed to be dense, so |
|
1345 |
a 4 bitPerSample palette image will store 2 pixels per byte." |
|
1346 |
||
1347 |
^ bytes |
|
1348 |
! |
|
1349 |
||
1350 |
data |
|
1351 |
"for backward compatibility - will vanish" |
|
1352 |
||
1353 |
^ bytes |
|
1354 |
! |
|
1355 |
||
1356 |
data:aByteArray |
|
1357 |
"for backward compatibility - will vanish" |
|
1358 |
||
1359 |
bytes := aByteArray |
|
1360 |
! |
|
1361 |
||
81 | 1362 |
valueAt:aPoint |
1363 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1364 |
Pixels start at 0@0 for upper left pixel, end at |
|
1365 |
width-1@height-1 for lower right pixel. |
|
1366 |
The returned numbers interpretation depends on the photometric |
|
1367 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
2 | 1368 |
You should not use this method for image-processing, its |
81 | 1369 |
very slow ... |
1370 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1371 |
||
1372 |
^ self valueAtX:aPoint x y:aPoint y |
|
1373 |
! |
|
1374 |
||
1375 |
valueAtX:x y:y |
|
1376 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1377 |
Pixels start at 0/0 for upper left pixel, and end at |
|
1378 |
width-1@height-1 for lower right pixel. |
|
1379 |
The returned numbers interpretation depends on the photometric |
|
1380 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
1381 |
You should not use this method for image-processing of |
|
1382 |
big images, its very slow ... |
|
1383 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1384 |
|
1385 |
^ self subclassResponsibility |
|
592 | 1386 |
! ! |
1387 |
||
1388 |
!Image methodsFor:'accessing - private'! |
|
1389 |
||
1390 |
bits:aByteArray |
|
1391 |
"set the raw data. |
|
1392 |
||
1393 |
This interface is only to be used when initializing |
|
1394 |
instances or by image readers. Calling for a change of an |
|
1395 |
existing image may confuse later pixel interpretation." |
|
1396 |
||
1397 |
bytes := aByteArray |
|
1398 |
||
1399 |
"Modified: 23.4.1996 / 11:08:28 / cg" |
|
2 | 1400 |
! |
1401 |
||
592 | 1402 |
bitsPerSample:aNumber |
1403 |
"set the number of bits per sample. |
|
1404 |
||
1405 |
This interface is only to be used when initializing |
|
1406 |
instances or by image readers. Calling for a change of an |
|
1407 |
existing image may confuse later pixel interpretation." |
|
1408 |
||
1409 |
bitsPerSample := aNumber |
|
1410 |
||
1411 |
"Modified: 23.4.1996 / 11:08:31 / cg" |
|
1412 |
! |
|
1413 |
||
1414 |
depth:d |
|
1415 |
"set the depth of the image. |
|
1416 |
||
1417 |
This interface is only to be used when initializing |
|
1418 |
instances or by image readers. Calling for a change of an |
|
1419 |
existing image may confuse later pixel interpretation." |
|
1420 |
||
1421 |
d == 24 ifTrue:[ |
|
1422 |
samplesPerPixel := 3. |
|
1423 |
bitsPerSample := #(8 8 8) |
|
1424 |
] ifFalse:[ |
|
1425 |
samplesPerPixel := 1. |
|
1426 |
bitsPerSample := Array with:d |
|
1427 |
] |
|
1428 |
||
1429 |
"Modified: 23.4.1996 / 11:08:34 / cg" |
|
1430 |
! |
|
1431 |
||
1432 |
extent:anExtent |
|
1433 |
"set the images extent. |
|
1434 |
||
1435 |
This interface is only to be used when initializing |
|
1436 |
instances or by image readers. Calling for a change of an |
|
1437 |
existing image may confuse later pixel interpretation." |
|
1438 |
||
1439 |
width := anExtent x. |
|
1440 |
height := anExtent y |
|
1441 |
||
1442 |
"Modified: 23.4.1996 / 11:08:38 / cg" |
|
1443 |
! |
|
1444 |
||
1445 |
height:aNumber |
|
1446 |
"set the height of the image. |
|
1447 |
||
1448 |
This interface is only to be used when initializing |
|
1449 |
instances or by image readers. Calling for a change of an |
|
1450 |
existing image may confuse later pixel interpretation." |
|
1451 |
||
1452 |
height := aNumber |
|
1453 |
||
1454 |
"Modified: 23.4.1996 / 11:08:40 / cg" |
|
1455 |
! |
|
1456 |
||
1457 |
photometric:aSymbol |
|
1458 |
"set the photometric interpretation of the pixel values. |
|
1459 |
The argument, aSymbol is one of: |
|
1460 |
#blackIs0, #whiteIs0, #palette, #rgb |
|
1461 |
See TIFF documentation, from which the photometric concept is borrowed. |
|
1462 |
||
1463 |
This interface is only to be used when initializing |
|
1464 |
instances or by image readers. Calling for a change of an |
|
1465 |
existing image may confuse later pixel interpretation." |
|
1466 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1467 |
|b| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1468 |
|
798 | 1469 |
photometric := aSymbol. |
1470 |
bitsPerSample isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1471 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1472 |
b := self class imageDepth // 3. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1473 |
bitsPerSample := Array with:b with:b with:b |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1474 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1475 |
bitsPerSample := Array with:(self class imageDepth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1476 |
]. |
798 | 1477 |
]. |
1478 |
samplesPerPixel isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1479 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1480 |
samplesPerPixel := 3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1481 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1482 |
samplesPerPixel := 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1483 |
] |
798 | 1484 |
]. |
1485 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1486 |
"Modified: 10.6.1996 / 18:21:29 / cg" |
592 | 1487 |
! |
1488 |
||
1489 |
samplesPerPixel:aNumber |
|
1490 |
"set the array of samples per pixel. |
|
1491 |
||
1492 |
This interface is only to be used when initializing |
|
1493 |
instances or by image readers. Calling for a change of an |
|
1494 |
existing image may confuse later pixel interpretation." |
|
1495 |
||
1496 |
samplesPerPixel := aNumber |
|
1497 |
||
1498 |
"Modified: 23.4.1996 / 11:08:45 / cg" |
|
81 | 1499 |
! |
1500 |
||
283 | 1501 |
width:aNumber |
592 | 1502 |
"set the width of the image. |
1503 |
||
1504 |
This interface is only to be used when initializing |
|
1505 |
instances or by image readers. Calling for a change of an |
|
1506 |
existing image may confuse later pixel interpretation." |
|
283 | 1507 |
|
1508 |
width := aNumber |
|
592 | 1509 |
|
1510 |
"Modified: 23.4.1996 / 11:08:48 / cg" |
|
100 | 1511 |
! |
1512 |
||
283 | 1513 |
width:w height:h |
592 | 1514 |
"set the width and height of the image. |
1515 |
||
1516 |
This interface is only to be used when initializing |
|
1517 |
instances or by image readers. Calling for a change of an |
|
1518 |
existing image may confuse later pixel interpretation." |
|
283 | 1519 |
|
1520 |
width := w. |
|
1521 |
height := h |
|
592 | 1522 |
|
1523 |
"Modified: 23.4.1996 / 11:08:53 / cg" |
|
81 | 1524 |
! |
2 | 1525 |
|
283 | 1526 |
width:w height:h depth:d |
592 | 1527 |
"set the width, height and depth of the image. |
1528 |
||
1529 |
This interface is only to be used when initializing |
|
1530 |
instances or by image readers. Calling for a change of an |
|
1531 |
existing image may confuse later pixel interpretation." |
|
283 | 1532 |
|
1533 |
width := w. |
|
1534 |
height := h. |
|
1535 |
self depth:d. |
|
592 | 1536 |
|
1537 |
"Modified: 23.4.1996 / 11:08:56 / cg" |
|
89 | 1538 |
! |
1539 |
||
283 | 1540 |
width:w height:h depth:d fromArray:bits |
592 | 1541 |
"set the width, height, depth and pixels 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. |
|
1550 |
bytes := bits |
|
592 | 1551 |
|
1552 |
"Modified: 23.4.1996 / 11:08:59 / cg" |
|
1553 |
! |
|
1554 |
||
1555 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels |
|
1556 |
"set all relevant internal state of the image. |
|
1557 |
||
1558 |
This interface is only to be used when initializing |
|
1559 |
instances or by image readers. Calling for a change of an |
|
1560 |
existing image may confuse later pixel interpretation." |
|
1561 |
||
1562 |
width := w. |
|
1563 |
height := h. |
|
1564 |
photometric := p. |
|
1565 |
samplesPerPixel := spp. |
|
1566 |
bitsPerSample := bps. |
|
1567 |
colorMap := cm. |
|
1568 |
bytes := pixels. |
|
1569 |
||
1570 |
"Created: 23.4.1996 / 11:06:40 / cg" |
|
1571 |
"Modified: 23.4.1996 / 11:09:02 / cg" |
|
0 | 1572 |
! ! |
1573 |
||
283 | 1574 |
!Image methodsFor:'binary storage'! |
1575 |
||
1576 |
readBinaryContentsFrom: stream manager: manager |
|
1577 |
"read a binary representation of an image from stream. |
|
1578 |
Redefined to flush any device data." |
|
1579 |
||
1580 |
super readBinaryContentsFrom: stream manager: manager. |
|
1581 |
device := nil. |
|
1582 |
deviceForm := nil. |
|
1583 |
monoDeviceForm := nil. |
|
1584 |
fullColorDeviceForm := nil. |
|
0 | 1585 |
! |
1586 |
||
283 | 1587 |
storeBinaryDefinitionOn: stream manager: manager |
1588 |
"store a binary representation of the receiver on stream. |
|
592 | 1589 |
This is an internal interface for binary storage mechanism. |
283 | 1590 |
Redefined to not store the device form (which is recreated at |
1591 |
load time anyway)" |
|
1592 |
||
1593 |
|tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm| |
|
1594 |
||
1595 |
tDevice := device. |
|
1596 |
tDeviceForm := deviceForm. |
|
1597 |
tMonoDeviceForm := monoDeviceForm. |
|
1598 |
tFullColorDeviceForm := fullColorDeviceForm. |
|
1599 |
||
1600 |
device := nil. |
|
1601 |
deviceForm := nil. |
|
1602 |
monoDeviceForm := nil. |
|
1603 |
fullColorDeviceForm := nil. |
|
1604 |
||
1605 |
super storeBinaryDefinitionOn: stream manager: manager. |
|
1606 |
||
1607 |
device := tDevice. |
|
1608 |
deviceForm := tDeviceForm. |
|
1609 |
monoDeviceForm := tMonoDeviceForm. |
|
1610 |
fullColorDeviceForm := tFullColorDeviceForm. |
|
592 | 1611 |
|
1612 |
"Modified: 23.4.1996 / 09:30:50 / cg" |
|
0 | 1613 |
! ! |
1614 |
||
1615 |
!Image methodsFor:'converting'! |
|
1616 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1617 |
asBurkesDitheredMonochromeImage |
837 | 1618 |
"return a burkes dithered monochrome image from the receiver image. |
1619 |
Depending on the images contents, this may or may not look better than |
|
1620 |
a floyd-steinberg dithered image. |
|
1621 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
1622 |
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
|
1623 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1624 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1625 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1626 |
monoBits := self burkesDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1627 |
^ 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
|
1628 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1629 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1630 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1631 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1632 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1633 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1634 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1635 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1636 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
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 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1641 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1642 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1643 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1644 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1645 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1646 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1647 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1648 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1649 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1650 |
|i| |
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 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1653 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1654 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1655 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1656 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1657 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1658 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1659 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1660 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1661 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1662 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1663 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1664 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1665 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1666 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1667 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1668 |
"Created: 10.6.1996 / 12:34:44 / cg" |
837 | 1669 |
"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
|
1670 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1671 |
|
283 | 1672 |
asCachedImage |
592 | 1673 |
"return the receiver associated to the current screens device. |
1674 |
For ST-80 compatibility |
|
1675 |
(ST/X uses Image for both device- and nonDevice-images)" |
|
283 | 1676 |
|
1677 |
^ self on:Screen current |
|
592 | 1678 |
|
1679 |
"Modified: 23.4.1996 / 11:10:32 / cg" |
|
0 | 1680 |
! |
1681 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1682 |
asErrorDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1683 |
"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
|
1684 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1685 |
DitherAlgorithm == #burkes ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1686 |
^ self asBurkesDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1687 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1688 |
DitherAlgorithm == #stevensonArce ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1689 |
^ self asStevensonArgceDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1690 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1691 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1692 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1693 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1694 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1695 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1696 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1697 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1698 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1699 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1700 |
" |
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 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1703 |
|i| |
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 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1706 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1707 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1708 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1711 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1712 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1713 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1714 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1715 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1716 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1717 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1718 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1719 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1720 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1721 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1722 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1723 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1724 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1725 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1726 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1729 |
"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
|
1730 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1731 |
|
854 | 1732 |
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
1733 |
"return a floyd-steinberg dithered pseudoForm from the palette picture. |
|
1734 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
|
1735 |
colors assigned to aDevice, such as the preallocated colors of the |
|
1736 |
Color class. |
|
1737 |
By passing the ditherColors as extra array, this method can |
|
1738 |
also be used to dither an 8bit image into a smaller number of colors, |
|
1739 |
for example to create dithered Depth4Images from Depth8Images." |
|
1740 |
||
1741 |
|pseudoBits f has8BitImage deviceDepth |
|
1742 |
map | |
|
1743 |
||
1744 |
deviceDepth := aDevice depth. |
|
1745 |
deviceDepth == 8 ifTrue:[ |
|
1746 |
has8BitImage := true. |
|
1747 |
] ifFalse:[ |
|
1748 |
has8BitImage := false. |
|
1749 |
aDevice supportedImageFormats do:[:fmt | |
|
1750 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
1751 |
has8BitImage := true. |
|
1752 |
] |
|
1753 |
] |
|
1754 |
]. |
|
1755 |
has8BitImage ifFalse:[^ nil]. |
|
1756 |
||
1757 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
|
1758 |
pseudoBits isNil ifTrue:[^ nil]. |
|
1759 |
||
1760 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
|
1761 |
f isNil ifTrue:[^ nil]. |
|
1762 |
||
1763 |
"/ |
|
1764 |
"/ have to create a funny colorMap, where |
|
1765 |
"/ color at:index == color colorId:index |
|
1766 |
"/ |
|
1767 |
map := Array new:256. |
|
1768 |
fixColors do:[:clr | |
|
1769 |
map at:clr colorId + 1 put:clr |
|
1770 |
]. |
|
1771 |
f colorMap:map. |
|
1772 |
f initGC. |
|
1773 |
f bits:pseudoBits. |
|
1774 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
|
1775 |
width:width height:height |
|
1776 |
x:0 y:0 |
|
1777 |
into:(f id) x:0 y:0 |
|
1778 |
width:width height:height with:(f gcId). |
|
1779 |
^ f |
|
1780 |
||
1781 |
" |
|
1782 |
example: |
|
1783 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
|
1784 |
||
1785 |
|img8 reducedImg8 img4 map form| |
|
1786 |
||
1787 |
map := #( |
|
1788 |
(0 0 0) |
|
1789 |
(0 0 100) |
|
1790 |
(0 50 0) |
|
1791 |
(0 50 100) |
|
1792 |
(0 100 0) |
|
1793 |
(0 100 100) |
|
1794 |
(100 0 0) |
|
1795 |
(100 0 100) |
|
1796 |
(100 50 0) |
|
1797 |
(100 50 100) |
|
1798 |
(100 100 0) |
|
1799 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
|
1800 |
green:(rgb at:2) |
|
1801 |
blue:(rgb at:3)) on:Display]. |
|
1802 |
||
1803 |
img8 := Image fromFile:'bitmaps/bf.im8'. |
|
1804 |
form := img8 paletteImageAsDitheredPseudoFormOn:Display |
|
1805 |
colors:map |
|
1806 |
nRed:2 |
|
1807 |
nGreen:3 |
|
1808 |
nBlue:2. |
|
1809 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
|
1810 |
img4 := Depth4Image fromImage:img8. |
|
1811 |
" |
|
1812 |
||
1813 |
"Modified: 14.6.1996 / 16:52:34 / cg" |
|
1814 |
! |
|
1815 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1816 |
asFloydSteinbergDitheredGrayFormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1817 |
"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
|
1818 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1819 |
|f depth bits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1820 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1821 |
depth := aDevice depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1822 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1823 |
"/ for monochrome, there is specialized |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1824 |
"/ monochrome dither code available |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1825 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1826 |
bits := self floydSteinbergDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1827 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1828 |
bits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1829 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1830 |
|
816 | 1831 |
^ 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
|
1832 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1833 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1834 |
|i f| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1835 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1836 |
i := Image fromFile:'bitmaps/claus.gif'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1837 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1838 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1839 |
|
841 | 1840 |
" |
1841 |
|i f| |
|
1842 |
||
1843 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1844 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
|
1845 |
" |
|
1846 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1847 |
"Created: 10.6.1996 / 14:11:39 / cg" |
841 | 1848 |
"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
|
1849 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1850 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1851 |
asFloydSteinbergDitheredGrayImageDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1852 |
"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
|
1853 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1854 |
|ditheredBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1855 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1856 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1857 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1858 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1859 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1860 |
ditheredBits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1861 |
^ (self class implementorForDepth:depth) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1862 |
width:width height:height fromArray:ditheredBits |
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 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1866 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1867 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1868 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1869 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1870 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1871 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
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 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1875 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1876 |
|
829 | 1877 |
i := Depth24Image width:4 height:1 |
1878 |
fromArray:#[ |
|
1879 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1880 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1881 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1882 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00]. |
|
1883 |
i := i magnifiedBy:4@1. |
|
1884 |
i inspect. |
|
1885 |
||
1886 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1887 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1888 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1889 |
" |
|
1890 |
||
1891 |
" |
|
1892 |
|i| |
|
1893 |
||
1894 |
i := Depth24Image width:4 height:6 |
|
1895 |
fromArray:#[ |
|
1896 |
16r00 16r00 16r00 16r00 16r00 16r80 16r00 16r00 16rff 16r00 16r80 16r00 |
|
1897 |
16r00 16r80 16r80 16r00 16rFF 16r00 16r00 16rFF 16r80 16r00 16rFF 16rFF |
|
1898 |
16r80 16r00 16r00 16r80 16r00 16r80 16r80 16r00 16rff 16r80 16r80 16r00 |
|
1899 |
16r80 16r80 16r80 16r80 16rFF 16r00 16r80 16rFF 16r80 16r80 16rFF 16rFF |
|
1900 |
16rFF 16r00 16r00 16rFF 16r00 16r80 16rFF 16r00 16rff 16rFF 16r80 16r00 |
|
1901 |
16rFF 16r80 16r80 16rFF 16rFF 16r00 16rFF 16rFF 16r80 16rFF 16rFF 16rFF]. |
|
1902 |
i := i magnifiedBy:30. |
|
1903 |
i inspect. |
|
1904 |
||
1905 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1906 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1907 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1908 |
" |
|
1909 |
" |
|
1910 |
|i| |
|
1911 |
||
1912 |
i := Image fromFile:'granite.tiff'. |
|
1913 |
i inspect. |
|
1914 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1915 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1916 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1917 |
" |
|
1918 |
||
1919 |
" |
|
1920 |
|i| |
|
1921 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1922 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1923 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1924 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1925 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1926 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1927 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1928 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1929 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1930 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1931 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1932 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1933 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1934 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1935 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1936 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1937 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1938 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1939 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1940 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1941 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1942 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1943 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1944 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1945 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1946 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1947 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1948 |
"Created: 10.6.1996 / 12:33:47 / cg" |
829 | 1949 |
"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
|
1950 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1951 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1952 |
asFloydSteinbergDitheredMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1953 |
"return a dithered moncohrome form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1954 |
|
816 | 1955 |
|monoBits clr0 clr1| |
1956 |
||
1957 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
|
1958 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1959 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1960 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1961 |
|i f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1962 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1963 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1964 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1965 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1966 |
|
816 | 1967 |
" |
1968 |
|i f| |
|
1969 |
||
1970 |
i := Depth2Image width:8 height:8 |
|
1971 |
fromArray:#[ |
|
1972 |
4r0000 4r0000 |
|
1973 |
4r0000 4r0000 |
|
1974 |
4r1111 4r1111 |
|
1975 |
4r1111 4r1111 |
|
1976 |
4r2222 4r2222 |
|
1977 |
4r2222 4r2222 |
|
1978 |
4r3333 4r3333 |
|
1979 |
4r3333 4r3333 |
|
1980 |
]. |
|
1981 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
|
1982 |
" |
|
1983 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1984 |
"Created: 10.6.1996 / 14:11:39 / cg" |
816 | 1985 |
"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
|
1986 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1987 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1988 |
asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1989 |
"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
|
1990 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1991 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1992 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1993 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1994 |
^ 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
|
1995 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1996 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1997 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1998 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1999 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2000 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2001 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2002 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2003 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
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 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2008 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2009 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2010 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2011 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2012 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2013 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2014 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2015 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2016 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2017 |
|i| |
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 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2020 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2021 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2022 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2023 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2024 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2025 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2026 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2027 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2028 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2029 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2030 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2031 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2032 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2033 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2034 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2035 |
"Created: 10.6.1996 / 12:33:47 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2036 |
"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
|
2037 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2038 |
|
0 | 2039 |
asFormOn:aDevice |
72 | 2040 |
"get a device form, with best possible approximation. |
2041 |
remember it in case someone asks again." |
|
2042 |
||
2043 |
|form| |
|
2044 |
||
2045 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
|
0 | 2046 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2047 |
aDevice depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2048 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2049 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2050 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2051 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2052 |
^ self asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2053 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2054 |
|
873 | 2055 |
(aDevice visualType == #PseudoColor) ifTrue:[ |
2056 |
form := self asPseudoFormQuickOn:aDevice. |
|
2057 |
form notNil ifTrue:[ |
|
2058 |
^ form |
|
2059 |
]. |
|
2060 |
]. |
|
2061 |
||
0 | 2062 |
(photometric == #palette) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2063 |
form := self paletteImageAsFormOn:aDevice |
72 | 2064 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2065 |
(photometric == #rgb) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2066 |
form := self rgbImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2067 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2068 |
form := self greyImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2069 |
] |
0 | 2070 |
]. |
2071 |
||
72 | 2072 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2073 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2074 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2075 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2076 |
deviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2077 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2078 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2079 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2080 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2081 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2082 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2083 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2084 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2085 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2086 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2087 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2088 |
] |
0 | 2089 |
]. |
2090 |
||
72 | 2091 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2092 |
|
873 | 2093 |
"Modified: 17.6.1996 / 10:41:02 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2094 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2095 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2096 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2097 |
"get a gray device form" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2098 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2099 |
^ self asGrayFormOn:aDevice dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2100 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2101 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2102 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2103 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2104 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2105 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2106 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2107 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2108 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2109 |
"Created: 10.6.1996 / 18:44:42 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2110 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2111 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2112 |
asGrayFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2113 |
"get a greyscale device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2114 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2115 |
|grayBits depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2116 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2117 |
depth := aDevice depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2118 |
depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2119 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2120 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2121 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2122 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2123 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2124 |
^ self asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2125 |
]. |
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 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2128 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2129 |
^ self asOrderedDitheredGrayFormOn: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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2132 |
^ self asFloydSteinbergDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2133 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2134 |
"Created: 10.6.1996 / 18:42:01 / cg" |
852 | 2135 |
"Modified: 14.6.1996 / 15:17:28 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2136 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2137 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2138 |
asGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2139 |
"get a gray image from the receiver" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2140 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2141 |
^ self asGrayImageDepth:depth dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2142 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2143 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2144 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2145 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2146 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2147 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2148 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2149 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2150 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2151 |
"Created: 10.6.1996 / 19:07:08 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2152 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2153 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2154 |
asGrayImageDepth:depth dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2155 |
"get a greyscale image, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2156 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2157 |
|grayBits| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2158 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2159 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2160 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2161 |
^ self asThresholdGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2162 |
]. |
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 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2165 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2166 |
^ self asOrderedDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2167 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2168 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2169 |
^ self asFloydSteinbergDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2170 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2171 |
"Created: 10.6.1996 / 19:08:21 / cg" |
0 | 2172 |
! |
2173 |
||
2174 |
asMonochromeFormOn:aDevice |
|
2175 |
"get a monochrome device form" |
|
2176 |
||
72 | 2177 |
|form| |
2178 |
||
2179 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm]. |
|
2180 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2181 |
form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm. |
0 | 2182 |
|
72 | 2183 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2184 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2185 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2186 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2187 |
monoDeviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2188 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2189 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2190 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2191 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2192 |
Lobby registerChange:self |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2195 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2196 |
twice (here and in the device form) |
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 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2199 |
] |
0 | 2200 |
]. |
2201 |
||
72 | 2202 |
^ form |
813
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2205 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2206 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2207 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2208 |
(i asMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2209 |
" |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2212 |
! |
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 |
asMonochromeFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2215 |
"get a monochrome device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2216 |
|
816 | 2217 |
|monoBits clr0 clr1 mustInvert| |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2218 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2219 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2220 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2221 |
^ self asThresholdMonochromeFormOn:aDevice |
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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2224 |
aDitherAlgorithm == #burkes ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2225 |
monoBits := self burkesDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2226 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2227 |
aDitherAlgorithm == #stevensonArce ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2228 |
monoBits := self stevensonArceDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2229 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2230 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2231 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2232 |
^ self asOrderedDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2233 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2234 |
^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice. |
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 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2237 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2238 |
|
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 |
"/ make its pixel interpretation correct for the device |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2241 |
"/ |
816 | 2242 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
2243 |
||
2244 |
"Modified: 10.6.1996 / 20:18:05 / cg" |
|
89 | 2245 |
! |
2246 |
||
808 | 2247 |
asOrderedDitheredGrayFormOn:aDevice |
2248 |
"return a dithered depth-x grey form from the receiver image. |
|
2249 |
Uses an 8x8 dithermatrix." |
|
2250 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2251 |
|f depth bits| |
808 | 2252 |
|
2253 |
depth := aDevice depth. |
|
2254 |
depth == 1 ifTrue:[ |
|
2255 |
"/ for monochrome, there is highly specialized |
|
2256 |
"/ monochrome dither code available |
|
2257 |
||
2258 |
^ self asOrderedDitheredMonochromeFormOn:aDevice |
|
2259 |
]. |
|
2260 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2261 |
bits := self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2262 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
808 | 2263 |
ditherWidth:8 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2264 |
depth:depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2265 |
|
816 | 2266 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2267 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2268 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2269 |
|i| |
808 | 2270 |
|
2271 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2272 |
(i asOrderedDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2273 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2274 |
|
816 | 2275 |
"Modified: 10.6.1996 / 20:10:07 / cg" |
808 | 2276 |
! |
2277 |
||
798 | 2278 |
asOrderedDitheredGrayImageDepth:depth |
2279 |
"return a dithered depth-x grey image from the receiver image. |
|
2280 |
Uses an 8x8 dithermatrix." |
|
2281 |
||
2282 |
|dither| |
|
2283 |
||
2284 |
dither := self class orderedDitherMatrixOfSize:8. |
|
2285 |
||
2286 |
depth == 1 ifTrue:[ |
|
2287 |
"/ for monochrome, there is highly specialized |
|
2288 |
"/ monochrome dither code available |
|
2289 |
||
2290 |
^ Depth1Image |
|
2291 |
width:width |
|
2292 |
height:height |
|
2293 |
fromArray:( |
|
2294 |
self |
|
2295 |
orderedDitheredMonochromeBitsWithDitherMatrix:dither |
|
2296 |
ditherWidth:8) |
|
2297 |
]. |
|
2298 |
||
2299 |
^ (self class implementorForDepth:depth) |
|
2300 |
width:width |
|
2301 |
height:height |
|
2302 |
fromArray:( |
|
2303 |
self |
|
2304 |
orderedDitheredBitsWithDitherMatrix:dither |
|
2305 |
ditherWidth:8 |
|
2306 |
depth:depth) |
|
2307 |
||
2308 |
" |
|
2309 |
|i i1 i2 i4 i8| |
|
2310 |
||
2311 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2312 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2313 |
i1 inspect. |
|
2314 |
||
2315 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2316 |
i2 inspect. |
|
2317 |
||
2318 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2319 |
i4 inspect. |
|
2320 |
||
2321 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2322 |
i8 inspect. |
|
2323 |
" |
|
2324 |
||
2325 |
" |
|
2326 |
|i i1 i2 i4 i8| |
|
2327 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2328 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2329 |
i1 inspect. |
|
2330 |
||
2331 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2332 |
i2 inspect. |
|
2333 |
||
2334 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2335 |
i4 inspect. |
|
2336 |
||
2337 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2338 |
i8 inspect. |
|
800 | 2339 |
|
2340 |
i2 := i8 asOrderedDitheredGrayImageDepth:2. |
|
2341 |
i2 inspect. |
|
798 | 2342 |
" |
2343 |
||
2344 |
"Created: 7.6.1996 / 18:03:54 / cg" |
|
800 | 2345 |
"Modified: 7.6.1996 / 19:41:59 / cg" |
798 | 2346 |
! |
2347 |
||
2348 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2349 |
"return a dithered monochrome form from the grey image. |
|
2350 |
Uses a 4x4 dithermatrix." |
|
2351 |
||
2352 |
"/ 4x4 seems a good comprimize between: |
|
2353 |
"/ number of grey levels (8x8 is better) |
|
2354 |
"/ artifacts (4x4 is better) |
|
2355 |
"/ |
|
2356 |
"/ could look at the image and decide upon the number of |
|
2357 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2358 |
"/ 4x4 for small number of colors ... |
|
2359 |
||
2360 |
^ self |
|
2361 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2362 |
ditherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2363 |
ditherWidth:4 |
|
2364 |
||
2365 |
"/ ^ self |
|
2366 |
"/ asOrderedDitheredMonochromeFormOn:aDevice |
|
2367 |
"/ ditherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2368 |
"/ ditherWidth:8 |
|
2369 |
||
2370 |
" |
|
2371 |
|i f| |
|
2372 |
||
2373 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2374 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2375 |
||
2376 |
||
2377 |
|i f| |
|
2378 |
||
2379 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2380 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2381 |
||
2382 |
||
2383 |
|i f| |
|
2384 |
||
2385 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2386 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2387 |
||
2388 |
||
2389 |
|i f| |
|
2390 |
||
2391 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2392 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2393 |
||
2394 |
||
2395 |
|i f| |
|
2396 |
||
2397 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
2398 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2399 |
" |
|
2400 |
||
2401 |
"Created: 7.6.1996 / 14:52:32 / cg" |
|
2402 |
"Modified: 7.6.1996 / 16:37:47 / cg" |
|
2403 |
! |
|
2404 |
||
2405 |
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW |
|
2406 |
"return a dithered monochrome form from the image. |
|
2407 |
Uses the passed ditherMatrix and ditherWidth." |
|
2408 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2409 |
|monoBits clr0 clr1| |
798 | 2410 |
|
2411 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
816 | 2412 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2413 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2414 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2415 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2416 |
|i| |
798 | 2417 |
|
2418 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2419 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2420 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2421 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2422 |
|i| |
798 | 2423 |
|
2424 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2425 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2426 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2427 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2428 |
|i| |
798 | 2429 |
|
2430 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2431 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
798 | 2432 |
" |
2433 |
||
2434 |
"Created: 7.6.1996 / 14:51:42 / cg" |
|
816 | 2435 |
"Modified: 10.6.1996 / 20:18:07 / cg" |
798 | 2436 |
! |
2437 |
||
2438 |
asOrderedDitheredMonochromeImage |
|
2439 |
"return a dithered monochrome image from the receiver image. |
|
2440 |
Uses a 4x4 dithermatrix." |
|
2441 |
||
2442 |
"/ 4x4 seems a good comprimize between: |
|
2443 |
"/ number of grey levels (8x8 is better) |
|
2444 |
"/ artifacts (4x4 is better) |
|
2445 |
"/ |
|
2446 |
"/ could look at the image and decide upon the number of |
|
2447 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2448 |
"/ 4x4 for small number of colors ... |
|
2449 |
||
2450 |
^ self |
|
2451 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2452 |
ditherWidth:4 |
|
2453 |
||
2454 |
"/ ^ self |
|
2455 |
"/ asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2456 |
"/ ditherWidth:8 |
|
2457 |
||
2458 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2459 |
|i| |
798 | 2460 |
|
2461 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2462 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2463 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2464 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2465 |
|i| |
798 | 2466 |
|
2467 |
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
|
2468 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2469 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2470 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2471 |
|i| |
798 | 2472 |
|
2473 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2474 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2475 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2476 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2477 |
|i| |
798 | 2478 |
|
2479 |
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
|
2480 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2481 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2482 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2483 |
|i| |
798 | 2484 |
|
2485 |
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
|
2486 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2487 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2488 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2489 |
|i| |
798 | 2490 |
|
2491 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2492 |
i asOrderedDitheredMonochromeImage inspect |
798 | 2493 |
" |
2494 |
||
2495 |
"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
|
2496 |
"Modified: 10.6.1996 / 11:15:09 / cg" |
798 | 2497 |
! |
2498 |
||
2499 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
2500 |
"return a dithered monochrome image from the receiver image. |
|
2501 |
Uses the passed ditherMatrix and ditherWidth." |
|
2502 |
||
2503 |
|monoBits| |
|
2504 |
||
2505 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
2506 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
|
2507 |
||
2508 |
"order-4 dither: |
|
2509 |
||
2510 |
|i| |
|
2511 |
||
2512 |
i := Image fromFile:'garfield.gif'. |
|
2513 |
i |
|
2514 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4) |
|
2515 |
ditherWidth:4 |
|
2516 |
" |
|
2517 |
||
2518 |
"order-6 dither: |
|
2519 |
||
2520 |
|i| |
|
2521 |
||
2522 |
i := Image fromFile:'garfield.gif'. |
|
2523 |
i |
|
2524 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8) |
|
2525 |
ditherWidth:8 |
|
2526 |
" |
|
2527 |
||
2528 |
||
2529 |
"thresholding at:0.5 (all above 0.5 becomes white): |
|
2530 |
||
2531 |
|i| |
|
2532 |
||
2533 |
i := Image fromFile:'garfield.gif'. |
|
2534 |
i |
|
2535 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8) |
|
2536 |
ditherWidth:4 |
|
2537 |
" |
|
2538 |
||
2539 |
"thresholding at: 0.25 (all above 0.25 becomes white): |
|
2540 |
||
2541 |
|i| |
|
2542 |
||
2543 |
i := Image fromFile:'garfield.gif'. |
|
2544 |
i |
|
2545 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3) |
|
2546 |
ditherWidth:4 |
|
2547 |
" |
|
2548 |
||
2549 |
"thresholding at: 0.75 (all above 0.75 becomes white): |
|
2550 |
||
2551 |
|i| |
|
2552 |
||
2553 |
i := Image fromFile:'garfield.gif'. |
|
2554 |
i |
|
2555 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11) |
|
2556 |
ditherWidth:4 |
|
2557 |
" |
|
2558 |
||
2559 |
"Modified: 7.6.1996 / 17:23:47 / cg" |
|
2560 |
! |
|
2561 |
||
873 | 2562 |
asPseudoFormQuickOn:aDevice |
2563 |
"return a pseudo-deviceForm from the image. |
|
2564 |
Fail if colors are not fully available." |
|
2565 |
||
2566 |
|f d dDev temp temp8 bits anyMissing clr cMap idMap |
|
2567 |
nClr "{ Class: SmallInteger }" | |
|
2568 |
||
2569 |
d := self depth. |
|
2570 |
(d == 1 |
|
2571 |
or:[d == 2 |
|
2572 |
or:[d == 4 |
|
2573 |
or:[d == 8]]]) ifFalse:[^ nil]. |
|
2574 |
||
2575 |
"/ |
|
2576 |
"/ see if all of the images colors are representable |
|
2577 |
"/ on the device |
|
2578 |
||
2579 |
bits := self bitsPerPixel. |
|
2580 |
nClr := (1 bitShift:bits). |
|
2581 |
cMap := Array new:nClr. |
|
2582 |
idMap := ByteArray new:nClr. |
|
2583 |
||
2584 |
photometric == #palette ifTrue:[ |
|
2585 |
nClr := nClr min:(colorMap size) |
|
2586 |
]. |
|
2587 |
||
2588 |
1 to:nClr do:[:pixel | |
|
2589 |
clr := self colorFromValue:pixel-1. |
|
2590 |
clr := clr exactOn:aDevice. |
|
2591 |
clr isNil ifTrue:[^ nil]. |
|
2592 |
||
2593 |
cMap at:(pixel) put:clr. |
|
2594 |
idMap at:(pixel) put:(clr colorId). |
|
2595 |
]. |
|
2596 |
||
2597 |
"/ got all colors; good - simply change depth & translate pixels |
|
2598 |
||
2599 |
dDev := aDevice depth. |
|
2600 |
||
2601 |
(d == 8 and:[dDev == 8]) ifTrue:[ |
|
2602 |
"/ only translate |
|
2603 |
temp := ByteArray uninitializedNew:(width * height). |
|
2604 |
bytes expandPixels:8 "xlate only" |
|
2605 |
width:width |
|
2606 |
height:height |
|
2607 |
into:temp |
|
2608 |
mapping:idMap. |
|
2609 |
] ifFalse:[ |
|
2610 |
||
2611 |
"/ stupid: expandPixels can only handle any-to-8 |
|
2612 |
"/ compressPixels can only handle 8-to-any |
|
2613 |
||
2614 |
d ~~ 8 ifTrue:[ |
|
2615 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
2616 |
||
2617 |
bytes expandPixels:d |
|
2618 |
width:width |
|
2619 |
height:height |
|
2620 |
into:temp8 |
|
2621 |
mapping:idMap. |
|
2622 |
idMap := nil. |
|
2623 |
] ifFalse:[ |
|
2624 |
temp8 := bytes. |
|
2625 |
]. |
|
2626 |
||
2627 |
dDev ~~ 8 ifTrue:[ |
|
2628 |
temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height). |
|
2629 |
||
2630 |
temp8 compressPixels:dDev |
|
2631 |
width:width |
|
2632 |
height:height |
|
2633 |
into:temp |
|
2634 |
mapping:idMap. |
|
2635 |
] ifFalse:[ |
|
2636 |
temp := temp8 |
|
2637 |
]. |
|
2638 |
]. |
|
2639 |
||
2640 |
f := Form width:width height:height depth:dDev on:aDevice. |
|
2641 |
f isNil ifTrue:[^ nil]. |
|
2642 |
||
2643 |
f colorMap:cMap. |
|
2644 |
f initGC. |
|
2645 |
||
2646 |
aDevice |
|
2647 |
drawBits:temp |
|
2648 |
depth:dDev |
|
2649 |
width:width |
|
2650 |
height:height |
|
2651 |
x:0 y:0 |
|
2652 |
into:(f id) x:0 y:0 |
|
2653 |
width:width |
|
2654 |
height:height |
|
2655 |
with:(f gcId). |
|
2656 |
||
2657 |
^ f |
|
2658 |
||
2659 |
" |
|
2660 |
( |
|
2661 |
(((Depth4Image |
|
2662 |
width:4 |
|
2663 |
height:4 |
|
2664 |
fromArray:#[ |
|
2665 |
16r01 16r23 |
|
2666 |
16r45 16r67 |
|
2667 |
16r89 16rab |
|
2668 |
16rcd 16ref |
|
2669 |
])) |
|
2670 |
magnifiedBy:30 |
|
2671 |
) |
|
2672 |
asPseudoFormQuickOn:Display |
|
2673 |
) inspect |
|
2674 |
" |
|
2675 |
||
2676 |
"Modified: 17.6.1996 / 11:39:55 / cg" |
|
2677 |
! |
|
2678 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2679 |
asStevensonArceDitheredMonochromeImage |
837 | 2680 |
"return a stevenson-arce dithered monochrome image from the receiver image. |
2681 |
Depending on the images contents, this may or may not look better than |
|
2682 |
a floyd-steinberg dithered image. |
|
2683 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
2684 |
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
|
2685 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2686 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2687 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2688 |
monoBits := self stevensonArceDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2689 |
^ (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
|
2690 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2691 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2692 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2693 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2694 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2695 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2696 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2697 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2698 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2699 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2700 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2701 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2702 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2703 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2704 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2705 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2706 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2707 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2708 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2709 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2710 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2711 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2712 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2713 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2714 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2715 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2716 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2717 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2718 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2719 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2720 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2721 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2722 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2723 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2724 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2725 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2726 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2727 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2728 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2729 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2730 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2731 |
"Created: 10.6.1996 / 12:38:29 / cg" |
837 | 2732 |
"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
|
2733 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2734 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2735 |
asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2736 |
"return a thresholded grey form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2737 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2738 |
|depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2739 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2740 |
(depth := aDevice depth) == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2741 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2742 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2743 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2744 |
^ self |
816 | 2745 |
makeDeviceGrayPixmapOn:aDevice |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2746 |
depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2747 |
fromArray:(self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2748 |
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
|
2749 |
ditherWidth:4 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2750 |
depth:depth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2751 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2752 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2753 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2754 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2755 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2756 |
(i asThresholdGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2757 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2758 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2759 |
"Created: 10.6.1996 / 18:38:31 / cg" |
816 | 2760 |
"Modified: 10.6.1996 / 20:10:26 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2761 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2762 |
|
798 | 2763 |
asThresholdGrayImageDepth:depth |
2764 |
"return a thresholded depth-x grey image from the receiver image." |
|
2765 |
||
800 | 2766 |
depth == 1 ifTrue:[ |
2767 |
"/ for monochrome, there is highly specialized |
|
2768 |
"/ monochrome dither code available |
|
2769 |
||
2770 |
^ Depth1Image |
|
2771 |
width:width |
|
2772 |
height:height |
|
2773 |
fromArray:( |
|
2774 |
self |
|
2775 |
orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2776 |
ditherWidth:4) |
|
2777 |
]. |
|
2778 |
||
798 | 2779 |
^ (self class implementorForDepth:depth) |
2780 |
width:width |
|
2781 |
height:height |
|
2782 |
fromArray:( |
|
2783 |
self |
|
2784 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2785 |
ditherWidth:4 |
|
2786 |
depth:depth) |
|
2787 |
||
2788 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2789 |
|i| |
798 | 2790 |
|
2791 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2792 |
(i asThresholdGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2793 |
(i asThresholdGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2794 |
(i asThresholdGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2795 |
(i asThresholdGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2796 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2797 |
(i asOrderedDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2798 |
(i asOrderedDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2799 |
(i asOrderedDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2800 |
(i asOrderedDitheredGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2801 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2802 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2803 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2804 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2805 |
(i asFloydSteinbergDitheredGrayImageDepth:8) inspect. |
798 | 2806 |
" |
2807 |
||
2808 |
"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
|
2809 |
"Modified: 10.6.1996 / 14:20:56 / cg" |
798 | 2810 |
! |
2811 |
||
2812 |
asThresholdMonochromeFormOn:aDevice |
|
2813 |
"return a threshold monochrome form from the image." |
|
2814 |
||
2815 |
^ self |
|
2816 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2817 |
ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2818 |
ditherWidth:4 |
|
2819 |
||
2820 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2821 |
|i| |
798 | 2822 |
|
2823 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2824 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2825 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2826 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2827 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2828 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2829 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2830 |
i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2831 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2832 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2833 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2834 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2835 |
|i| |
798 | 2836 |
|
2837 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2838 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2839 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2840 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2841 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2842 |
|i| |
798 | 2843 |
|
2844 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2845 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2846 |
(i asThresholdMonochromeFormOn:Display) inspect |
798 | 2847 |
" |
2848 |
||
2849 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2850 |
"Modified: 10.6.1996 / 17:44:29 / cg" |
798 | 2851 |
! |
2852 |
||
2853 |
asThresholdMonochromeImage |
|
2854 |
"return a threshold monochrome image from the image. |
|
2855 |
Threshold means: brightness < 0.5 -> black / otherwise white" |
|
2856 |
||
2857 |
^ self |
|
2858 |
asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2859 |
ditherWidth:4 |
|
2860 |
||
2861 |
" |
|
2862 |
|i i2| |
|
2863 |
||
2864 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2865 |
i2 := i asThresholdMonochromeImage |
|
2866 |
||
2867 |
||
2868 |
|i i2| |
|
2869 |
||
2870 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2871 |
i2 := i asThresholdMonochromeImage |
|
2872 |
||
2873 |
||
2874 |
|i i2| |
|
2875 |
||
2876 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
2877 |
i2 := i asThresholdMonochromeImage |
|
2878 |
||
2879 |
||
2880 |
|i i2| |
|
2881 |
||
2882 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2883 |
i2 := i asThresholdMonochromeImage |
|
2884 |
" |
|
2885 |
||
2886 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
2887 |
"Modified: 7.6.1996 / 17:16:10 / cg" |
|
2888 |
! |
|
2889 |
||
808 | 2890 |
asThresholdMonochromeImage:thresholdBrighness |
2891 |
"return a threshold monochrome image from the image. |
|
2892 |
The argument (0..1) gives the threshold value; |
|
2893 |
Threshold means: brightness < threshold -> black / otherwise white" |
|
2894 |
||
2895 |
|value ditherMatrix| |
|
2896 |
||
2897 |
value := thresholdBrighness * 255. |
|
2898 |
ditherMatrix := ByteArray new:256 withAll:(value truncated). |
|
2899 |
||
2900 |
^ self |
|
2901 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix |
|
2902 |
ditherWidth:16 |
|
2903 |
||
2904 |
" |
|
2905 |
|i| |
|
2906 |
||
2907 |
i := Image width:4 height:4 depth:4 |
|
2908 |
fromArray:#[ 16r01 16r23 |
|
2909 |
16r45 16r67 |
|
2910 |
16r89 16rab |
|
2911 |
16rcd 16ref ]. |
|
2912 |
i := i magnifiedBy:30. |
|
2913 |
i inspect. |
|
2914 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
2915 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
2916 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
2917 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
2918 |
(i asThresholdMonochromeImage:1) inspect. |
|
2919 |
" |
|
2920 |
||
2921 |
" |
|
2922 |
|i| |
|
2923 |
||
2924 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2925 |
i inspect. |
|
2926 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
2927 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
2928 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
2929 |
(i asThresholdMonochromeImage:0.625) inspect. |
|
2930 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
2931 |
" |
|
2932 |
||
2933 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
2934 |
"Modified: 8.6.1996 / 14:51:57 / cg" |
|
2935 |
! |
|
2936 |
||
283 | 2937 |
fromForm:aForm |
592 | 2938 |
"setup the receiver from a form" |
283 | 2939 |
|
2940 |
|map c0 c1| |
|
2941 |
||
2942 |
width := aForm width. |
|
2943 |
height := aForm height. |
|
2944 |
bytes := aForm bits. |
|
2945 |
bitsPerSample := self bitsPerSample. |
|
2946 |
samplesPerPixel := self samplesPerPixel. |
|
2947 |
map := aForm colorMap. |
|
2948 |
||
2949 |
aForm depth == 1 ifTrue:[ |
|
592 | 2950 |
map isNil ifTrue:[ |
2951 |
photometric := #whiteIs0 |
|
2952 |
] ifFalse:[ |
|
2953 |
c0 := map at:1. |
|
2954 |
c1 := map at:2. |
|
2955 |
((c0 = Color white) |
|
2956 |
and:[c1 = Color black]) ifTrue:[ |
|
2957 |
photometric := #whiteIs0 |
|
2958 |
] ifFalse:[ |
|
2959 |
((c0 = Color black) |
|
2960 |
and:[c1 = Color white]) ifTrue:[ |
|
2961 |
photometric := #blackIs0 |
|
2962 |
] ifFalse:[ |
|
2963 |
photometric := #palette. |
|
2964 |
colorMap := Array with:c0 with:c1. |
|
2965 |
] |
|
2966 |
] |
|
2967 |
] |
|
283 | 2968 |
] ifFalse:[ |
592 | 2969 |
map notNil ifTrue:[ |
2970 |
photometric := #palette. |
|
2971 |
colorMap := map copy. |
|
2972 |
] ifFalse:[ |
|
2973 |
" |
|
2974 |
photometric stays at default |
|
2975 |
(which is rgb for d24, greyscale for others) |
|
2976 |
" |
|
2977 |
] |
|
283 | 2978 |
]. |
592 | 2979 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2980 |
"Modified: 8.6.1996 / 16:02:03 / cg" |
283 | 2981 |
! |
2982 |
||
89 | 2983 |
fromImage:anImage |
2984 |
"setup the receiver from another image. |
|
2985 |
Color precision may be lost, if conversion is from a higher depth |
|
191 | 2986 |
image. |
2987 |
WARNING: |
|
2988 |
This implementation is a slow fallback (the loop over the |
|
89 | 2989 |
source pixels is very slow). If this method is used heavily, you |
2990 |
may want to redefine it in concrete subclasses for common source images." |
|
2991 |
||
2992 |
width := anImage width. |
|
2993 |
height := anImage height. |
|
2994 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
2995 |
bitsPerSample := self bitsPerSample. |
|
2996 |
samplesPerPixel := self samplesPerPixel. |
|
191 | 2997 |
self colormapFromImage:anImage. |
89 | 2998 |
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr | |
798 | 2999 |
self atX:x y:y put:clr |
89 | 3000 |
]. |
3001 |
||
3002 |
" |
|
798 | 3003 |
|i i2 i4 i8 i16 i24| |
89 | 3004 |
|
3005 |
i := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
3006 |
i inspect. |
|
3007 |
i2 := Depth2Image fromImage:i. |
|
3008 |
i2 inspect. |
|
3009 |
i4 := Depth4Image fromImage:i. |
|
3010 |
i4 inspect. |
|
3011 |
i8 := Depth8Image fromImage:i. |
|
3012 |
i8 inspect. |
|
3013 |
i24 := Depth24Image fromImage:i. |
|
3014 |
i24 inspect. |
|
3015 |
" |
|
191 | 3016 |
|
3017 |
"Created: 20.9.1995 / 00:59:03 / claus" |
|
798 | 3018 |
"Modified: 7.6.1996 / 16:23:03 / cg" |
191 | 3019 |
! |
3020 |
||
3021 |
fromSubImage:anImage in:aRectangle |
|
3022 |
"setup the receiver from another image, extracting a rectangular |
|
3023 |
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
|
3024 |
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
|
3025 |
represented. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3026 |
|
191 | 3027 |
WARNING: |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3028 |
This implementation is a slow fallback (the loop over the |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3029 |
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
|
3030 |
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
|
3031 |
of creating a subImage with the same depth & palette." |
191 | 3032 |
|
3033 |
|x0 y0| |
|
3034 |
||
3035 |
width := aRectangle width + 1. |
|
3036 |
height := aRectangle height + 1. |
|
3037 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3038 |
bitsPerSample := self bitsPerSample. |
|
3039 |
samplesPerPixel := self samplesPerPixel. |
|
3040 |
self colormapFromImage:anImage. |
|
3041 |
x0 := aRectangle left. |
|
3042 |
y0 := aRectangle top. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3043 |
|
191 | 3044 |
((photometric == anImage photometric) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3045 |
and:[self bitsPerPixel = anImage bitsPerPixel |
191 | 3046 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3047 |
"/ can do it by value |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3048 |
anImage valuesFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3049 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3050 |
do:[:x :y :pixelValue | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3051 |
self atX:x-x0 y:y-y0 putValue:pixelValue. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3052 |
] |
191 | 3053 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3054 |
"/ must do it by colors |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3055 |
anImage colorsFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3056 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3057 |
do:[:x :y :clr | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3058 |
self atX:x-x0 y:y-y0 put:clr. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3059 |
] |
191 | 3060 |
]. |
3061 |
||
3062 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3063 |
|i i2 i4 i8 i16 i24| |
191 | 3064 |
|
3065 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3066 |
i inspect. |
|
3067 |
i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200). |
|
3068 |
i4 inspect. |
|
3069 |
i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200). |
|
3070 |
i8 inspect. |
|
3071 |
i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200). |
|
3072 |
i24 inspect. |
|
3073 |
" |
|
3074 |
||
3075 |
"Created: 20.9.1995 / 01:06:02 / claus" |
|
3076 |
"Modified: 20.9.1995 / 10:15:37 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3077 |
"Modified: 10.6.1996 / 18:30:17 / cg" |
89 | 3078 |
! |
3079 |
||
283 | 3080 |
monochromeOn:aDevice |
3081 |
"return a monochrome device image of the receiver for aDevice. |
|
3082 |
(monochrome, even if device supports colors)" |
|
3083 |
||
3084 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self]. |
|
3085 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
|
3086 |
"oops, I am already accociated to another device |
|
3087 |
- need a copy ... |
|
3088 |
" |
|
3089 |
^ self copy monochromeOn:aDevice |
|
3090 |
]. |
|
3091 |
monoDeviceForm := self asMonochromeFormOn:aDevice. |
|
3092 |
! |
|
3093 |
||
3094 |
on:aDevice |
|
3095 |
"return an image with the same pixels as the receiver, but |
|
3096 |
associated to aDevice. If the receiver is not yet bound to |
|
3097 |
a device, this will be the receiver. Otherwise, a new image |
|
3098 |
is returned." |
|
3099 |
||
3100 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self]. |
|
852 | 3101 |
|
283 | 3102 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
852 | 3103 |
"oops, I am already accociated to another device |
3104 |
- need a copy ... |
|
3105 |
" |
|
3106 |
^ self copy on:aDevice |
|
283 | 3107 |
]. |
3108 |
deviceForm := self asFormOn:aDevice. |
|
3109 |
device := aDevice |
|
852 | 3110 |
|
3111 |
"Modified: 14.6.1996 / 15:28:30 / cg" |
|
283 | 3112 |
! ! |
3113 |
||
3114 |
!Image methodsFor:'converting greyscale images'! |
|
3115 |
||
3116 |
greyImageAsFormOn:aDevice |
|
3117 |
"return a thresholded grey-deviceForm from the grey image." |
|
3118 |
||
3119 |
|pictureDepth nPlanes f| |
|
3120 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3121 |
|
283 | 3122 |
nPlanes := samplesPerPixel. |
3123 |
(nPlanes == 2) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3124 |
'IMAGE: alpha plane ignored' errorPrintNL. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3125 |
nPlanes := 1 |
283 | 3126 |
]. |
3127 |
||
3128 |
pictureDepth := bitsPerSample at:1. |
|
3129 |
||
3130 |
"monochrome is very easy ..." |
|
3131 |
||
3132 |
(pictureDepth == 1) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3133 |
^ Form width:width height:height fromArray:bytes on:aDevice |
283 | 3134 |
]. |
3135 |
||
3136 |
(aDevice visualType == #TrueColor) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3137 |
^ self greyImageAsTrueColorFormOn:aDevice |
283 | 3138 |
]. |
3139 |
||
858 | 3140 |
"/ (aDevice visualType == #PseudoColor |
3141 |
"/ or:[aDevice visualType == #GrayScale |
|
3142 |
"/ or:[aDevice visualType == #StaticColor]]) ifTrue:[ |
|
3143 |
||
3144 |
"/ PseudoColor conversion also works for StaticColor, |
|
3145 |
"/ GrayScale and DirectColor; although possibly with suboptimal results |
|
3146 |
||
3147 |
^ self greyImageAsPseudoFormOn:aDevice |
|
3148 |
||
3149 |
"Modified: 14.6.1996 / 19:32:01 / cg" |
|
283 | 3150 |
! |
3151 |
||
3152 |
greyImageAsPseudoFormOn:aDevice |
|
3153 |
"return an 8-bit pseudo Form from the grey image" |
|
3154 |
||
3155 |
|wideBits pictureDepth f map |
|
3156 |
colorMap usedColors nUsed aColor |
|
3157 |
nColors "{ Class: SmallInteger }" |
|
3158 |
range id| |
|
3159 |
||
3160 |
pictureDepth := bitsPerSample at:1. |
|
3161 |
||
3162 |
(#(2 4 8) includes:pictureDepth) ifFalse:[ |
|
746 | 3163 |
self error:'currently only depth-2, 4 or 8 supported'. |
3164 |
^ nil |
|
283 | 3165 |
]. |
3166 |
||
3167 |
wideBits := ByteArray uninitializedNew:(width * height). |
|
3168 |
||
3169 |
(pictureDepth == 8) ifTrue:[ |
|
746 | 3170 |
"for 8bits, we scan for used colors first; |
3171 |
to avoid allocating too many colors" |
|
3172 |
||
3173 |
usedColors := bytes usedValues. |
|
3174 |
nUsed := usedColors max + 1. |
|
3175 |
||
3176 |
colorMap := Array new:nUsed. |
|
3177 |
photometric == #blackIs0 ifTrue:[ |
|
3178 |
usedColors do:[:grey | |
|
3179 |
colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey)) |
|
3180 |
] |
|
3181 |
] ifFalse:[ |
|
3182 |
usedColors do:[:grey | |
|
3183 |
colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey))) |
|
3184 |
] |
|
3185 |
] |
|
89 | 3186 |
] ifFalse:[ |
746 | 3187 |
nColors := (1 bitShift:pictureDepth). |
3188 |
colorMap := Array new:nColors. |
|
3189 |
range := 100 / (nColors - 1) asFloat. |
|
3190 |
photometric == #blackIs0 ifTrue:[ |
|
3191 |
1 to:nColors do:[:i | |
|
3192 |
colorMap at:i put:(Color gray:(i - 1) * range). |
|
3193 |
]. |
|
3194 |
] ifFalse:[ |
|
3195 |
1 to:nColors do:[:i | |
|
3196 |
colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range). |
|
3197 |
]. |
|
3198 |
]. |
|
283 | 3199 |
]. |
3200 |
||
3201 |
"XXX should reduce 8->6->4->2 planes, if not all colors could be allocated" |
|
3202 |
||
3203 |
"setup the translation map" |
|
3204 |
map := ByteArray uninitializedNew:256. |
|
3205 |
nColors := colorMap size. |
|
3206 |
1 to:nColors do:[:i | |
|
746 | 3207 |
aColor := colorMap at:i. |
3208 |
aColor notNil ifTrue:[ |
|
3209 |
aColor := aColor on:aDevice. |
|
3210 |
colorMap at:i put:aColor. |
|
3211 |
id := aColor colorId. |
|
3212 |
id notNil ifTrue:[ |
|
3213 |
map at:i put:id |
|
3214 |
] ifFalse:[ |
|
3215 |
map at:i put:0 |
|
3216 |
] |
|
3217 |
] |
|
89 | 3218 |
]. |
283 | 3219 |
|
3220 |
"expand & translate" |
|
3221 |
bytes expandPixels:pictureDepth |
|
746 | 3222 |
width:width |
3223 |
height:height |
|
3224 |
into:wideBits |
|
3225 |
mapping:map. |
|
283 | 3226 |
|
3227 |
f := Form width:width height:height depth:8 on:aDevice. |
|
3228 |
f isNil ifTrue:[^ nil]. |
|
3229 |
f colorMap:colorMap. |
|
3230 |
f initGC. |
|
3231 |
aDevice drawBits:wideBits depth:8 width:width height:height |
|
746 | 3232 |
x:0 y:0 |
3233 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
283 | 3234 |
^ f |
746 | 3235 |
|
3236 |
"Modified: 28.5.1996 / 20:55:57 / cg" |
|
0 | 3237 |
! |
3238 |
||
283 | 3239 |
greyImageAsTrueColorFormOn:aDevice |
3240 |
"return a true-color device-form for the grey-image receiver. |
|
3241 |
TODO: the pixel loops ought to be implemented as inline primitive code ..." |
|
3242 |
||
3243 |
|depth |
|
3244 |
myDepth "{ Class: SmallInteger }" |
|
3245 |
nColors "{ Class: SmallInteger }" |
|
3246 |
colorValues |
|
3247 |
scaleDown scaleRed scaleGreen scaleBlue redShift blueShift greenShift |
|
3248 |
form imageBitsdestIndex |
|
3249 |
bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits destIndex |
|
3250 |
nPixels| |
|
3251 |
||
3252 |
"/ this is a slow fallback method; this ought to be |
|
3253 |
"/ redefined in DepthxImage for more performance. |
|
3254 |
||
3255 |
depth := aDevice depth. |
|
3256 |
myDepth := self depth. |
|
3257 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3258 |
self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3259 |
^ nil |
0 | 3260 |
]. |
3261 |
||
283 | 3262 |
"/ compute scale to map from my pixels into devices range |
3263 |
||
3264 |
scaleDown := 1 bitShift:myDepth. |
|
3265 |
scaleRed := (1 bitShift:aDevice bitsRed). |
|
3266 |
scaleGreen := (1 bitShift:aDevice bitsGreen). |
|
3267 |
scaleBlue := (1 bitShift:aDevice bitsBlue). |
|
3268 |
redShift := aDevice shiftRed. |
|
3269 |
greenShift := aDevice shiftGreen. |
|
3270 |
blueShift := aDevice shiftBlue. |
|
3271 |
||
3272 |
nColors := (1 bitShift:myDepth). |
|
3273 |
colorValues := Array new:nColors. |
|
3274 |
1 to:nColors do:[:i | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3275 |
|v gv bv rv nv| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3276 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3277 |
"/ scale down to 0..1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3278 |
v := (i-1) / scaleDown. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3279 |
rv := (v * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3280 |
gv := (v * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3281 |
bv := (v * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3282 |
nv := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3283 |
nv := nv bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3284 |
nv := nv bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3285 |
colorValues at:i put:nv |
0 | 3286 |
]. |
283 | 3287 |
photometric == #whiteIs0 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3288 |
"/ reverse the order; 0 is brightest |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3289 |
colorValues reverse |
283 | 3290 |
]. |
193 | 3291 |
|
3292 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3293 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3294 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3295 |
|
283 | 3296 |
"/ for now, only support some depths |
3297 |
||
3298 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3299 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3300 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3301 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3302 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3303 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3304 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3305 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3306 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3307 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3308 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3309 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3310 |
imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3311 |
destIndex := destIndex + 2. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3312 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3313 |
] |
283 | 3314 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3315 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3316 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3317 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3318 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3319 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3320 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3321 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3322 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3323 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3324 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3325 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3326 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3327 |
imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3328 |
destIndex := destIndex + 4. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3329 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3330 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3331 |
] |
193 | 3332 |
]. |
3333 |
||
283 | 3334 |
imageBits isNil ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3335 |
'IMAGE: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3336 |
^ self asMonochromeFormOn:aDevice |
283 | 3337 |
]. |
3338 |
||
3339 |
form := |
|
193 | 3340 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
283 | 3341 |
form isNil ifTrue:[^ nil]. |
193 | 3342 |
form initGC. |
3343 |
||
3344 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3345 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3346 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3347 |
x:0 y:0 toX:0 y:0. |
193 | 3348 |
|
3349 |
^ form |
|
3350 |
||
283 | 3351 |
"Created: 20.10.1995 / 22:05:10 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3352 |
"Modified: 10.6.1996 / 19:15:13 / cg" |
0 | 3353 |
! ! |
3354 |
||
3355 |
!Image methodsFor:'converting palette images'! |
|
3356 |
||
3357 |
paletteImageAsFormOn:aDevice |
|
72 | 3358 |
"return a device-form for the palette-image receiver" |
3359 |
||
380 | 3360 |
|type ddepth| |
193 | 3361 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3362 |
ddepth := aDevice depth. |
379 | 3363 |
|
193 | 3364 |
((type := aDevice visualType) == #StaticGray) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3365 |
ddepth == 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3366 |
^ self paletteImageAsGray8FormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3367 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3368 |
^ self asGrayFormOn:aDevice |
0 | 3369 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3370 |
|
193 | 3371 |
(type == #TrueColor) ifTrue:[ |
854 | 3372 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
3373 |
ddepth == 8 ifTrue:[ |
|
3374 |
self depth == 8 ifTrue:[ |
|
3375 |
"/ use fixColor dither algorithm |
|
3376 |
^ self asDitheredTrueColor8FormOn:aDevice |
|
3377 |
] |
|
3378 |
] |
|
3379 |
]. |
|
3380 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3381 |
^ self paletteImageAsTrueColorFormOn:aDevice |
193 | 3382 |
]. |
858 | 3383 |
|
3384 |
"/ the PseudoColor conversion also works for |
|
3385 |
"/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results |
|
3386 |
||
3387 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
3388 |
||
3389 |
"Modified: 14.6.1996 / 19:31:01 / cg" |
|
0 | 3390 |
! |
3391 |
||
3392 |
paletteImageAsPseudoFormOn:aDevice |
|
72 | 3393 |
"return a pseudo-deviceForm from the palette image." |
0 | 3394 |
|
89 | 3395 |
|tempImage d temp8| |
3396 |
||
3397 |
d := self depth. |
|
3398 |
(#(1 2 4 8) includes:d) ifTrue:[ |
|
3399 |
" |
|
3400 |
fallback code for some depth's: |
|
3401 |
create a temporary Depth8Image and use its conversion method |
|
3402 |
" |
|
3403 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
3404 |
||
3405 |
bytes expandPixels:d |
|
3406 |
width:width |
|
3407 |
height:height |
|
3408 |
into:temp8 |
|
3409 |
mapping:nil. |
|
3410 |
||
3411 |
tempImage := Image width:width height:height depth:8 fromArray:temp8. |
|
3412 |
tempImage colorMap:colorMap. |
|
3413 |
^ tempImage paletteImageAsPseudoFormOn:aDevice |
|
3414 |
]. |
|
2 | 3415 |
^ self subclassResponsibility |
0 | 3416 |
! |
3417 |
||
193 | 3418 |
paletteImageAsTrueColorFormOn:aDevice |
3419 |
"return a true-color device-form for the palette-image receiver." |
|
3420 |
||
209 | 3421 |
|depth |
3422 |
myDepth "{ Class: SmallInteger }" |
|
3423 |
nColors "{ Class: SmallInteger }" |
|
3424 |
colorValues |
|
193 | 3425 |
scaleRed scaleGreen scaleBlue redShift greenShift blueShift |
194 | 3426 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
854 | 3427 |
destIndex| |
193 | 3428 |
|
3429 |
"/ this is a slow fallback method; this ought to be |
|
3430 |
"/ redefined in DepthxImage for more performance. |
|
3431 |
||
3432 |
depth := aDevice depth. |
|
3433 |
myDepth := self bitsPerPixel. |
|
3434 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3435 |
'IMAGE: depth > 12 not supported' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3436 |
^ nil |
193 | 3437 |
]. |
3438 |
||
3439 |
"/ gather r/g/b values for all colors in the map ... |
|
3440 |
||
3441 |
nColors := colorMap size. |
|
3442 |
||
3443 |
"/ precompute scales to map from 0..100 into devices range |
|
3444 |
"/ (this may be different for the individual components) |
|
3445 |
||
3446 |
scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100. |
|
3447 |
scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100. |
|
3448 |
scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100. |
|
3449 |
redShift := aDevice shiftRed. |
|
3450 |
greenShift := aDevice shiftGreen. |
|
3451 |
blueShift := aDevice shiftBlue. |
|
3452 |
||
3453 |
colorValues := Array uninitializedNew:nColors. |
|
3454 |
||
3455 |
1 to:nColors do:[:index | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3456 |
|clr rv gv bv v "{ Class: SmallInteger }" | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3457 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3458 |
clr := colorMap at:index. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3459 |
clr notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3460 |
rv := (clr red * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3461 |
gv := (clr green * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3462 |
bv := (clr blue * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3463 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3464 |
v := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3465 |
v := v bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3466 |
v := v bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3467 |
colorValues at:index put:v. |
193 | 3468 |
"/ clr print. ' ' print. |
3469 |
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print. |
|
3470 |
"/ ' -> ' print. v printNL. |
|
3471 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3472 |
] |
193 | 3473 |
]. |
3474 |
||
3475 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3476 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3477 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3478 |
|
3479 |
"/ for now, only support some depths |
|
3480 |
||
854 | 3481 |
"/ 16 bits/pixel |
3482 |
||
193 | 3483 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3484 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3485 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3486 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3487 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3488 |
|
854 | 3489 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3490 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3491 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3492 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3493 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3494 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3495 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3496 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3497 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3498 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3499 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3500 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3501 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3502 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3503 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3504 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3505 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3506 |
OBJ clr; |
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 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3509 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3510 |
v = __intVal(clr); |
193 | 3511 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3512 |
((short *)dstPtr)[0] = v; |
193 | 3513 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3514 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3515 |
dstPtr[1] = (v) & 0xFF; |
193 | 3516 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3517 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3518 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3519 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3520 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3521 |
} |
193 | 3522 |
%}. |
3523 |
] ifFalse:[ |
|
854 | 3524 |
"/ 32 bits/pixel |
3525 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3526 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3527 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3528 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3529 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3530 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3531 |
|
854 | 3532 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3533 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3534 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3535 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3536 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3537 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3538 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3539 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3540 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3541 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3542 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3543 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3544 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3545 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3546 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3547 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3548 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3549 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3550 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3551 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3552 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3553 |
v = __intVal(clr); |
193 | 3554 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3555 |
((long *)dstPtr)[0] = v; |
193 | 3556 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3557 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3558 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3559 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3560 |
dstPtr[3] = (v) & 0xFF; |
193 | 3561 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3562 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3563 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3564 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3565 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3566 |
} |
193 | 3567 |
%}. |
854 | 3568 |
] ifFalse:[ |
3569 |
"/ 8 bits/pixel |
|
3570 |
||
3571 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
3572 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
3573 |
||
3574 |
"/ now, walk over the image and replace |
|
3575 |
"/ colorMap indices by color values in the bits array |
|
3576 |
||
3577 |
%{ |
|
3578 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
3579 |
&& __isArray(colorValues) |
|
3580 |
&& __isByteArray(_INST(bytes)) |
|
3581 |
&& (myDepth == __MKSMALLINT(8)) |
|
3582 |
&& __isByteArray(imageBits)) { |
|
3583 |
int x, y, w, h, nPix; |
|
3584 |
||
3585 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
3586 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
3587 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
|
3588 |
||
3589 |
w = __intVal(_INST(width)); |
|
3590 |
h = __intVal(_INST(height)); |
|
3591 |
nPix = w * h; |
|
3592 |
while (nPix > 0) { |
|
3593 |
unsigned idx, v; |
|
3594 |
OBJ clr; |
|
3595 |
||
3596 |
idx = *srcPtr; |
|
3597 |
clr = ap[idx]; |
|
3598 |
v = __intVal(clr); |
|
3599 |
||
3600 |
dstPtr[0] = v; |
|
3601 |
||
3602 |
dstPtr += 1; |
|
3603 |
srcPtr += 1; |
|
3604 |
nPix--; |
|
3605 |
} |
|
3606 |
} |
|
3607 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3608 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3609 |
] |
193 | 3610 |
]. |
3611 |
||
3612 |
imageBits isNil ifTrue:[ |
|
854 | 3613 |
'IMAGE: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintNL. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3614 |
^ self asMonochromeFormOn:aDevice |
193 | 3615 |
]. |
3616 |
||
3617 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
3618 |
form isNil ifTrue:[^ nil]. |
|
3619 |
form initGC. |
|
3620 |
||
3621 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3622 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3623 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3624 |
x:0 y:0 toX:0 y:0. |
193 | 3625 |
|
3626 |
^ form |
|
3627 |
||
3628 |
"Created: 20.10.1995 / 22:05:10 / cg" |
|
3629 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
|
0 | 3630 |
! ! |
3631 |
||
283 | 3632 |
!Image methodsFor:'converting rgb images'! |
3633 |
||
854 | 3634 |
asDitheredTrueColor8FormOn:aDevice |
3635 |
"convert an rgb image to a dithered depth8-form on aDevice. |
|
3636 |
Return the device-form." |
|
3637 |
||
3638 |
|fixColors pixel |
|
3639 |
dstIdx "{ Class: SmallInteger }" |
|
3640 |
shiftRed "{ Class: SmallInteger }" |
|
3641 |
shiftGreen "{ Class: SmallInteger }" |
|
3642 |
shiftBlue "{ Class: SmallInteger }" |
|
3643 |
nRed "{ Class: SmallInteger }" |
|
3644 |
nGreen "{ Class: SmallInteger }" |
|
3645 |
nBlue "{ Class: SmallInteger }"| |
|
3646 |
||
3647 |
shiftRed := aDevice shiftRed. |
|
3648 |
shiftGreen := aDevice shiftGreen. |
|
3649 |
shiftBlue := aDevice shiftBlue. |
|
3650 |
||
3651 |
nRed := (1 bitShift:aDevice bitsRed). |
|
3652 |
nGreen := (1 bitShift:aDevice bitsGreen). |
|
3653 |
nBlue := (1 bitShift:aDevice bitsBlue). |
|
3654 |
||
3655 |
fixColors := Array new:(nRed * nGreen * nBlue). |
|
3656 |
||
3657 |
dstIdx := 1. |
|
3658 |
0 to:nRed - 1 do:[:sR | |
|
3659 |
0 to:nGreen - 1 do:[:sG | |
|
3660 |
0 to:nBlue - 1 do:[:sB | |
|
3661 |
pixel := (sR bitShift:shiftRed) |
|
3662 |
+ (sG bitShift:shiftGreen) |
|
3663 |
+ (sB bitShift:shiftBlue). |
|
3664 |
fixColors at:dstIdx put:(Color colorId:(pixel)). |
|
3665 |
dstIdx := dstIdx + 1 |
|
3666 |
] |
|
3667 |
] |
|
3668 |
]. |
|
3669 |
||
3670 |
^ self |
|
3671 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
3672 |
colors:fixColors |
|
3673 |
nRed:nRed nGreen:nGreen nBlue:nBlue |
|
3674 |
||
3675 |
"Modified: 14.6.1996 / 17:18:57 / cg" |
|
3676 |
"Created: 14.6.1996 / 17:23:52 / cg" |
|
3677 |
! |
|
3678 |
||
283 | 3679 |
rgbImageAsFormOn:aDevice |
3680 |
"convert am rgb image to a device-form on aDevice. |
|
3681 |
Return the device-form." |
|
3682 |
||
3683 |
|visual| |
|
3684 |
||
3685 |
visual := aDevice visualType. |
|
3686 |
(visual == #StaticGray) ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3687 |
^ self asGrayFormOn:aDevice |
0 | 3688 |
]. |
283 | 3689 |
(visual == #TrueColor) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3690 |
^ self rgbImageAsTrueColorFormOn:aDevice |
0 | 3691 |
]. |
858 | 3692 |
|
3693 |
"/ PseudoColor conversion also works for StaticColor, GrayScale |
|
3694 |
"/ and DirectColor displays; although possibly with suboptimal results |
|
3695 |
||
283 | 3696 |
^ self rgbImageAsPseudoFormOn:aDevice |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3697 |
|
858 | 3698 |
"Modified: 14.6.1996 / 19:30:06 / cg" |
283 | 3699 |
! |
3700 |
||
3701 |
rgbImageAsPseudoFormOn:aDevice |
|
3702 |
"return a pseudocolor form from the rgb-picture" |
|
3703 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3704 |
|n "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3705 |
depth "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3706 |
palette f| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3707 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3708 |
(depth := self depth) <= 8 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3709 |
"/ 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
|
3710 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3711 |
palette := Array new:(1 bitShift:depth). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3712 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3713 |
n := (1 bitShift:depth)-1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3714 |
0 to:n do:[:pixelValue | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3715 |
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
|
3716 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3717 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3718 |
colorMap := palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3719 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3720 |
f := self paletteImageAsPseudoFormOn:aDevice. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3721 |
colorMap := nil. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3722 |
photometric := #rgb. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3723 |
^ f |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3724 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3725 |
|
283 | 3726 |
^ self subclassResponsibility |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3727 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3728 |
"Modified: 8.6.1996 / 10:58:25 / cg" |
283 | 3729 |
! |
3730 |
||
3731 |
rgbImageAsTrueColorFormOn:aDevice |
|
3732 |
"return a truecolor form from the rgb-picture." |
|
3733 |
||
3734 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
3735 |
form| |
|
193 | 3736 |
|
3737 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3738 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3739 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3740 |
|
854 | 3741 |
"/ 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
|
3742 |
usedDeviceBitsPerPixel == 15 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3743 |
usedDeviceBitsPerPixel := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3744 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3745 |
|
283 | 3746 |
"/ |
3747 |
"/ only the trivial case, where the depths match |
|
3748 |
"/ is handled here; conversions are supposed to |
|
3749 |
"/ be done in concrete subclasses (see D24Image) |
|
3750 |
"/ |
|
3751 |
self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[ |
|
854 | 3752 |
'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
|
3753 |
^ self asMonochromeFormOn:aDevice |
193 | 3754 |
]. |
3755 |
||
283 | 3756 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
3757 |
form isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3758 |
'IMAGE: display bitmap creation failed' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3759 |
^ nil |
193 | 3760 |
]. |
3761 |
form initGC. |
|
3762 |
||
3763 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3764 |
copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3765 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3766 |
x:0 y:0 toX:0 y:0. |
193 | 3767 |
|
3768 |
^ form |
|
3769 |
||
854 | 3770 |
"Modified: 14.6.1996 / 16:57:47 / cg" |
283 | 3771 |
! ! |
3772 |
||
3773 |
!Image methodsFor:'copying'! |
|
3774 |
||
3775 |
postCopy |
|
592 | 3776 |
"redefined to also copy the pixels and the colorMap |
3777 |
and clear out any device handles in the copy." |
|
3778 |
||
283 | 3779 |
bytes := bytes copy. |
3780 |
colorMap := colorMap deepCopy. |
|
3781 |
device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil |
|
592 | 3782 |
|
3783 |
"Modified: 23.4.1996 / 11:12:03 / cg" |
|
283 | 3784 |
! ! |
3785 |
||
3786 |
!Image methodsFor:'displaying'! |
|
3787 |
||
758 | 3788 |
displayFilledOn:aGC |
759 | 3789 |
"display the receiver as an opaque image. |
758 | 3790 |
This allows Images to be wrapped by a FillingWrapper" |
3791 |
||
3792 |
aGC displayOpaqueForm:self x:0 y:0. |
|
3793 |
||
3794 |
"Created: 29.5.1996 / 10:34:18 / cg" |
|
759 | 3795 |
"Modified: 29.5.1996 / 10:52:36 / cg" |
758 | 3796 |
! |
3797 |
||
283 | 3798 |
displayOn:aGC at:aPoint |
592 | 3799 |
"draw the receiver in the graphicsContext, aGC. |
283 | 3800 |
Smalltalk-80 compatibility" |
3801 |
||
672 | 3802 |
self displayOn:aGC x:aPoint x y:aPoint y. |
3803 |
||
3804 |
"Modified: 12.5.1996 / 20:16:38 / cg" |
|
3805 |
! |
|
3806 |
||
3807 |
displayOn:aGC x:x y:y |
|
3808 |
"draw the receiver in the graphicsContext, aGC. |
|
3809 |
Smalltalk-80 compatibility" |
|
3810 |
||
3811 |
aGC displayForm:self x:x y:y. |
|
592 | 3812 |
|
3813 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
|
672 | 3814 |
"Created: 12.5.1996 / 20:14:31 / cg" |
758 | 3815 |
! |
3816 |
||
3817 |
displayStrokedOn:aGC |
|
759 | 3818 |
"display the receiver as an non opaque image. |
758 | 3819 |
This allows Images to be wrapped by a StrokingWrapper" |
3820 |
||
3821 |
aGC displayForm:self x:0 y:0. |
|
3822 |
||
759 | 3823 |
"Created: 29.5.1996 / 10:34:18 / cg" |
3824 |
"Modified: 29.5.1996 / 10:52:30 / cg" |
|
283 | 3825 |
! ! |
3826 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3827 |
!Image methodsFor:'dither helpers'! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3828 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3829 |
burkesDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3830 |
"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
|
3831 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3832 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3833 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3834 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3835 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3836 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3837 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3838 |
errorArray1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3839 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3840 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3841 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3842 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3843 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3844 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3845 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3846 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3847 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3848 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3849 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3850 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3851 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3852 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3853 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3854 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3855 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3856 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3857 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3858 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3859 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3860 |
errorArray := Array new:(w+4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3861 |
errorArray1 := Array new:(w+4) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3862 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3863 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3864 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3865 |
"/ 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
|
3866 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3867 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3868 |
greyValues := self greyMapForRange:(255*1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3869 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3870 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3871 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3872 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3873 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3874 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3875 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3876 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3877 |
errorArray1 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3878 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3879 |
errorArray1 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3880 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3881 |
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
|
3882 |
|eP "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3883 |
eD |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3884 |
eI "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3885 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3886 |
xN "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3887 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3888 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3889 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3890 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3891 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3892 |
xE := x + 2 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3893 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3894 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3895 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3896 |
grey > (127*1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3897 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3898 |
e := grey - (255*1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3899 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3900 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3901 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3902 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3903 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3904 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3905 |
"/ XX 8 4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3906 |
"/ 2 4 8 4 2 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3907 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3908 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3909 |
eI := e // 32. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3910 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3911 |
eP := eI * 8. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3912 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3913 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3914 |
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
|
3915 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3916 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3917 |
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
|
3918 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3919 |
eP := eI * 4. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3920 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3921 |
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
|
3922 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3923 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3924 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3925 |
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
|
3926 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3927 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3928 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3929 |
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
|
3930 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3931 |
eP := eI * 2. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3932 |
xN := xE - 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3933 |
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
|
3934 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3935 |
eD := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3936 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3937 |
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
|
3938 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3939 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3940 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3941 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3942 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3943 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3944 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3945 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3946 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3947 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3948 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3949 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3950 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3951 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3952 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3953 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3954 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3955 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3956 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3957 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3958 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3959 |
"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
|
3960 |
"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
|
3961 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3962 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3963 |
floydSteinbergDitheredBitsDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3964 |
"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
|
3965 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3966 |
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
|
3967 |
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
|
3968 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3969 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3970 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3971 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3972 |
outBits greyValues greyErrors greyPixels greyLevels |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3973 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3974 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3975 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3976 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3977 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3978 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3979 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3980 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3981 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3982 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3983 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3984 |
self error:'unimplemented conversion'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3985 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3986 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3987 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3988 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3989 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3990 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3991 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3992 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3993 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3994 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3995 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3996 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3997 |
greyLevels := (1 bitShift:depth) - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3998 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3999 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4000 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4001 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4002 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4003 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4004 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4005 |
bitCnt := 8. |
809
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 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4008 |
"/ 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
|
4009 |
"/ use table-value in loop |
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 |
greyValues := self greyMapForRange:(greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4012 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4013 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4014 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4015 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4016 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4017 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4018 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4019 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4020 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4021 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4022 |
] ifFalse:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4023 |
((v - v truncated) * 1024) truncated |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4026 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4027 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4028 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4029 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4030 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4031 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4032 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4033 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4034 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4035 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4036 |
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
|
4037 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4038 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4039 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4040 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4041 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4042 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4043 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4044 |
pixel := greyPixels at:(value + 1). |
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 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4047 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4048 |
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
|
4049 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4050 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4051 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4052 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4053 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4054 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4055 |
e := error |
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 |
byte := byte bitOr:pixel. |
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 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4060 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4061 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4062 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4063 |
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
|
4064 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4065 |
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
|
4066 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4067 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4068 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4069 |
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
|
4070 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4071 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4072 |
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
|
4073 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4074 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4075 |
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
|
4076 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4077 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4078 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4079 |
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
|
4080 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4081 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4082 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4083 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4084 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4085 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4086 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4087 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4088 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4089 |
]. |
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 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4092 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4093 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4094 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4095 |
bitCnt := 8. |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4098 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4099 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4100 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4101 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4102 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4103 |
byte := 0. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4106 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4107 |
nextErrorArray := t. |
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 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4110 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4111 |
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
|
4112 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4113 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4114 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4115 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4116 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4117 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4118 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4119 |
grey := (clr brightness * greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4120 |
pixel := grey truncated. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4121 |
error := ((grey - pixel) * 1024) truncated. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4122 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4123 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4124 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4125 |
error := error + (errorArray at:xE). |
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 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4128 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4129 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4130 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4131 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4132 |
e := error |
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 |
byte := byte bitOr:pixel. |
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 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4138 |
e16 := e // 16. |
809
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 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4141 |
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
|
4142 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4143 |
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
|
4144 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4145 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4146 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4147 |
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
|
4148 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4149 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4150 |
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
|
4151 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4152 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4153 |
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
|
4154 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4155 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4156 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4157 |
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
|
4158 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4159 |
]. |
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 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4162 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4163 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4164 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4165 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4166 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4167 |
]. |
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 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4170 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4171 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4172 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4173 |
bitCnt := 8. |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4176 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4177 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4178 |
]. |
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 |
^ outBits |
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 |
"Created: 10.6.1996 / 13:28:22 / cg" |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4183 |
"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
|
4184 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4185 |
|
854 | 4186 |
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
858 | 4187 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
4188 |
which must be a depth-8 image. |
|
4189 |
This is a special-cased dither method for 8-bit palette images being displayed on |
|
4190 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
|
854 | 4191 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
4192 |
colors assigned to aDevice, such as the preallocated colors of the |
|
4193 |
Color class. |
|
4194 |
By passing the ditherColors as extra array, this method can |
|
4195 |
also be used to dither an 8bit image into a smaller number of colors, |
|
4196 |
for example to create dithered Depth4Images from Depth8Images." |
|
4197 |
||
858 | 4198 |
|pseudoBits |
854 | 4199 |
rgbBytes |
4200 |
w "{Class: SmallInteger }" |
|
4201 |
h "{Class: SmallInteger }" |
|
4202 |
index "{Class: SmallInteger }" |
|
4203 |
fixR "{Class: SmallInteger }" |
|
4204 |
fixG "{Class: SmallInteger }" |
|
4205 |
fixB "{Class: SmallInteger }" |
|
4206 |
fixIds failed map lastColor |
|
4207 |
error clr| |
|
4208 |
||
858 | 4209 |
self depth ~~ 8 ifTrue:[^ nil]. |
4210 |
||
854 | 4211 |
fixR := nRed. |
4212 |
fixR == 0 ifTrue:[ ^ nil]. |
|
4213 |
fixG := nGreen. |
|
4214 |
fixG == 0 ifTrue:[ ^ nil]. |
|
4215 |
fixB := nBlue. |
|
4216 |
fixB == 0 ifTrue:[ ^ nil]. |
|
4217 |
||
4218 |
"/ simple check |
|
4219 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
4220 |
self error:'invalid color array passed'. |
|
4221 |
^ nil |
|
4222 |
]. |
|
4223 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
4224 |
||
4225 |
"/ |
|
4226 |
"/ collect color components as integer values (for integer arithmetic) |
|
4227 |
"/ |
|
4228 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
|
4229 |
||
4230 |
index := 1. |
|
4231 |
||
4232 |
photometric == #palette ifTrue:[ |
|
4233 |
lastColor := colorMap size - 1 |
|
4234 |
] ifFalse:[ |
|
4235 |
lastColor := 255. |
|
4236 |
]. |
|
4237 |
0 to:lastColor do:[:pix | |
|
4238 |
clr := self colorFromValue:pix. |
|
4239 |
rgbBytes at:index put:(clr redByte). |
|
4240 |
rgbBytes at:index+1 put:(clr greenByte). |
|
4241 |
rgbBytes at:index+2 put:(clr blueByte). |
|
4242 |
||
4243 |
index := index + 3. |
|
4244 |
]. |
|
4245 |
||
4246 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
4247 |
||
4248 |
w := width + 2. |
|
4249 |
error := ByteArray uninitializedNew:w*(3*2). |
|
4250 |
||
4251 |
w := width. |
|
4252 |
h := height. |
|
4253 |
||
4254 |
failed := true. |
|
4255 |
||
4256 |
%{ |
|
4257 |
int __x, __y; |
|
4258 |
int __eR, __eG, __eB; |
|
4259 |
unsigned char *srcP, *dstP; |
|
4260 |
unsigned char *rgbP; |
|
4261 |
unsigned char *idP; |
|
4262 |
short *errP, *eP; |
|
4263 |
int __fR, __fG, __fB; |
|
4264 |
int iR, iG, iB; |
|
4265 |
int idx; |
|
4266 |
int __w = __intVal(w); |
|
4267 |
||
4268 |
if (__isByteArray(__INST(bytes)) |
|
4269 |
&& __isByteArray(pseudoBits) |
|
4270 |
&& __isByteArray(rgbBytes) |
|
4271 |
&& __isByteArray(fixIds) |
|
4272 |
&& __isByteArray(error) |
|
4273 |
&& __bothSmallInteger(fixR, fixG) |
|
4274 |
&& __isSmallInteger(fixB)) { |
|
4275 |
failed = false; |
|
4276 |
||
4277 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
4278 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
4279 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
|
4280 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
4281 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
|
4282 |
__fR = __intVal(fixR)-1; |
|
4283 |
__fG = __intVal(fixG)-1; |
|
4284 |
__fB = __intVal(fixB)-1; |
|
4285 |
||
4286 |
/* |
|
4287 |
* clear error accumulator |
|
4288 |
*/ |
|
4289 |
eP = errP; |
|
4290 |
bzero(eP, (__w+2) * 2 * 3); |
|
4291 |
||
4292 |
for (__y=__intVal(h); __y>0; __y--) { |
|
4293 |
__eR = __eG = __eB = 0; |
|
4294 |
||
4295 |
eP = &(errP[3]); |
|
4296 |
__eR = eP[0]; |
|
4297 |
__eG = eP[1]; |
|
4298 |
__eB = eP[2]; |
|
4299 |
||
4300 |
for (__x=__w; __x>0; __x--) { |
|
4301 |
int __want; |
|
4302 |
int pix; |
|
4303 |
int __wantR, __wantG, __wantB; |
|
4304 |
int idx; |
|
4305 |
int tR, tG, tB; |
|
4306 |
int nR, nG, nB; |
|
4307 |
||
4308 |
pix = *srcP++; |
|
4309 |
||
4310 |
/* |
|
4311 |
* wR, wG and wB is the wanted r/g/b value; |
|
4312 |
*/ |
|
4313 |
idx = pix+pix+pix; /* pix * 3 */ |
|
4314 |
||
4315 |
__wantR = __want = rgbP[idx] + __eR; |
|
4316 |
if (__want > 255) __want = 255; |
|
4317 |
else if (__want < 0) __want = 0; |
|
4318 |
iR = (__want * __fR + 128) / 255; /* red index rounded */ |
|
4319 |
||
4320 |
__wantG = __want = rgbP[idx+1] + __eG; |
|
4321 |
if (__want > 255) __want = 255; |
|
4322 |
else if (__want < 0) __want = 0; |
|
4323 |
iG = (__want * __fG + 128) / 255; /* green index rounded */ |
|
4324 |
||
4325 |
__wantB = __want = rgbP[idx+2] + __eB; |
|
4326 |
if (__want > 255) __want = 255; |
|
4327 |
else if (__want < 0) __want = 0; |
|
4328 |
iB = (__want * __fB + 128) / 255; /* blue index rounded */ |
|
4329 |
||
4330 |
idx = iR * (__fG+1); |
|
4331 |
idx = (idx + iG) * (__fB+1); |
|
4332 |
idx = idx + iB; |
|
4333 |
||
4334 |
/* |
|
4335 |
* store the corresponding dither colors colorId |
|
4336 |
*/ |
|
4337 |
*dstP++ = idP[idx]; |
|
4338 |
||
4339 |
/* |
|
4340 |
* the new error: |
|
4341 |
*/ |
|
4342 |
__eR = __wantR - (iR * 255 / __fR); |
|
4343 |
__eG = __wantG - (iG * 255 / __fG); |
|
4344 |
__eB = __wantB - (iB * 255 / __fB); |
|
4345 |
||
4346 |
/* |
|
4347 |
* distribute the error |
|
4348 |
*/ |
|
4349 |
tR = __eR >> 4; /* 16th of error */ |
|
4350 |
tG = __eG >> 4; |
|
4351 |
tB = __eB >> 4; |
|
4352 |
||
4353 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
4354 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
4355 |
nB = eP[5] + (tB * 7); |
|
4356 |
||
4357 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
4358 |
eP[1] = tG*5; |
|
4359 |
eP[2] = tB*5; |
|
4360 |
||
4361 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
4362 |
eP[-2] = tG*3; |
|
4363 |
eP[-1] = tB*3; |
|
4364 |
||
4365 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
4366 |
eP[4] = __eG - (tG*15); |
|
4367 |
eP[5] = __eB - (tB*15); |
|
4368 |
||
4369 |
__eR = nR; |
|
4370 |
__eG = nG; |
|
4371 |
__eB = nB; |
|
4372 |
||
4373 |
eP += 3; |
|
4374 |
} |
|
4375 |
} |
|
4376 |
} |
|
4377 |
%}. |
|
4378 |
failed ifTrue:[ |
|
4379 |
self primitiveFailed. |
|
4380 |
^ nil |
|
4381 |
]. |
|
4382 |
||
4383 |
^ pseudoBits |
|
4384 |
||
4385 |
||
4386 |
! |
|
4387 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4388 |
floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4389 |
"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
|
4390 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4391 |
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
|
4392 |
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
|
4393 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4394 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4395 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4396 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4397 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4398 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4399 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4400 |
e eD t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4401 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4402 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4403 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4404 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4405 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4406 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4407 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4408 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4409 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4410 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4411 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4412 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4413 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4414 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4415 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4416 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4417 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4418 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4419 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4420 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4421 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4422 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4423 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4424 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4425 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4426 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4427 |
"/ 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
|
4428 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4429 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4430 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4431 |
greyValues := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4432 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4433 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4434 |
v rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4435 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4436 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4437 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4438 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4439 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4440 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4441 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4442 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4443 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4444 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4445 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4446 |
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
|
4447 |
%{ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4448 |
int __grey, __e; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4449 |
int __byte = __intVal(byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4450 |
OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4451 |
OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4452 |
int __x = __intVal(x); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4453 |
int __eR, __eB, __eRB, __eLB, __eI; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4454 |
int __bitCnt = __intVal(bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4455 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4456 |
__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4457 |
__grey += __intVal(__errorArray[__x+1]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4458 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4459 |
__byte <<= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4460 |
if (__grey > 127*1024) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4461 |
__e = __grey - (255*1024); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4462 |
__byte |= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4463 |
} else { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4464 |
__e = __grey; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4465 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4466 |
if (__e) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4467 |
__eI = __e >> 4; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4468 |
__eR = __eI * 7; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4469 |
__eRB = __eI * 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4470 |
__eB = __eI * 5; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4471 |
__eLB = __e - __eR - __eRB - __eB; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4472 |
__errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4473 |
__nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4474 |
__nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4475 |
__nextErrorArray[__x ] = __MKSMALLINT(__intVal(__nextErrorArray[__x ]) + __eLB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4476 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4477 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4478 |
__bitCnt--; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4479 |
if (__bitCnt == 0) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4480 |
int __dstIndex = __intVal(dstIndex); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4481 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4482 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4483 |
dstIndex = __MKSMALLINT(__dstIndex + 1); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4484 |
__byte = 0; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4485 |
__bitCnt = 8; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4486 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4487 |
byte = __MKSMALLINT(__byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4488 |
bitCnt = __MKSMALLINT(__bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4489 |
%}. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4490 |
|
829 | 4491 |
"/ |eI "{ Class: SmallInteger }" |
4492 |
"/ xE "{ Class: SmallInteger }" |
|
4493 |
"/ xN "{ Class: SmallInteger }" | |
|
4494 |
"/ |
|
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4495 |
"/ "/ get the colors grey value [0 .. 1] |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4496 |
"/ grey := greyValues at:(pixel + 1). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4497 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4498 |
"/ "/ adjust error |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4499 |
"/ xE := x + 2. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4500 |
"/ grey := (grey + (errorArray at:xE)). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4501 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4502 |
"/ byte := byte bitShift:1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4503 |
"/ grey > (127*1024) ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4504 |
"/ byte := byte bitOr:1. "/ white |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4505 |
"/ e := grey - (255*1024) |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4506 |
"/ ] ifFalse:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4507 |
"/ e := grey "/ black |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4508 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4509 |
"/ e ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4510 |
"/ eD := e. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4511 |
"/ eI := e // 16. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4512 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4513 |
"/ eR := eI * 7. "/ 7/16 to right |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4514 |
"/ eRB := eI * 1. "/ 1/16 to right below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4515 |
"/ eB := eI * 5. "/ 5/16 to below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4516 |
"/ eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4517 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4518 |
"/ xN := xE + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4519 |
"/ eR ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4520 |
"/ errorArray at:xN put:(errorArray at:xN) + eR. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4521 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4522 |
"/ eRB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4523 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4524 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4525 |
"/ eB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4526 |
"/ nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4527 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4528 |
"/ eLB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4529 |
"/ xN := xE - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4530 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4531 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4532 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4533 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4534 |
"/ bitCnt := bitCnt - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4535 |
"/ bitCnt == 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4536 |
"/ monoBits at:dstIndex put:byte. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4537 |
"/ dstIndex := dstIndex + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4538 |
"/ byte := 0. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4539 |
"/ bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4540 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4541 |
0 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4542 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4543 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4544 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4545 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4546 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4547 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4548 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4549 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4550 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4551 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4552 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4553 |
'IMAGE: slow floydSteinberg dither ..' infoPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4554 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4555 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4556 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4557 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4558 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4559 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4560 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4561 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4562 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4563 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4564 |
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
|
4565 |
|eI "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4566 |
xE "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4567 |
xN "{ Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4568 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4569 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4570 |
grey := (clr brightness * 255). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4571 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4572 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4573 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4574 |
grey := (grey + (errorArray at:xE)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4575 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4576 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4577 |
grey > 127 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4578 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4579 |
e := grey - 255 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4580 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4581 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4582 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4583 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4584 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4585 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4586 |
eI := e // 16. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4587 |
eR := eI * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4588 |
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
|
4589 |
eB := eI * 5. "/ 5/16 to below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4590 |
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
|
4591 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4592 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4593 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4594 |
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
|
4595 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4596 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4597 |
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
|
4598 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4599 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4600 |
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
|
4601 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4602 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4603 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4604 |
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
|
4605 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4606 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4607 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4608 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4609 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4610 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4611 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4612 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4613 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4614 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4615 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4616 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4617 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4618 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4619 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4620 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4621 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4622 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4623 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4624 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4625 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4626 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4627 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4628 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4629 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4630 |
"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
|
4631 |
"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
|
4632 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4633 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4634 |
orderedDitheredBitsDepth:depth |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4635 |
"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
|
4636 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4637 |
^ self |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4638 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4639 |
ditherWidth:8 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4640 |
depth:depth. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4641 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4642 |
"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
|
4643 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4644 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4645 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4646 |
"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
|
4647 |
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
|
4648 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4649 |
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
|
4650 |
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
|
4651 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4652 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4653 |
greyLevels greyValues greyPixels greyErrors |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4654 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4655 |
nextDst |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4656 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4657 |
pixelsPerByte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4658 |
outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4659 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4660 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4661 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4662 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4663 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4664 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4665 |
'IMAGE: unimplemented orderedDither conversion' errorPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4666 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4667 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4668 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4669 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4670 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4671 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4672 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4673 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4674 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4675 |
greyLevels := 1 bitShift:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4676 |
pixelsPerByte := 8 / depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4677 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4678 |
bytesPerOutRow := (w * depth + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4679 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4680 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4681 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4682 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4683 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4684 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4685 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4686 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4687 |
"/ 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
|
4688 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4689 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4690 |
greyValues := self greyMapForRange:(greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4691 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4692 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4693 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4694 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4695 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4696 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4697 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4698 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4699 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4700 |
((v - v truncated) * nDither) rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4701 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4702 |
greyErrors := ByteArray withAll:greyErrors. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4703 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4704 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4705 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4706 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4707 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4708 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4709 |
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
|
4710 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4711 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4712 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4713 |
int __value = __intVal(value); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4714 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4715 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4716 |
int __pixel, __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4717 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4718 |
unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4719 |
unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4720 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4721 |
__pixel = __greyPixels[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4722 |
__grey = __greyErrors[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4723 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4724 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4725 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4726 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4727 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4728 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4729 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4730 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4731 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4732 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4733 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4734 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4735 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4736 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4737 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4738 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4739 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4740 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4741 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4742 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4743 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4744 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4745 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4746 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4747 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4748 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4749 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4750 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4751 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4752 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4753 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4754 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4755 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4756 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4757 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4758 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4759 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4760 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4761 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4762 |
"/ this is the representaion independent (but slow) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4763 |
"/ 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
|
4764 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4765 |
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
|
4766 |
|dstClr grey dT pixel| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4767 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4768 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4769 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4770 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4771 |
"/ remap into [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4772 |
grey := grey * (greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4773 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4774 |
"/ get threshold pixel [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4775 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4776 |
pixel := grey truncated. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4777 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4778 |
"/ compute the error [0..1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4779 |
grey := grey - pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4780 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4781 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4782 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4783 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4784 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4785 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4786 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4787 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4788 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4789 |
int __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4790 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4791 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4792 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4793 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4794 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4795 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4796 |
__pixel = __intVal(pixel); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4797 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4798 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4799 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4800 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4801 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4802 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4803 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4804 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4805 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4806 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4807 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4808 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4809 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4810 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4811 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4812 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4813 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4814 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4815 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4816 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4817 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4818 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4819 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4820 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4821 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4822 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4823 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4824 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4825 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4826 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4827 |
|
831 | 4828 |
orderedDitheredMonochromeBits |
4829 |
"return the bitmap for a dithered monochrome bitmap from the image; |
|
4830 |
using a default ditherMatrix." |
|
4831 |
||
4832 |
^ self |
|
4833 |
orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
4834 |
ditherWidth:8 |
|
4835 |
||
4836 |
"Created: 11.6.1996 / 16:48:57 / cg" |
|
4837 |
! |
|
4838 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4839 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4840 |
"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
|
4841 |
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
|
4842 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4843 |
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
|
4844 |
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
|
4845 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4846 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4847 |
greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4848 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4849 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4850 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4851 |
monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4852 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4853 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4854 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4855 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4856 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4857 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4858 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4859 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4860 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4861 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4862 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4863 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4864 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4865 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4866 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4867 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4868 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4869 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4870 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4871 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4872 |
"/ 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
|
4873 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4874 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4875 |
greyValues := self greyByteMapForRange:nDither. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4876 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4877 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4878 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4879 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4880 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4881 |
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
|
4882 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4883 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4884 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4885 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4886 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4887 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4888 |
int __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4889 |
unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4890 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4891 |
__grey = __greyValues[__intVal(value)]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4892 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4893 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4894 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4895 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4896 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4897 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4898 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4899 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4900 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4901 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4902 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4903 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4904 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4905 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4906 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4907 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4908 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4909 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4910 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4911 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4912 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4913 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4914 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4915 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4916 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4917 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4918 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4919 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4920 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4921 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4922 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4923 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4924 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4925 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4926 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4927 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4928 |
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
|
4929 |
|dstClr grey dT| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4930 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4931 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4932 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4933 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4934 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4935 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4936 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4937 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4938 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4939 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4940 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4941 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4942 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4943 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4944 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4945 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4946 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4947 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4948 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4949 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4950 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4951 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4952 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4953 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4954 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4955 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4956 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4957 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4958 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4959 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4960 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4961 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4962 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4963 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4964 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4965 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4966 |
"/ 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
|
4967 |
"/ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4968 |
"/ byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4969 |
"/ grey < dT ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4970 |
"/ byte := byte bitOr:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4971 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4972 |
"/ bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4973 |
"/ bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4974 |
"/ monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4975 |
"/ dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4976 |
"/ byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4977 |
"/ bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4978 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4979 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4980 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4981 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4982 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4983 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4984 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4985 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4986 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4987 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4988 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4989 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4990 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4991 |
stevensonArceDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4992 |
"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
|
4993 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4994 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4995 |
|f last |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4996 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4997 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4998 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4999 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5000 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5001 |
errorArray1 errorArray2 errorArray3 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5002 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5003 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5004 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5005 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5006 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5007 |
direction "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5008 |
dstClr grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5009 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5010 |
xN "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5011 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5012 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5013 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5014 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5015 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5016 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5017 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5018 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5019 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5020 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5021 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5022 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5023 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5024 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5025 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5026 |
errorArray := Array new:(w+6). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5027 |
errorArray1 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5028 |
errorArray2 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5029 |
errorArray3 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5030 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5031 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5032 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5033 |
"/ 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
|
5034 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5035 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5036 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5037 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5038 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5039 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5040 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5041 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5042 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5043 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5044 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5045 |
errorArray1 := errorArray2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5046 |
errorArray2 := errorArray3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5047 |
errorArray3 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5048 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5049 |
errorArray3 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5050 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5051 |
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
|
5052 |
|eP eD| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5053 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5054 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5055 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5056 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5057 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5058 |
xE := x + 3 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5059 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5060 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5061 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5062 |
grey > (127 * 1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5063 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5064 |
e := grey - (255 * 1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5065 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5066 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5067 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5068 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5069 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5070 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5071 |
"/ XX 32 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5072 |
"/ 12 26 30 16 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5073 |
"/ 12 26 12 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5074 |
"/ 5 12 12 5 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5075 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5076 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5077 |
e := e // 200. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5078 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5079 |
eP := e * 32. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5080 |
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
|
5081 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5082 |
eP := e * 30. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5083 |
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
|
5084 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5085 |
eP := e * 16. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5086 |
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
|
5087 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5088 |
eP := e * 26. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5089 |
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
|
5090 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5091 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5092 |
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
|
5093 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5094 |
eP := e * 12. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5095 |
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
|
5096 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5097 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5098 |
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
|
5099 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5100 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5101 |
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
|
5102 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5103 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5104 |
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
|
5105 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5106 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5107 |
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
|
5108 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5109 |
eP := e * 5. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5110 |
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
|
5111 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5112 |
eP := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5113 |
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
|
5114 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5115 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5116 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5117 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5118 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5119 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5120 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5121 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5122 |
]. |
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 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5125 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5126 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5127 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5128 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5129 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5130 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5131 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5132 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5133 |
^ monoBits |
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 |
"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
|
5136 |
"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
|
5137 |
! ! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5138 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5139 |
!Image methodsFor:'drawing'! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5140 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5141 |
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
|
5142 |
|pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5143 |
xI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5144 |
yI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5145 |
wI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5146 |
hI "{ Class: SmallInteger }"| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5147 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5148 |
pixel := self valueFromColor:aColor. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5149 |
xI := x. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5150 |
yI := y. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5151 |
wI := w. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5152 |
hI := h. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5153 |
yI to:yI+hI-1 do:[:yRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5154 |
xI to:xI+wI-1 do:[:xRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5155 |
self atX:xRun y:yRun putValue:pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5156 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5157 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5158 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5159 |
"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
|
5160 |
"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
|
5161 |
! ! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5162 |
|
283 | 5163 |
!Image methodsFor:'enumerating'! |
5164 |
||
5165 |
atY:y from:x1 to:x2 do:aBlock |
|
5166 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5167 |
The block is passed the color at each pixel. |
|
5168 |
The code here provides a generic and slow implementation, and |
|
5169 |
should be redefined in concrete subclasses, to avoid some processing |
|
5170 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5171 |
and also the color allocation)." |
|
5172 |
||
798 | 5173 |
self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'. |
5174 |
self colorsAtY:y from:x1 to:x2 do:aBlock |
|
5175 |
||
5176 |
"Modified: 7.6.1996 / 19:13:30 / cg" |
|
5177 |
! |
|
5178 |
||
5179 |
colorsAtY:y from:x1 to:x2 do:aBlock |
|
5180 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5181 |
The block is passed the color at each pixel. |
|
5182 |
The code here provides a generic and slow implementation, and |
|
5183 |
should be redefined in concrete subclasses, to avoid some processing |
|
5184 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5185 |
and also the color allocation)." |
|
5186 |
||
283 | 5187 |
|xStart "{Class: SmallInteger }" |
5188 |
xEnd "{Class: SmallInteger }"| |
|
5189 |
||
5190 |
xStart := x1. |
|
5191 |
xEnd := x2. |
|
5192 |
xStart to:xEnd do:[:xRun | |
|
798 | 5193 |
aBlock value:xRun value:(self atX:xRun y:y) |
283 | 5194 |
] |
798 | 5195 |
|
5196 |
"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
|
5197 |
"Modified: 10.6.1996 / 10:27:29 / cg" |
283 | 5198 |
! |
5199 |
||
5200 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5201 |
"perform aBlock for each color in a rectangular area of the image. |
|
5202 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5203 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5204 |
The code here provides a generic and slow implementation, and |
|
5205 |
should be redefined in concrete subclasses, to avoid some processing |
|
5206 |
when going from pixel to pixel (i.e. the byte-index and mask computations, |
|
5207 |
and especially, the color allocations)." |
|
5208 |
||
5209 |
|xS "{Class: SmallInteger }" |
|
5210 |
xE "{Class: SmallInteger }"| |
|
5211 |
||
5212 |
xS := xStart. |
|
5213 |
xE := xEnd. |
|
5214 |
yStart to:yEnd do:[:yRun | |
|
798 | 5215 |
self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color | |
5216 |
aBlock value:xRun value:yRun value:color |
|
5217 |
] |
|
283 | 5218 |
] |
798 | 5219 |
|
5220 |
"Modified: 7.6.1996 / 19:11:39 / cg" |
|
283 | 5221 |
! |
5222 |
||
5223 |
valueAtY:y from:x1 to:x2 do:aBlock |
|
5224 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
798 | 5225 |
Obsolete - remains for backward compatibility." |
5226 |
||
5227 |
self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'. |
|
5228 |
self valuesAtY:y from:x1 to:x2 do:aBlock |
|
5229 |
||
5230 |
"Modified: 7.6.1996 / 19:11:06 / cg" |
|
5231 |
! |
|
5232 |
||
5233 |
valuesAtY:y from:x1 to:x2 do:aBlock |
|
5234 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
283 | 5235 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
5236 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
5237 |
(see also Image>>atY:from:to:do:). |
|
5238 |
The code here provides a generic and slow implementation, and |
|
5239 |
should be redefined in concrete subclasses, to avoid some processing |
|
5240 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
5241 |
||
5242 |
|xStart "{Class: SmallInteger }" |
|
5243 |
xEnd "{Class: SmallInteger }"| |
|
5244 |
||
5245 |
xStart := x1. |
|
5246 |
xEnd := x2. |
|
5247 |
xStart to:xEnd do:[:xRun | |
|
692 | 5248 |
aBlock value:xRun value:(self valueAtX:xRun y:y) |
283 | 5249 |
] |
692 | 5250 |
|
5251 |
"Modified: 17.5.1996 / 12:03:59 / cg" |
|
798 | 5252 |
"Created: 7.6.1996 / 19:09:51 / cg" |
283 | 5253 |
! |
5254 |
||
5255 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5256 |
"perform aBlock for each pixelValue in a rectangular area of the image. |
|
5257 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5258 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5259 |
The code here provides a generic and slow implementation, and |
|
5260 |
should be redefined in concrete subclasses, to avoid some processing |
|
5261 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
5262 |
||
5263 |
|xS "{Class: SmallInteger }" |
|
5264 |
xE "{Class: SmallInteger }"| |
|
5265 |
||
5266 |
xS := xStart. |
|
5267 |
xE := xEnd. |
|
5268 |
yStart to:yEnd do:[:yRun | |
|
798 | 5269 |
self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel | |
5270 |
aBlock value:xRun value:yRun value:pixel |
|
5271 |
] |
|
283 | 5272 |
] |
798 | 5273 |
|
5274 |
"Modified: 7.6.1996 / 19:09:29 / cg" |
|
0 | 5275 |
! ! |
5276 |
||
5277 |
!Image methodsFor:'image manipulations'! |
|
5278 |
||
283 | 5279 |
colorMapProcessing:aBlock |
5280 |
"a helper for all kinds of colormap manipulations. |
|
592 | 5281 |
The argument, aBlock is called for every colormap entry, |
5282 |
and the returned value will replace the original entry in the map. |
|
283 | 5283 |
This will fail for non-palette images. |
592 | 5284 |
See examples in Image>>copyWithColorMapProcessing:" |
283 | 5285 |
|
5286 |
|nColors "{ Class: SmallInteger }"| |
|
5287 |
||
5288 |
colorMap isNil ifTrue:[ |
|
592 | 5289 |
^ self error:'image has no colormap' |
283 | 5290 |
]. |
5291 |
||
5292 |
nColors := colorMap size. |
|
5293 |
1 to:nColors do:[:index | |
|
592 | 5294 |
|clr| |
5295 |
||
5296 |
clr := colorMap at:index. |
|
5297 |
clr notNil ifTrue:[ |
|
5298 |
colorMap at:index put:(aBlock value:clr) |
|
5299 |
] |
|
283 | 5300 |
] |
592 | 5301 |
|
5302 |
"Modified: 23.4.1996 / 11:13:55 / cg" |
|
283 | 5303 |
! |
5304 |
||
89 | 5305 |
copyWithColorMapProcessing:aBlock |
81 | 5306 |
"a helper to create & return new images based on the receiver with |
89 | 5307 |
some colorMap processing. The receiver is copied, and the copied images |
5308 |
colormap is modified by replacing entries with the result of the processing block, |
|
5309 |
which is called with the original color values. The block is supposed to return |
|
5310 |
a color." |
|
81 | 5311 |
|
5312 |
|newImage| |
|
5313 |
||
5314 |
newImage := self copy. |
|
5315 |
newImage colorMap isNil ifTrue:[ |
|
5316 |
self error:'no colormap in image'. |
|
5317 |
^ nil |
|
5318 |
]. |
|
5319 |
||
5320 |
" |
|
5321 |
the code below manipulates the colormap. |
|
5322 |
For non-palette images, special code is required |
|
5323 |
" |
|
89 | 5324 |
newImage colorMapProcessing:aBlock. |
81 | 5325 |
^ newImage |
5326 |
||
5327 |
" |
|
5328 |
leave red component only: |
|
5329 |
||
5330 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5331 |
copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] |
81 | 5332 |
" |
89 | 5333 |
|
81 | 5334 |
" |
5335 |
make it reddish: |
|
5336 |
||
5337 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5338 |
copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] |
81 | 5339 |
" |
89 | 5340 |
|
81 | 5341 |
" |
5342 |
invert: |
|
5343 |
||
5344 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5345 |
copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] |
81 | 5346 |
" |
89 | 5347 |
|
81 | 5348 |
" |
5349 |
lighter: |
|
5350 |
||
5351 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5352 |
copyWithColorMapProcessing:[:clr | |r g b| |
5353 |
r := clr red. g := clr green. b := clr blue. |
|
5354 |
Color red:(r + (100-r//2)) |
|
5355 |
green:(g + (100-g//2)) |
|
5356 |
blue:(b + (100-b//2))] |
|
81 | 5357 |
" |
89 | 5358 |
|
81 | 5359 |
" |
5360 |
darker: |
|
5361 |
||
5362 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5363 |
copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] |
81 | 5364 |
" |
5365 |
! |
|
5366 |
||
283 | 5367 |
darkened |
5368 |
"return a new image which is slightly darker than the receiver. |
|
5369 |
The receiver must be a palette image (currently). |
|
592 | 5370 |
CAVEAT: Need an argument, which specifies by how much it should be darker." |
283 | 5371 |
|
5372 |
^ self |
|
592 | 5373 |
copyWithColorMapProcessing:[:clr | |
5374 |
Color red:(clr red // 2) |
|
5375 |
green:(clr green // 2) |
|
5376 |
blue:(clr blue // 2)] |
|
283 | 5377 |
|
5378 |
" |
|
5379 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
5380 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
5381 |
" |
|
592 | 5382 |
|
5383 |
"Modified: 23.4.1996 / 11:14:34 / cg" |
|
283 | 5384 |
! |
5385 |
||
5386 |
flipHorizontal |
|
5387 |
"inplace horizontal flip" |
|
5388 |
||
5389 |
|w "{Class: SmallInteger }" |
|
5390 |
h "{Class: SmallInteger }" |
|
5391 |
c2 "{Class: SmallInteger }" |
|
5392 |
value | |
|
5393 |
||
5394 |
w := width - 1. |
|
5395 |
h := height - 1. |
|
5396 |
||
5397 |
0 to:h do:[:row | |
|
5398 |
c2 := w. |
|
5399 |
0 to:(w // 2) do:[:col | |
|
5400 |
value := self valueAtX:col y:row. |
|
5401 |
self atX:col y:row putValue:(self valueAtX:c2 y:row). |
|
5402 |
self atX:c2 y:row putValue:value. |
|
5403 |
c2 := c2 - 1. |
|
5404 |
] |
|
81 | 5405 |
]. |
283 | 5406 |
"flush device info" |
5407 |
self restored |
|
5408 |
! |
|
5409 |
||
5410 |
flipVertical |
|
5411 |
"inplace vertical flip" |
|
5412 |
||
5413 |
|h "{Class: SmallInteger }" |
|
5414 |
bytesPerRow "{Class: SmallInteger }" |
|
5415 |
buffer |
|
5416 |
indexLow "{Class: SmallInteger }" |
|
5417 |
indexHi "{Class: SmallInteger }"| |
|
5418 |
||
5419 |
bytesPerRow := self bytesPerRow. |
|
5420 |
buffer := ByteArray new:bytesPerRow. |
|
5421 |
||
5422 |
h := height - 1. |
|
5423 |
||
5424 |
indexLow := 1. |
|
5425 |
indexHi := bytesPerRow * h + 1. |
|
5426 |
||
5427 |
0 to:(h // 2) do:[:row | |
|
5428 |
buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow. |
|
5429 |
bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi. |
|
5430 |
bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1. |
|
5431 |
indexLow := indexLow + bytesPerRow. |
|
5432 |
indexHi := indexHi - bytesPerRow. |
|
5433 |
]. |
|
5434 |
"flush device info" |
|
5435 |
self restored |
|
5436 |
! |
|
5437 |
||
5438 |
hardMagnifiedBy:scalePoint |
|
5439 |
"return a new image magnified by scalePoint, aPoint. |
|
5440 |
This is the general magnification method, handling non-integral values. |
|
5441 |
It is slower than the integral magnification method." |
|
5442 |
||
5443 |
|mX |
|
5444 |
mY |
|
5445 |
newWidth "{ Class: SmallInteger }" |
|
5446 |
newHeight "{ Class: SmallInteger }" |
|
5447 |
w "{ Class: SmallInteger }" |
|
5448 |
h "{ Class: SmallInteger }" |
|
5449 |
newImage newBits bitsPerPixel newBytesPerRow |
|
5450 |
value srcRow| |
|
5451 |
||
5452 |
mX := scalePoint x. |
|
5453 |
mY := scalePoint y. |
|
5454 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
5455 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
5456 |
||
5457 |
newWidth := (width * mX) truncated. |
|
5458 |
newHeight := (height * mY) truncated. |
|
5459 |
||
5460 |
bitsPerPixel := self depth. |
|
5461 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
5462 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
5463 |
||
5464 |
newImage := self species new. |
|
5465 |
newImage bits:newBits. |
|
5466 |
newImage width:newWidth. |
|
5467 |
newImage height:newHeight. |
|
5468 |
newImage photometric:photometric. |
|
5469 |
newImage samplesPerPixel:samplesPerPixel. |
|
5470 |
newImage bitsPerSample:bitsPerSample. |
|
5471 |
newImage colorMap:colorMap copy. |
|
5472 |
||
5473 |
"walk over destination image fetching pixels from source image" |
|
5474 |
||
5475 |
w := newWidth - 1. |
|
5476 |
h := newHeight - 1. |
|
5477 |
||
5478 |
0 to:h do:[:row | |
|
5479 |
srcRow := (row // mY). |
|
5480 |
0 to:w do:[:col | |
|
5481 |
value := self valueAtX:(col // mX) y:srcRow. |
|
5482 |
newImage atX:col y:row putValue:value. |
|
89 | 5483 |
] |
283 | 5484 |
]. |
5485 |
||
5486 |
^ newImage |
|
5487 |
||
5488 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
|
5489 |
! |
|
5490 |
||
5491 |
hardRotated:degrees |
|
592 | 5492 |
"raise an error - rotation by arbitrary angles is not yet implemented" |
5493 |
||
283 | 5494 |
self error:'not yet implemented' |
592 | 5495 |
|
5496 |
"Modified: 23.4.1996 / 11:15:33 / cg" |
|
81 | 5497 |
! |
5498 |
||
54 | 5499 |
lightened |
89 | 5500 |
"return a new image which is slightly brighter than the receiver. |
5501 |
The receiver must be a palette image (currently). |
|
592 | 5502 |
CAVEAT: Need an argument, which specifies by how much it should be lighter." |
54 | 5503 |
|
81 | 5504 |
^ self |
592 | 5505 |
copyWithColorMapProcessing:[:clr | |r g b| |
5506 |
r := clr red. |
|
5507 |
g := clr green. |
|
5508 |
b := clr blue. |
|
5509 |
Color red:(r + (100-r//2)) |
|
5510 |
green:(g + (100-g//2)) |
|
5511 |
blue:(b + (100-b//2))] |
|
81 | 5512 |
|
5513 |
" |
|
5514 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
5515 |
(Image fromFile:'bitmaps/claus.gif') lightened inspect |
|
5516 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
5517 |
(Image fromFile:'bitmaps/claus.gif') darkened darkened inspect |
|
5518 |
" |
|
592 | 5519 |
|
5520 |
"Modified: 23.4.1996 / 11:14:41 / cg" |
|
54 | 5521 |
! |
5522 |
||
134 | 5523 |
magnifiedBy:scale |
81 | 5524 |
"return a new image magnified by scalePoint, aPoint. |
72 | 5525 |
If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:' |
5526 |
while simple (integral) magnifications are handled here." |
|
0 | 5527 |
|
81 | 5528 |
|scalePoint mX mY |
46 | 5529 |
magX "{ Class: SmallInteger }" "new version of stc can find this out itself..." |
5530 |
magY "{ Class: SmallInteger }" |
|
5531 |
srcOffset "{ Class: SmallInteger }" |
|
5532 |
dstOffset "{ Class: SmallInteger }" |
|
5533 |
w "{ Class: SmallInteger }" |
|
5534 |
h "{ Class: SmallInteger }" |
|
5535 |
first |
|
81 | 5536 |
newWidth newHeight newImage newBits |
5537 |
bitsPerPixel newBytesPerRow oldBytesPerRow| |
|
0 | 5538 |
|
81 | 5539 |
scalePoint := scale asPoint. |
5540 |
mX := scalePoint asPoint x. |
|
5541 |
mY := scalePoint asPoint y. |
|
46 | 5542 |
((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil]. |
0 | 5543 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
5544 |
||
12 | 5545 |
((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[ |
134 | 5546 |
^ self hardMagnifiedBy:scalePoint |
0 | 5547 |
]. |
5548 |
||
2 | 5549 |
bitsPerPixel := self depth. |
0 | 5550 |
oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8. |
5551 |
||
46 | 5552 |
w := width. |
5553 |
h := height. |
|
5554 |
magX := mX. |
|
5555 |
magY := mY. |
|
5556 |
||
5557 |
newWidth := w * mX. |
|
5558 |
newHeight := h * mY. |
|
0 | 5559 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
5560 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
5561 |
||
5562 |
newImage := self species new. |
|
2 | 5563 |
newImage bits:newBits. |
0 | 5564 |
newImage width:newWidth. |
5565 |
newImage height:newHeight. |
|
5566 |
newImage photometric:photometric. |
|
5567 |
newImage samplesPerPixel:samplesPerPixel. |
|
5568 |
newImage bitsPerSample:bitsPerSample. |
|
5569 |
newImage colorMap:colorMap copy. |
|
5570 |
||
5571 |
mX = 1 ifTrue:[ |
|
72 | 5572 |
"expand rows only" |
5573 |
srcOffset := 1. |
|
5574 |
dstOffset := 1. |
|
0 | 5575 |
|
72 | 5576 |
1 to:h do:[:row | |
5577 |
1 to:mY do:[:i | |
|
5578 |
newBits replaceFrom:dstOffset |
|
5579 |
to:(dstOffset + oldBytesPerRow - 1) |
|
5580 |
with:bytes |
|
5581 |
startingAt:srcOffset. |
|
5582 |
dstOffset := dstOffset + newBytesPerRow |
|
5583 |
]. |
|
5584 |
srcOffset := srcOffset + oldBytesPerRow. |
|
5585 |
]. |
|
0 | 5586 |
] ifFalse:[ |
72 | 5587 |
"expand cols" |
5588 |
(mX > 1) ifTrue:[ |
|
5589 |
dstOffset := 1. |
|
5590 |
srcOffset := 1. |
|
5591 |
1 to:h do:[:row | |
|
5592 |
self magnifyRowFrom:bytes |
|
5593 |
offset:srcOffset |
|
5594 |
into:newBits |
|
5595 |
offset:dstOffset |
|
5596 |
factor:mX. |
|
0 | 5597 |
|
72 | 5598 |
first := dstOffset. |
5599 |
dstOffset := dstOffset + newBytesPerRow. |
|
5600 |
" and copy for row expansion " |
|
5601 |
2 to:mY do:[:i | |
|
5602 |
newBits replaceFrom:dstOffset |
|
5603 |
to:(dstOffset + newBytesPerRow - 1) |
|
5604 |
with:newBits |
|
5605 |
startingAt:first. |
|
5606 |
dstOffset := dstOffset + newBytesPerRow |
|
5607 |
]. |
|
5608 |
srcOffset := srcOffset + oldBytesPerRow. |
|
5609 |
]. |
|
5610 |
] |
|
0 | 5611 |
]. |
5612 |
^ newImage |
|
5613 |
||
134 | 5614 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)" |
2 | 5615 |
! |
5616 |
||
154 | 5617 |
magnifiedPreservingRatioTo:anExtent |
5618 |
"return a new image magnified to fit into anExtent, |
|
5619 |
preserving the receivers width/height ratio. |
|
5620 |
(i.e. not distorting the image). |
|
5621 |
See also #magnifiedTo: and #magnifiedBy:" |
|
5622 |
||
5623 |
|rX rY| |
|
5624 |
||
5625 |
rX := anExtent x / self width. |
|
5626 |
rY := anExtent y / self height. |
|
5627 |
^ self magnifiedBy:(rX min:rY) |
|
5628 |
||
5629 |
" |
|
5630 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
5631 |
||
5632 |
in contrast to: |
|
5633 |
||
5634 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
|
5635 |
" |
|
5636 |
! |
|
5637 |
||
134 | 5638 |
magnifiedTo:anExtent |
154 | 5639 |
"return a new image magnified to have the size specified by extent. |
5640 |
This may distort the image if the arguments ratio is not the images ratio. |
|
5641 |
See also #magnifiedPreservingRatioTo: and #magnifiedBy:" |
|
89 | 5642 |
|
134 | 5643 |
^ self magnifiedBy:(anExtent / self extent) |
89 | 5644 |
|
5645 |
" |
|
134 | 5646 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
154 | 5647 |
|
5648 |
in contrast to: |
|
5649 |
||
5650 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
89 | 5651 |
" |
5652 |
! |
|
5653 |
||
12 | 5654 |
rotated:degrees |
5655 |
"return a new image from the old one, by rotating the image |
|
46 | 5656 |
degrees clockwise. |
592 | 5657 |
CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented." |
12 | 5658 |
|
46 | 5659 |
|w "{Class: SmallInteger }" |
5660 |
h "{Class: SmallInteger }" |
|
12 | 5661 |
c2 "{Class: SmallInteger }" |
692 | 5662 |
r2 "{Class: SmallInteger }" |
5663 |
nW "{Class: SmallInteger }" |
|
5664 |
nH "{Class: SmallInteger }" |
|
24 | 5665 |
newImage newBits newBytesPerRow d| |
12 | 5666 |
|
5667 |
d := degrees. |
|
5668 |
[d < 0] whileTrue:[d := d + 360]. |
|
5669 |
d >= 360 ifTrue:[d := d \\ 360]. |
|
46 | 5670 |
d := d truncated. |
5671 |
d == 0 ifTrue:[^ self]. |
|
5672 |
((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[ |
|
592 | 5673 |
^ self hardRotated:d |
12 | 5674 |
]. |
5675 |
||
692 | 5676 |
d == 180 ifTrue:[ |
5677 |
nW := width. |
|
5678 |
nH := height. |
|
5679 |
] ifFalse:[ |
|
5680 |
nW := height. |
|
5681 |
nH := width. |
|
5682 |
]. |
|
5683 |
||
5684 |
newBytesPerRow := ((nW * self depth) + 7) // 8. |
|
5685 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * nH). |
|
12 | 5686 |
|
5687 |
newImage := self species new. |
|
5688 |
newImage bits:newBits. |
|
692 | 5689 |
newImage width:nW. |
5690 |
newImage height:nH. |
|
12 | 5691 |
newImage photometric:photometric. |
5692 |
newImage samplesPerPixel:samplesPerPixel. |
|
5693 |
newImage bitsPerSample:bitsPerSample. |
|
5694 |
newImage colorMap:colorMap copy. |
|
5695 |
||
5696 |
w := width - 1. |
|
5697 |
h := height - 1. |
|
5698 |
||
5699 |
d == 90 ifTrue:[ |
|
592 | 5700 |
0 to:h do:[:row | |
5701 |
c2 := h-row. |
|
798 | 5702 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 5703 |
newImage atX:c2 y:col putValue:pixel. |
592 | 5704 |
] |
692 | 5705 |
"/ 0 to:w do:[:col | |
5706 |
"/ newImage atX:c2 y:col putValue:(self valueAtX:col y:row). |
|
5707 |
"/ ] |
|
592 | 5708 |
] |
12 | 5709 |
]. |
46 | 5710 |
d == 180 ifTrue:[ |
592 | 5711 |
0 to:h do:[:row | |
692 | 5712 |
r2 := h - row. |
798 | 5713 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 5714 |
newImage atX:(w-col) y:r2 putValue:pixel. |
592 | 5715 |
] |
692 | 5716 |
"/ 0 to:w do:[:col | |
5717 |
"/ newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row). |
|
5718 |
"/ ] |
|
592 | 5719 |
] |
46 | 5720 |
]. |
12 | 5721 |
d == 270 ifTrue:[ |
592 | 5722 |
0 to:h do:[:row | |
798 | 5723 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 5724 |
newImage atX:row y:(w-col) putValue:pixel. |
592 | 5725 |
] |
692 | 5726 |
"/ 0 to:w do:[:col | |
5727 |
"/ newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row). |
|
5728 |
"/ ] |
|
592 | 5729 |
] |
12 | 5730 |
]. |
5731 |
^ newImage |
|
592 | 5732 |
|
692 | 5733 |
" |
5734 |
|i| |
|
5735 |
||
5736 |
i := Image fromFile:'claus.gif'. |
|
5737 |
i inspect. |
|
5738 |
(i rotated:90) inspect. |
|
5739 |
(i rotated:180) inspect. |
|
5740 |
(i rotated:270) inspect. |
|
5741 |
" |
|
5742 |
||
798 | 5743 |
"Modified: 7.6.1996 / 19:09:22 / cg" |
692 | 5744 |
! |
5745 |
||
5746 |
withPixelFunctionApplied:pixelFunctionBlock |
|
5747 |
"return a new image from the old one, by applying a pixel processor |
|
5748 |
(read `Behond photography, by Gerard J. Holzmann; |
|
5749 |
ISBM 0-13-074410-7) |
|
5750 |
See blurred / oilPointed as examples ...)" |
|
5751 |
||
5752 |
|w "{Class: SmallInteger }" |
|
5753 |
h "{Class: SmallInteger }" |
|
5754 |
newImage newBits newBytesPerRow d| |
|
5755 |
||
5756 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
5757 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
5758 |
||
5759 |
newImage := self species new. |
|
5760 |
newImage bits:newBits. |
|
5761 |
newImage width:width. |
|
5762 |
newImage height:height. |
|
5763 |
newImage photometric:photometric. |
|
5764 |
newImage samplesPerPixel:samplesPerPixel. |
|
5765 |
newImage bitsPerSample:bitsPerSample. |
|
5766 |
newImage colorMap:colorMap copy. |
|
5767 |
||
5768 |
w := width - 1. |
|
5769 |
h := height - 1. |
|
5770 |
||
5771 |
0 to:h do:[:y | |
|
5772 |
0 to:w do:[:x | |
|
5773 |
newImage atX:x y:y put:(pixelFunctionBlock |
|
5774 |
value:self |
|
5775 |
value:x |
|
5776 |
value:y) |
|
5777 |
] |
|
5778 |
]. |
|
5779 |
^ newImage |
|
5780 |
||
5781 |
" |
|
5782 |
|i| |
|
5783 |
||
5784 |
i := Image fromFile:'claus.gif'. |
|
5785 |
i inspect. |
|
5786 |
(i withPixelFunctionApplied:[:oldImage :x :y | |
|
5787 |
((x between:100 and:200) |
|
5788 |
and:[y between:100 and:200]) ifTrue:[ |
|
5789 |
oldImage atX:x y:y |
|
5790 |
] ifFalse:[ |
|
5791 |
Color black. |
|
5792 |
] |
|
5793 |
]) inspect. |
|
5794 |
" |
|
5795 |
||
5796 |
"Modified: 17.5.1996 / 12:31:44 / cg" |
|
283 | 5797 |
! ! |
5798 |
||
5799 |
!Image methodsFor:'inspecting'! |
|
5800 |
||
5801 |
inspectorClass |
|
5802 |
"redefined to launch an ImageInspector |
|
5803 |
(instead of the default InspectorView)." |
|
5804 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5805 |
(width notNil and:[height notNil]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5806 |
^ ImageInspectorView |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5807 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5808 |
^ super inspectorClass |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5809 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
5810 |
"Modified: 10.6.1996 / 18:23:55 / cg" |
283 | 5811 |
! ! |
5812 |
||
5813 |
!Image methodsFor:'instance release'! |
|
5814 |
||
5815 |
disposed |
|
5816 |
"some Image has been collected - nothing to do" |
|
12 | 5817 |
! |
5818 |
||
283 | 5819 |
release |
5820 |
"release device resources" |
|
5821 |
||
5822 |
device := nil. |
|
5823 |
deviceForm := nil. |
|
5824 |
monoDeviceForm := nil. |
|
5825 |
fullColorDeviceForm := nil. |
|
5826 |
Lobby unregister:self |
|
46 | 5827 |
! |
5828 |
||
283 | 5829 |
restored |
5830 |
"flush device specifics after a snapin or binary restore" |
|
5831 |
||
5832 |
self release |
|
5833 |
! ! |
|
5834 |
||
592 | 5835 |
!Image methodsFor:'obsolete'! |
5836 |
||
5837 |
magnifyBy:scale |
|
5838 |
"obsolete: has been renamed to magnifiedBy: for ST-80 compatibility |
|
5839 |
and name consistency ..." |
|
5840 |
||
5841 |
self obsoleteMethodWarning. |
|
5842 |
^ self magnifiedBy:scale |
|
5843 |
! ! |
|
5844 |
||
283 | 5845 |
!Image methodsFor:'pixel copying'! |
5846 |
||
5847 |
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
5848 |
"replace a rectangulat area by pixels from another image. |
|
5849 |
WARNING: |
|
5850 |
This implementation is a slow fallback (the loop over the |
|
5851 |
source pixels is very slow). If this method is used heavily, you |
|
5852 |
may want to redefine it in concrete subclasses for the common case of |
|
5853 |
of copying from an Image with the same depth & palette." |
|
5854 |
||
5855 |
|dX dY| |
|
5856 |
||
5857 |
dX := srcX-dstX. |
|
5858 |
dY := srcY-dstY. |
|
5859 |
((photometric == anImage photometric) |
|
5860 |
and:[self bitsPerPixel == anImage bitsPerPixel |
|
5861 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
|
5862 |
"/ can loop over values |
|
5863 |
anImage valuesFromX:srcX y:srcY |
|
5864 |
toX:srcX+w-1 y:srcY+h-1 |
|
5865 |
do:[:x :y :pixelValue | |
|
5866 |
self atX:x-dX y:y-dY putValue:pixelValue. |
|
5867 |
] |
|
5868 |
] ifFalse:[ |
|
5869 |
"/ must loop over colors |
|
5870 |
anImage colorsFromX:srcX y:srcY |
|
5871 |
toX:srcX+w-1 y:srcY+h-1 |
|
5872 |
do:[:x :y :clr | |
|
5873 |
self atX:x-dX y:y-dY put:clr. |
|
5874 |
] |
|
5875 |
] |
|
5876 |
||
5877 |
" |
|
5878 |
|i1 i8 i4| |
|
5879 |
||
5880 |
i8 := Image fromFile:'bitmaps/garfield.gif'. |
|
5881 |
i8 inspect. |
|
5882 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
5883 |
i1 inspect. |
|
5884 |
||
5885 |
i4 := Depth4Image fromImage:i8. |
|
5886 |
i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30. |
|
5887 |
i4 inspect. |
|
5888 |
" |
|
5889 |
||
5890 |
"Created: 20.9.1995 / 10:14:01 / claus" |
|
5891 |
"Modified: 20.9.1995 / 10:25:31 / claus" |
|
5892 |
! |
|
5893 |
||
5894 |
subImageIn:aRectangle |
|
5895 |
"create and return a new image consisting of a subArea of myself" |
|
5896 |
||
5897 |
^ self class fromSubImage:self in:aRectangle |
|
5898 |
||
5899 |
" |
|
5900 |
|i| |
|
5901 |
||
5902 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
5903 |
i inspect. |
|
5904 |
(i subImageIn:(300@160 corner:340@200)) inspect |
|
5905 |
" |
|
5906 |
||
5907 |
"Created: 20.9.1995 / 01:24:20 / claus" |
|
5908 |
! ! |
|
5909 |
||
5910 |
!Image methodsFor:'printing & storing'! |
|
5911 |
||
5912 |
storeOn:aStream |
|
592 | 5913 |
"append a printed representation of the receiver to aStream, |
5914 |
from which a copy of it can be reconstructed." |
|
5915 |
||
283 | 5916 |
aStream nextPutAll:'(' , self class name , ' new)'. |
5917 |
aStream nextPutAll:' width: '. width storeOn:aStream. |
|
5918 |
aStream nextPutAll:'; height: '. height storeOn:aStream. |
|
5919 |
aStream nextPutAll:'; photometric:('. photometric storeOn:aStream. |
|
5920 |
aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream. |
|
5921 |
aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. |
|
5922 |
aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '. |
|
5923 |
colorMap notNil ifTrue:[ |
|
592 | 5924 |
aStream nextPutAll:'; colorMap:('. |
5925 |
colorMap storeOn:aStream. |
|
5926 |
aStream nextPutAll:')'. |
|
283 | 5927 |
]. |
5928 |
aStream nextPutAll:'; yourself' |
|
592 | 5929 |
|
5930 |
"Modified: 23.4.1996 / 11:18:05 / cg" |
|
0 | 5931 |
! ! |
5932 |
||
5933 |
!Image methodsFor:'private'! |
|
5934 |
||
193 | 5935 |
bestSupportedImageFormatFor:aDevice |
5936 |
"scan through the image formats as supported by aDevice, |
|
5937 |
and return the best to use when the receiver is to be represented |
|
5938 |
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
|
5939 |
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
|
5940 |
|
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
5941 |
|bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel | |
193 | 5942 |
|
5943 |
myDepth := self bitsPerPixel. |
|
5944 |
maxBitsPerPixel := 0. |
|
5945 |
||
5946 |
aDevice supportedImageFormats do:[:entry | |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5947 |
|deviceImageDepth deviceImageBitsPerPixel| |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5948 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5949 |
deviceImageDepth := entry at:#depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5950 |
deviceImageBitsPerPixel := entry at:#bitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5951 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5952 |
deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5953 |
maxInfo := entry. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
5954 |
"/ maxBitsPerPixel := deviceImageBitsPerPixel. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
5955 |
"/ maxDepth := deviceImageDepth. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5956 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5957 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5958 |
deviceImageDepth >= myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5959 |
deviceImageDepth == myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5960 |
"/ take the better one ... |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5961 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5962 |
or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth) |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5963 |
and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5964 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5965 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5966 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5967 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5968 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5969 |
"/ take the next-larger depth |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5970 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5971 |
or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5972 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5973 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5974 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5975 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5976 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5977 |
]. |
193 | 5978 |
]. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5979 |
|
193 | 5980 |
bestDeviceDepth isNil ifTrue:[ |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5981 |
maxBitsPerPixel == 0 ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5982 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5983 |
"/ oops - nothing appropriate |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5984 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5985 |
maxInfo notNil ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5986 |
^ maxInfo |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5987 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5988 |
bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5989 |
bestInfo := IdentityDictionary new. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5990 |
bestInfo at:#depth put:bestDeviceDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5991 |
bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5992 |
bestInfo at:#padding put:32. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5993 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5994 |
bestInfo := maxInfo. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5995 |
] |
193 | 5996 |
]. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
5997 |
^ bestInfo |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
5998 |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
5999 |
"Modified: 14.6.1996 / 14:46:40 / cg" |
283 | 6000 |
! |
6001 |
||
6002 |
colormapFromImage:anImage |
|
6003 |
"setup the receivers colormap from another image. |
|
6004 |
Color precision may be lost, if conversion is from a higher depth |
|
6005 |
image. This does not convert any pixel values; it is non-public helper |
|
6006 |
for fromImage:/fromSubImake:" |
|
6007 |
||
6008 |
samplesPerPixel == 3 ifTrue:[ |
|
6009 |
photometric := #rgb |
|
6010 |
] ifFalse:[ |
|
6011 |
photometric := anImage photometric. |
|
6012 |
photometric == #palette ifTrue:[ |
|
6013 |
colorMap := anImage colorMap copy. |
|
6014 |
" |
|
6015 |
must compress the colormap, if source image has higher depth |
|
6016 |
than myself. |
|
6017 |
" |
|
6018 |
anImage bitsPerPixel > self bitsPerPixel ifTrue:[ |
|
6019 |
" |
|
6020 |
get used colors are extracted into our colorMap |
|
6021 |
(the at-put below will set the pixelValue according the |
|
6022 |
new colorIndex |
|
6023 |
" |
|
6024 |
colorMap := anImage usedColors asArray. |
|
6025 |
colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[ |
|
6026 |
'IMAGE: possibly too many colors in image' errorPrintNL |
|
6027 |
] |
|
6028 |
] |
|
6029 |
] |
|
6030 |
]. |
|
6031 |
||
6032 |
"Created: 20.9.1995 / 00:58:42 / claus" |
|
6033 |
! |
|
6034 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6035 |
greyByteMapForRange:range |
798 | 6036 |
"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
|
6037 |
in the range 0..range. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6038 |
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
|
6039 |
The values are rounded towards the nearest pixel." |
798 | 6040 |
|
808 | 6041 |
|d n greyMap r| |
6042 |
||
6043 |
r := range. |
|
6044 |
r == 256 ifTrue:[ |
|
6045 |
r := 255 |
|
798 | 6046 |
]. |
6047 |
||
6048 |
photometric == #palette ifTrue:[ |
|
808 | 6049 |
n := colorMap size. |
6050 |
greyMap := ByteArray new:n. |
|
6051 |
||
6052 |
1 to:n do:[:i | |
|
6053 |
greyMap at:i put:(r * (colorMap at:i) brightness) rounded |
|
798 | 6054 |
]. |
6055 |
] ifFalse:[ |
|
808 | 6056 |
d := self bitsPerPixel. |
6057 |
n := 1 bitShift:d. |
|
6058 |
n >= 4096 ifTrue:[ |
|
6059 |
self error:'size not supported - too large'. |
|
6060 |
^ nil |
|
6061 |
]. |
|
6062 |
greyMap := ByteArray new:n. |
|
6063 |
||
6064 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6065 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6066 |
1 to:n do:[:i | |
808 | 6067 |
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
|
6068 |
]. |
798 | 6069 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6070 |
1 to:n do:[:i | |
808 | 6071 |
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
|
6072 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6073 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6074 |
"/ we are done |
798 | 6075 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6076 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6077 |
greyMap reverse |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6078 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6079 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6080 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6081 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6082 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6083 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6084 |
]. |
808 | 6085 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6086 |
^ greyMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6087 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6088 |
" |
808 | 6089 |
Depth8Image new greyByteMapForRange:256 |
6090 |
||
6091 |
Depth8Image new greyByteMapForRange:64 |
|
6092 |
Depth4Image new greyByteMapForRange:64 |
|
6093 |
||
6094 |
Depth4Image new greyByteMapForRange:1 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6095 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6096 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6097 |
"Created: 8.6.1996 / 08:34:14 / cg" |
808 | 6098 |
"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
|
6099 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6100 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6101 |
greyMapForRange:range |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6102 |
"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
|
6103 |
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
|
6104 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6105 |
|d r |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6106 |
n "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6107 |
greyArray| |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6108 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6109 |
d := self bitsPerPixel. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6110 |
n := 1 bitShift:d. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6111 |
n >= 4096 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6112 |
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
|
6113 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6114 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6115 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6116 |
greyArray := Array new:n. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6117 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6118 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6119 |
1 to:(colorMap size) do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6120 |
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
|
6121 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6122 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6123 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6124 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6125 |
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
|
6126 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6127 |
] ifFalse:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6128 |
r := range asFloat. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6129 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6130 |
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
|
6131 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6132 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6133 |
"/ we are done |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6134 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6135 |
photometric == #whiteIs0 ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6136 |
greyArray reverse |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6137 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6138 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6139 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6140 |
] |
798 | 6141 |
] |
6142 |
] |
|
6143 |
]. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6144 |
^ greyArray |
798 | 6145 |
|
6146 |
" |
|
6147 |
Depth8Image new greyMapForRange:64 |
|
6148 |
Depth4Image new greyMapForRange:64 |
|
6149 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6150 |
Depth16Image new greyMapForRange:1 |
798 | 6151 |
Depth4Image new greyMapForRange:1 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6152 |
Depth2Image new greyMapForRange:1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6153 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6154 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6155 |
"Modified: 10.6.1996 / 10:37:40 / cg" |
798 | 6156 |
! |
6157 |
||
283 | 6158 |
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels |
6159 |
into:dstBytes offset:dstStart factor:mX |
|
6160 |
||
6161 |
"magnify a single pixel row - can only magnify by integer factors, |
|
6162 |
can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast." |
|
6163 |
||
6164 |
^ self subclassResponsibility |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6165 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6166 |
|
816 | 6167 |
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
6168 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6169 |
pixels interpreted as greyValues, 0 is black, |
|
6170 |
create a device form for it" |
|
6171 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6172 |
|f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6173 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6174 |
f := Form width:width height:height depth:depth on:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6175 |
f isNil ifTrue:[^ nil]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6176 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6177 |
f bits:bits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6178 |
f initGC. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6179 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6180 |
(aDevice blackpixel ~~ 0) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6181 |
"/ have to invert bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6182 |
f function:#copyInverted |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6183 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6184 |
aDevice drawBits:bits depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6185 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6186 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6187 |
into:(f id) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6188 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6189 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6190 |
with:(f gcId). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6191 |
^ f |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6192 |
|
816 | 6193 |
"Created: 10.6.1996 / 20:10:31 / cg" |
6194 |
! |
|
6195 |
||
6196 |
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
6197 |
"given the bits of a monochrome bitmap, 8-bit padded and |
|
6198 |
0-bits as black, create a device form for it" |
|
6199 |
||
6200 |
monoBits invert. |
|
6201 |
^ (Form width:width height:height fromArray:monoBits on:aDevice) |
|
6202 |
colorMap:(Array with:Color black with:Color white). |
|
6203 |
||
6204 |
"Created: 10.6.1996 / 20:18:09 / cg" |
|
6205 |
"Modified: 10.6.1996 / 20:31:24 / cg" |
|
6206 |
! |
|
6207 |
||
6208 |
makeDevicePixmapOn:aDevice depth:depth fromArray:bits |
|
6209 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6210 |
pixels interpreted as in the devices colormap, |
|
6211 |
create a device form for it" |
|
6212 |
||
6213 |
|f| |
|
6214 |
||
6215 |
f := Form width:width height:height depth:depth on:aDevice. |
|
6216 |
f isNil ifTrue:[^ nil]. |
|
6217 |
||
6218 |
f bits:bits. |
|
6219 |
f initGC. |
|
6220 |
||
6221 |
aDevice drawBits:bits depth:depth |
|
6222 |
width:width height:height |
|
6223 |
x:0 y:0 |
|
6224 |
into:(f id) |
|
6225 |
x:0 y:0 |
|
6226 |
width:width height:height |
|
6227 |
with:(f gcId). |
|
6228 |
^ f |
|
6229 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6230 |
"Created: 10.6.1996 / 17:56:08 / cg" |
816 | 6231 |
"Modified: 10.6.1996 / 20:11:27 / cg" |
2 | 6232 |
! ! |
0 | 6233 |
|
283 | 6234 |
!Image methodsFor:'queries'! |
6235 |
||
6236 |
averageColor |
|
6237 |
"return the average color of the image. |
|
6238 |
This usually only makes sense for textures and patterns |
|
6239 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
6240 |
Notice, that for the above purpose, it is usually ok to process |
|
6241 |
a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle" |
|
6242 |
||
6243 |
^ self averageColorIn:(0@0 corner:(width-1)@(height-1)) |
|
6244 |
! |
|
6245 |
||
6246 |
averageColorIn:aRectangle |
|
6247 |
"return the images average color in an area. |
|
6248 |
The implementation below is slow - so you may want to |
|
6249 |
create tuned versions for DepthXImage if you plan to do |
|
6250 |
heavy image processing ... |
|
6251 |
(also, creating tuned versions of the enumeration messages helps a lot)" |
|
6252 |
||
6253 |
|x0 "{ Class:SmallInteger }" |
|
6254 |
y0 "{ Class:SmallInteger }" |
|
6255 |
x1 "{ Class:SmallInteger }" |
|
6256 |
y1 "{ Class:SmallInteger }" |
|
6257 |
sumRed sumGreen sumBlue n| |
|
6258 |
||
6259 |
sumRed := sumGreen := sumBlue := 0. |
|
6260 |
y0 := aRectangle top. |
|
6261 |
y1 := aRectangle bottom. |
|
6262 |
x0 := aRectangle left. |
|
6263 |
x1 := aRectangle right. |
|
6264 |
||
6265 |
self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY | |
|
6266 |
sumRed := sumRed + colorAtXY red. |
|
6267 |
sumGreen := sumGreen + colorAtXY green. |
|
6268 |
sumBlue := sumBlue + colorAtXY blue. |
|
6269 |
]. |
|
6270 |
n := (x1 - x0 + 1) * (y1 - y0 + 1). |
|
6271 |
^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n) |
|
6272 |
! |
|
6273 |
||
6274 |
bitsPerPixel |
|
6275 |
"return the number of bits per pixel" |
|
6276 |
||
6277 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
|
6278 |
! |
|
6279 |
||
6280 |
bitsPerRow |
|
6281 |
"return the number of bits in one scanline of the image" |
|
6282 |
||
6283 |
^ width * (self bitsPerPixel). |
|
6284 |
! |
|
6285 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6286 |
blueBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6287 |
"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
|
6288 |
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
|
6289 |
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
|
6290 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6291 |
|blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6292 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6293 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6294 |
"/ 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
|
6295 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6296 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6297 |
blueBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6298 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6299 |
^ pixel bitAnd:(1 bitShift:blueBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6300 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6301 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6302 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6303 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6304 |
"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
|
6305 |
"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
|
6306 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6307 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6308 |
blueComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6309 |
"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
|
6310 |
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
|
6311 |
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
|
6312 |
|
854 | 6313 |
|blueBits "{ Class: SmallInteger }" |
6314 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6315 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6316 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6317 |
"/ 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
|
6318 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6319 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6320 |
blueBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6321 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6322 |
s := (1 bitShift:blueBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6323 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6324 |
^ 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
|
6325 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6326 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6327 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6328 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6329 |
"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
|
6330 |
"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
|
6331 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6332 |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6333 |
bounds |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6334 |
"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
|
6335 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6336 |
^ 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
|
6337 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6338 |
"Created: 13.5.1996 / 10:27:06 / cg" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6339 |
! |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6340 |
|
283 | 6341 |
brightness |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6342 |
"return the (average) brightness of the image. |
283 | 6343 |
This usually only makes sense for textures and patterns |
6344 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
6345 |
Notice, that for the above purpose, only a subimage is inspected here" |
|
6346 |
||
6347 |
^ (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
|
6348 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6349 |
"Modified: 8.6.1996 / 08:46:46 / cg" |
283 | 6350 |
! |
6351 |
||
6352 |
bytesPerRow |
|
6353 |
"return the number of bytes in one scanline of the image" |
|
6354 |
||
6355 |
|bitsPerRow bytesPerRow| |
|
6356 |
||
6357 |
bitsPerRow := width * (self bitsPerPixel). |
|
6358 |
bytesPerRow := bitsPerRow // 8. |
|
6359 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
6360 |
bytesPerRow := bytesPerRow + 1 |
|
6361 |
]. |
|
6362 |
^ bytesPerRow |
|
6363 |
! |
|
6364 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6365 |
colorFromValue:pixelValue |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6366 |
"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
|
6367 |
Pixel values start with 0." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6368 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6369 |
|maxPixel r g b| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6370 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6371 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6372 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6373 |
^ Color gray:(pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6374 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6375 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6376 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6377 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6378 |
^ Color gray:100 - (pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6379 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6380 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6381 |
photometric == #palette ifTrue:[ |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6382 |
pixelValue >= colorMap size ifTrue:[ |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6383 |
^ Color black |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6384 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6385 |
^ colorMap at:(pixelValue + 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6386 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6387 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6388 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6389 |
r := self redComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6390 |
g := self greenComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6391 |
b := self blueComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6392 |
^ 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
|
6393 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6394 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6395 |
self error:'invalid photometric' |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6396 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6397 |
"Created: 8.6.1996 / 08:46:18 / cg" |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6398 |
"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
|
6399 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6400 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6401 |
greenBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6402 |
"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
|
6403 |
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
|
6404 |
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
|
6405 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6406 |
|blueBits greenBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6407 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6408 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6409 |
"/ 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
|
6410 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6411 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6412 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6413 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6414 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6415 |
^ (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
|
6416 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6417 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6418 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6419 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6420 |
"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
|
6421 |
"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
|
6422 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6423 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6424 |
greenComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6425 |
"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
|
6426 |
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
|
6427 |
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
|
6428 |
|
854 | 6429 |
|greenBits "{ Class: SmallInteger }" |
6430 |
blueBits "{ Class: SmallInteger }" |
|
6431 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6432 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6433 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6434 |
"/ 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
|
6435 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6436 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6437 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6438 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6439 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6440 |
s := (1 bitShift:greenBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6441 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6442 |
^ 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
|
6443 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6444 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6445 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6446 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6447 |
"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
|
6448 |
"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
|
6449 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6450 |
|
674 | 6451 |
heightOn:aGC |
6452 |
"return my height, if displayed on aGC; |
|
6453 |
since my height is independent of the device (the number of pixels), |
|
6454 |
return the pixel-height" |
|
6455 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6456 |
^ height |
674 | 6457 |
|
6458 |
"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
|
6459 |
"Modified: 13.5.1996 / 10:26:36 / cg" |
674 | 6460 |
! |
6461 |
||
283 | 6462 |
isImage |
6463 |
"return true, if the receiver is some kind of image; |
|
6464 |
true is returned here - the method is redefined from Object." |
|
6465 |
||
6466 |
^ true |
|
6467 |
! |
|
6468 |
||
6469 |
isImageOrForm |
|
6470 |
"return true, if the receiver is some kind of image or form; |
|
6471 |
true is returned here - the method is redefined from Object." |
|
6472 |
||
6473 |
^ true |
|
6474 |
! |
|
6475 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6476 |
redBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6477 |
"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
|
6478 |
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
|
6479 |
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
|
6480 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6481 |
|redBits greenBits blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6482 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6483 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6484 |
"/ 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
|
6485 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6486 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6487 |
redBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6488 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6489 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6490 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6491 |
^ (pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6492 |
bitAnd:(1 bitShift:redBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6493 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6494 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6495 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6496 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6497 |
"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
|
6498 |
"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
|
6499 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6500 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6501 |
redComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6502 |
"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
|
6503 |
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
|
6504 |
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
|
6505 |
|
854 | 6506 |
|redBits "{ Class: SmallInteger }" |
6507 |
greenBits "{ Class: SmallInteger }" |
|
6508 |
blueBits "{ Class: SmallInteger }" |
|
6509 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6510 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6511 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6512 |
"/ 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
|
6513 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6514 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6515 |
redBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6516 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6517 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6518 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6519 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6520 |
s := (1 bitShift:redBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6521 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6522 |
^ 100.0 / s * |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6523 |
((pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6524 |
bitAnd:(1 bitShift:redBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6525 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6526 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6527 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6528 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6529 |
"Created: 8.6.1996 / 08:45:30 / cg" |
854 | 6530 |
"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
|
6531 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6532 |
|
283 | 6533 |
usedColors |
6534 |
"return a collection of colors used in the receiver." |
|
6535 |
||
6536 |
|usedValues max| |
|
6537 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6538 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6539 |
"/ 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
|
6540 |
"/ 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
|
6541 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6542 |
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
|
6543 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6544 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6545 |
|
283 | 6546 |
usedValues := self usedValues asArray. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6547 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6548 |
^ usedValues collect:[:val | (colorMap at:val+1)] |
283 | 6549 |
]. |
6550 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6551 |
"/ (photometric == #blackIs0 or:[photometric == #whiteIs0]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6552 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6553 |
max := (1 bitShift:self depth) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6554 |
^ usedValues collect:[:val | (Color gray:(100 * val / max ))] |
283 | 6555 |
|
6556 |
" |
|
6557 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
6558 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
6559 |
(Image fromFile:'ttt.tiff') usedColors |
|
6560 |
" |
|
746 | 6561 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6562 |
"Modified: 8.6.1996 / 09:04:56 / cg" |
283 | 6563 |
! |
6564 |
||
6565 |
usedValues |
|
6566 |
"return a collection of color values used in the receiver. |
|
6567 |
Notice, that the interpretation of the pixels depends on the photometric |
|
6568 |
of the image. |
|
6569 |
This is a general and therefore slow implementation; subclasses |
|
6570 |
may want to redefine this method for more performance." |
|
6571 |
||
6572 |
|set| |
|
6573 |
||
6574 |
set := IdentitySet new. |
|
6575 |
self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel | |
|
6576 |
set add:pixel |
|
6577 |
]. |
|
6578 |
^ set |
|
6579 |
||
6580 |
" |
|
6581 |
(Image fromFile:'bitmaps/garfield.gif') usedValues |
|
6582 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedValues |
|
6583 |
(Image fromFile:'ttt.tiff') usedValues |
|
6584 |
" |
|
674 | 6585 |
! |
6586 |
||
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6587 |
valueFromColor:color |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6588 |
"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
|
6589 |
Non-representable colors return nil." |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6590 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6591 |
|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
|
6592 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6593 |
photometric == #whiteIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6594 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6595 |
^ maxPixel - (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6596 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6597 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6598 |
photometric == #blackIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6599 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6600 |
^ (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6601 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6602 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6603 |
photometric == #palette ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6604 |
pixel := colorMap indexOf:color. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6605 |
pixel == 0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6606 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6607 |
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
|
6608 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6609 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6610 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6611 |
^ pixel - 1 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6612 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6613 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6614 |
photometric == #rgb ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6615 |
samplesPerPixel >= 3 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6616 |
redBits := bitsPerSample at:1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6617 |
greenBits := bitsPerSample at:2. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6618 |
blueBits := bitsPerSample at:3. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6619 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6620 |
"/ map r/g/b to 0..255 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6621 |
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
|
6622 |
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
|
6623 |
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
|
6624 |
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
|
6625 |
^ pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6626 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6627 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6628 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6629 |
self error:'format not supported'. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6630 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6631 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6632 |
"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
|
6633 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6634 |
|
674 | 6635 |
widthOn:aGC |
6636 |
"return my width, if displayed on aGC; |
|
6637 |
since my width is independent of the device (the number of pixels), |
|
6638 |
return the pixel-width" |
|
6639 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6640 |
^ width |
674 | 6641 |
|
6642 |
"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
|
6643 |
"Modified: 13.5.1996 / 10:26:42 / cg" |
283 | 6644 |
! ! |
6645 |
||
6646 |
!Image methodsFor:'saving on file'! |
|
6647 |
||
6648 |
saveOn:aFileName |
|
6649 |
"save the image in a aFileName. The suffix of the filename |
|
6650 |
controls the format. Currently, not all formats may be supported |
|
6651 |
(see ImageReader subclasses implementing save:onFile:)" |
|
6652 |
||
6653 |
" |
|
6654 |
from the extension, get the imageReader class |
|
6655 |
(which should know how to write images as well) |
|
6656 |
" |
|
6657 |
FileFormats associationsDo:[:a | |
|
6658 |
(aFileName endsWith:(a key)) ifTrue:[ |
|
6659 |
^ (a value) save:self onFile:aFileName |
|
6660 |
] |
|
6661 |
]. |
|
6662 |
||
6663 |
" |
|
6664 |
no known extension - could ask user for the format here. |
|
6665 |
currently default to tiff format. |
|
6666 |
" |
|
6667 |
'IMAGE: unknown extension - cannot figure out format - using tiff' errorPrintNL. |
|
6668 |
^ self saveOn:aFileName using:TIFFReader |
|
89 | 6669 |
! |
6670 |
||
283 | 6671 |
saveOn:aFileName using:readerClass |
6672 |
"save the receiver using the representation class" |
|
6673 |
||
6674 |
readerClass save:self onFile:aFileName |
|
6675 |
||
6676 |
" |
|
6677 |
anImage saveOn:'myImage' using:TIFFReader |
|
6678 |
anImage saveOn:'myImage' using:XBMReader |
|
6679 |
" |
|
0 | 6680 |
! ! |
283 | 6681 |
|
6682 |
!Image methodsFor:'screen capture'! |
|
6683 |
||
6684 |
fromScreen:aRectangle |
|
6685 |
"read an image from the display screen" |
|
6686 |
||
6687 |
^ self fromScreen:aRectangle on:Screen current |
|
6688 |
! |
|
6689 |
||
6690 |
fromScreen:aRectangle on:aDevice |
|
6691 |
"read an image from aDevices display screen. |
|
6692 |
Since I have no other displays, only the MonoChrome, StaticGrey |
|
6693 |
and PseudoColor cases have been tested ... |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6694 |
(especially True- and DirectColor may be wrong). |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6695 |
Late note: 24bit rgb now also works." |
283 | 6696 |
|
6697 |
|depth visType |
|
6698 |
x "{ Class: SmallInteger }" |
|
6699 |
y "{ Class: SmallInteger }" |
|
6700 |
w "{ Class: SmallInteger }" |
|
6701 |
h "{ Class: SmallInteger }" |
|
6702 |
dstIndex "{ Class: SmallInteger }" |
|
6703 |
srcIndex "{ Class: SmallInteger }" |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6704 |
srcRow "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6705 |
dstRow "{ Class: SmallInteger }" |
283 | 6706 |
inData tmpData usedPixels mapSize |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6707 |
map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6708 |
info bitsPerPixelIn bytesPerLineIn curs cid rootView |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6709 |
maskR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6710 |
maskG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6711 |
maskB "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6712 |
shR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6713 |
shG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6714 |
shB "{ Class: SmallInteger }" |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6715 |
shR2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6716 |
shG2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6717 |
shB2 "{ Class: SmallInteger }" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6718 |
r "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6719 |
g "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6720 |
b "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6721 |
word| |
283 | 6722 |
|
6723 |
curs := Cursor sourceForm:(Form fromFile:'Camera.xbm') |
|
518 | 6724 |
maskForm:(Form fromFile:'Camera_m.xbm') |
6725 |
hotSpot:16@16. |
|
283 | 6726 |
curs notNil ifTrue:[ |
518 | 6727 |
cid := (curs on:aDevice) id |
283 | 6728 |
]. |
6729 |
||
6730 |
" |
|
6731 |
get some attributes of the display device |
|
6732 |
" |
|
6733 |
visType := aDevice visualType. |
|
6734 |
depth := aDevice depth. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6735 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6736 |
"/ kludge for 15bit XFree server |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6737 |
depth == 15 ifTrue:[ |
518 | 6738 |
depth := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6739 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6740 |
|
283 | 6741 |
(visType == #StaticGray) ifTrue:[ |
518 | 6742 |
(aDevice blackpixel == 0) ifTrue:[ |
6743 |
photometric := #blackIs0 |
|
6744 |
] ifFalse:[ |
|
6745 |
photometric := #whiteIs0 |
|
6746 |
]. |
|
6747 |
samplesPerPixel := 1. |
|
6748 |
bitsPerPixel := depth. |
|
6749 |
bitsPerSample := Array with:bitsPerPixel. |
|
283 | 6750 |
] ifFalse:[ |
518 | 6751 |
((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[ |
6752 |
photometric := #palette. |
|
6753 |
samplesPerPixel := 1. |
|
6754 |
bitsPerPixel := depth. |
|
6755 |
bitsPerSample := Array with:bitsPerPixel. |
|
6756 |
] ifFalse:[ |
|
6757 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
6758 |
photometric := #rgb. |
|
6759 |
samplesPerPixel := 3. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6760 |
"/ bitsPerPixel := depth. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6761 |
"/ 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
|
6762 |
"/ with:aDevice bitsGreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6763 |
"/ with:aDevice bitsBlue |
518 | 6764 |
bitsPerPixel := 24. |
6765 |
bitsPerSample := #(8 8 8). |
|
6766 |
] ifFalse:[ |
|
6767 |
self error:'screen visual not supported'. |
|
6768 |
^ nil |
|
6769 |
] |
|
6770 |
] |
|
283 | 6771 |
]. |
6772 |
||
6773 |
" |
|
6774 |
dont know yet, how the display pads; assume worst case, |
|
6775 |
offering enough space for 32 bit padding |
|
6776 |
" |
|
6777 |
w := width := aRectangle width. |
|
6778 |
h := height := aRectangle height. |
|
6779 |
x := aRectangle left. |
|
6780 |
y := aRectangle top. |
|
6781 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6782 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6783 |
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
|
6784 |
(its too late when info is present ...) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6785 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6786 |
spaceBitsPerPixel := bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6787 |
(bitsPerPixel > 8) ifTrue:[ |
518 | 6788 |
spaceBitsPerPixel := 16. |
6789 |
(bitsPerPixel > 16) ifTrue:[ |
|
6790 |
spaceBitsPerPixel := 32. |
|
6791 |
(bitsPerPixel > 32) ifTrue:[ |
|
6792 |
spaceBitsPerPixel := bitsPerPixel. |
|
6793 |
] |
|
6794 |
] |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6795 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6796 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6797 |
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4. |
283 | 6798 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
6799 |
||
6800 |
" |
|
6801 |
actually have to grabServer ... but thats not yet available |
|
6802 |
" |
|
728 | 6803 |
rootView := aDevice rootView. |
283 | 6804 |
aDevice setActivePointerGrab:rootView. |
6805 |
aDevice grabPointerIn:rootView id |
|
518 | 6806 |
withCursor:cid pointerMode:#async keyboardMode:#sync confineTo:nil. |
283 | 6807 |
|
6808 |
" |
|
6809 |
get the pixels |
|
6810 |
" |
|
6811 |
info := aDevice getBitsFrom:rootView id x:x y:y width:w height:h into:inData. |
|
6812 |
||
6813 |
" |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
6814 |
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
|
6815 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6816 |
byteOrder := info at:#byteOrder. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6817 |
bitsPerPixelIn := info at:#bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6818 |
byteOrder ~~ #msbFirst ifTrue:[ |
518 | 6819 |
bitsPerPixelIn == 16 ifTrue:[ |
6820 |
"/ must swap bytes |
|
6821 |
inData swapBytes |
|
6822 |
] ifFalse:[ |
|
6823 |
bitsPerPixelIn == 32 ifTrue:[ |
|
6824 |
"/ must swap longs |
|
6825 |
inData swapLongs |
|
6826 |
] |
|
6827 |
] |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
6828 |
]. |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
6829 |
|
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
6830 |
" |
283 | 6831 |
check, if the devices padding is different .. |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6832 |
or if the bitsPerPixels are different |
283 | 6833 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6834 |
bytesPerLineIn := (info at:#bytesPerLine). "what I got" |
283 | 6835 |
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
|
6836 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6837 |
((bytesPerLine ~~ bytesPerLineIn) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6838 |
or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[ |
518 | 6839 |
tmpData := inData. |
6840 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
6841 |
||
6842 |
srcRow := 1. |
|
6843 |
dstRow := 1. |
|
6844 |
||
6845 |
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[ |
|
6846 |
"/ for now, only 32 -> 24 is supported |
|
6847 |
||
6848 |
maskR := (1 bitShift:aDevice bitsRed) - 1. |
|
6849 |
maskG := (1 bitShift:aDevice bitsGreen) - 1. |
|
6850 |
maskB := (1 bitShift:aDevice bitsBlue) - 1. |
|
6851 |
shR := aDevice shiftRed negated. |
|
6852 |
shG := aDevice shiftGreen negated. |
|
6853 |
shB := aDevice shiftBlue negated. |
|
6854 |
shR2 := (8 - aDevice bitsRed). |
|
6855 |
shG2 := (8 - aDevice bitsGreen). |
|
6856 |
shB2 := (8 - aDevice bitsBlue). |
|
6857 |
||
6858 |
((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[ |
|
6859 |
"/ 'reformatting 32->24...' printNL. |
|
6860 |
1 to:h do:[:hi | |
|
6861 |
srcIndex := srcRow. |
|
6862 |
dstIndex := dstRow. |
|
6863 |
||
6864 |
1 to:w do:[:wi | |
|
6865 |
word := tmpData doubleWordAt:srcIndex MSB:true. |
|
6866 |
r := (word bitShift:shR) bitAnd:maskR. |
|
6867 |
g := (word bitShift:shG) bitAnd:maskG. |
|
6868 |
b := (word bitShift:shB) bitAnd:maskB. |
|
6869 |
||
6870 |
inData at:dstIndex put:r. |
|
6871 |
inData at:dstIndex+1 put:g. |
|
6872 |
inData at:dstIndex+2 put:b. |
|
6873 |
srcIndex := srcIndex + 4. |
|
6874 |
dstIndex := dstIndex + 3. |
|
6875 |
]. |
|
6876 |
dstRow := dstRow + bytesPerLine. |
|
6877 |
srcRow := srcRow + bytesPerLineIn |
|
6878 |
] |
|
6879 |
] ifFalse:[ |
|
6880 |
((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[ |
|
6881 |
"/ 'reformatting 16->24...' printNL. |
|
6882 |
1 to:h do:[:hi | |
|
6883 |
srcIndex := srcRow. |
|
6884 |
dstIndex := dstRow. |
|
6885 |
||
6886 |
1 to:w do:[:wi | |
|
6887 |
word := tmpData wordAt:srcIndex MSB:true. |
|
6888 |
r := (word bitShift:shR) bitAnd:maskR. |
|
6889 |
g := (word bitShift:shG) bitAnd:maskG. |
|
6890 |
b := (word bitShift:shB) bitAnd:maskB. |
|
6891 |
||
6892 |
inData at:dstIndex put:(r bitShift:shR2). |
|
6893 |
inData at:dstIndex+1 put:(g bitShift:shG2). |
|
6894 |
inData at:dstIndex+2 put:(b bitShift:shB2). |
|
6895 |
srcIndex := srcIndex + 2. |
|
6896 |
dstIndex := dstIndex + 3. |
|
6897 |
]. |
|
6898 |
dstRow := dstRow + bytesPerLine. |
|
6899 |
srcRow := srcRow + bytesPerLineIn |
|
6900 |
] |
|
6901 |
] ifFalse:[ |
|
6902 |
('IMAGE: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' , |
|
6903 |
bitsPerPixel printString) errorPrintNL. |
|
6904 |
^ nil |
|
6905 |
] |
|
6906 |
]. |
|
6907 |
] ifFalse:[ |
|
6908 |
" |
|
6909 |
repad in the buffer |
|
6910 |
" |
|
6911 |
1 to:h do:[:hi | |
|
6912 |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1) |
|
6913 |
with:tmpData startingAt:srcRow. |
|
6914 |
dstRow := dstRow + bytesPerLine. |
|
6915 |
srcRow := srcRow + bytesPerLineIn |
|
6916 |
] |
|
6917 |
] |
|
283 | 6918 |
] ifFalse:[ |
518 | 6919 |
(bytesPerLine * height) ~~ inData size ifTrue:[ |
6920 |
tmpData := inData. |
|
6921 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
6922 |
inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1 |
|
6923 |
] |
|
283 | 6924 |
]. |
6925 |
bytes := inData. |
|
6926 |
||
6927 |
"info printNL." |
|
6928 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6929 |
((visType == #StaticGray) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6930 |
or:[visType == #TrueColor |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6931 |
or:[visType == #DirectColor]]) ifTrue:[ |
518 | 6932 |
" |
6933 |
were done, the pixel values are the rgb/grey values |
|
6934 |
" |
|
283 | 6935 |
] ifFalse:[ |
518 | 6936 |
" |
6937 |
what we have now are the color numbers - still need the r/g/b values. |
|
6938 |
find out, which colors are in the picture |
|
6939 |
" |
|
6940 |
usedPixels := inData usedValues. |
|
6941 |
mapSize := usedPixels max + 1. |
|
6942 |
||
6943 |
"get the palette" |
|
6944 |
map := Array new:mapSize. |
|
6945 |
usedPixels do:[:colorIndex | |
|
6946 |
|i| |
|
6947 |
||
6948 |
i := colorIndex + 1. |
|
6949 |
aDevice getRGBFrom:colorIndex into:[:r :g :b | |
|
6950 |
map at:i put:(Color red:r green:g blue:b) |
|
6951 |
] |
|
6952 |
]. |
|
6953 |
colorMap := map. |
|
283 | 6954 |
]. |
6955 |
||
6956 |
aDevice ungrabPointer. |
|
6957 |
||
6958 |
" |
|
6959 |
(Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display |
|
6960 |
(Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display |
|
6961 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
6962 |
|
518 | 6963 |
"Modified: 7.3.1996 / 19:17:33 / cg" |
283 | 6964 |
! ! |
6965 |
||
6966 |
!Image class methodsFor:'documentation'! |
|
6967 |
||
6968 |
version |
|
873 | 6969 |
^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.100 1996-06-17 09:48:22 cg Exp $' |
650 | 6970 |
! ! |
283 | 6971 |
Image initialize! |