author | Claus Gittinger <cg@exept.de> |
Mon, 17 Jun 1996 14:47:28 +0200 | |
changeset 874 | cce9c1029d38 |
parent 873 | f44d57cc8d05 |
child 878 | b99add8dc742 |
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 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2039 |
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2040 |
"return a floyd-steinberg dithered pseudoForm from the picture, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2041 |
using colors in colors for dithering." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2042 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2043 |
|pseudoBits f has8BitImage deviceDepth |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2044 |
map | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2045 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2046 |
deviceDepth := aDevice depth. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2047 |
deviceDepth == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2048 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2049 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2050 |
has8BitImage := false. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2051 |
aDevice supportedImageFormats do:[:fmt | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2052 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2053 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2054 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2055 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2056 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2057 |
has8BitImage ifFalse:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2058 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2059 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:colors. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2060 |
pseudoBits isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2061 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2062 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2063 |
f isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2064 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2065 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2066 |
"/ have to create a funny colorMap, where |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2067 |
"/ color at:index == color colorId:index |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2068 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2069 |
map := Array new:256 withAll:0. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2070 |
colors do:[:clr | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2071 |
clr notNil ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2072 |
map at:clr colorId + 1 put:clr |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2073 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2074 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2075 |
f colorMap:map. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2076 |
f initGC. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2077 |
f bits:pseudoBits. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2078 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2079 |
width:width height:height |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2080 |
x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2081 |
into:(f id) x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2082 |
width:width height:height with:(f gcId). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2083 |
^ f |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2084 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2085 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2086 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2087 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2088 |
i := Image fromFile:'bitmaps/garfield.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2089 |
(i asFloydSteinbergDitheredPseudoFormUsing:(Smalltalk at:#'Color:DitherColors') on:Display) inspect |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2090 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2091 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2092 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2093 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2094 |
i := Image fromFile:'bitmaps/claus.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2095 |
(i asFloydSteinbergDitheredPseudoFormUsing:(Smalltalk at:#'Color:DitherColors') on:Display) inspect |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2096 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2097 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2098 |
"Created: 17.6.1996 / 12:13:35 / cg" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2099 |
"Modified: 17.6.1996 / 12:45:21 / cg" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2100 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2101 |
|
0 | 2102 |
asFormOn:aDevice |
72 | 2103 |
"get a device form, with best possible approximation. |
2104 |
remember it in case someone asks again." |
|
2105 |
||
2106 |
|form| |
|
2107 |
||
2108 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
|
0 | 2109 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2110 |
aDevice depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2111 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2112 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2113 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2114 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2115 |
^ self asGrayFormOn:aDevice |
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 |
|
873 | 2118 |
(aDevice visualType == #PseudoColor) ifTrue:[ |
2119 |
form := self asPseudoFormQuickOn:aDevice. |
|
2120 |
form notNil ifTrue:[ |
|
2121 |
^ form |
|
2122 |
]. |
|
2123 |
]. |
|
2124 |
||
0 | 2125 |
(photometric == #palette) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2126 |
form := self paletteImageAsFormOn:aDevice |
72 | 2127 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2128 |
(photometric == #rgb) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2129 |
form := self rgbImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2130 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2131 |
form := self greyImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2132 |
] |
0 | 2133 |
]. |
2134 |
||
72 | 2135 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2136 |
"remember this form in the receiver ..." |
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 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2139 |
deviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2140 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2141 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2142 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2143 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2144 |
Lobby registerChange:self |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2147 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2148 |
twice (here and in the device form) |
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 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2151 |
] |
0 | 2152 |
]. |
2153 |
||
72 | 2154 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2155 |
|
873 | 2156 |
"Modified: 17.6.1996 / 10:41:02 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2157 |
! |
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 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2160 |
"get a gray device form" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2161 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2162 |
^ self asGrayFormOn:aDevice dither:DitherAlgorithm. |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2165 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2166 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2167 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2168 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2169 |
" |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2172 |
"Created: 10.6.1996 / 18:44:42 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2173 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2174 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2175 |
asGrayFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2176 |
"get a greyscale device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2177 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2178 |
|grayBits depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2179 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2180 |
depth := aDevice depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2181 |
depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2182 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2183 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2184 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2185 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2186 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2187 |
^ self asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2188 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2189 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2190 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2191 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2192 |
^ self asOrderedDitheredGrayFormOn:aDevice |
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 |
^ self asFloydSteinbergDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2196 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2197 |
"Created: 10.6.1996 / 18:42:01 / cg" |
852 | 2198 |
"Modified: 14.6.1996 / 15:17:28 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2199 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2200 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2201 |
asGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2202 |
"get a gray image from the receiver" |
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 |
^ self asGrayImageDepth:depth dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2205 |
|
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| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2208 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2209 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2210 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2211 |
" |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2214 |
"Created: 10.6.1996 / 19:07:08 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2215 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2216 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2217 |
asGrayImageDepth:depth dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2218 |
"get a greyscale image, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2219 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2220 |
|grayBits| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2221 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2222 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2223 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2224 |
^ self asThresholdGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2225 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2226 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2227 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2228 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2229 |
^ self asOrderedDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2230 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2231 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2232 |
^ self asFloydSteinbergDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2233 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2234 |
"Created: 10.6.1996 / 19:08:21 / cg" |
0 | 2235 |
! |
2236 |
||
2237 |
asMonochromeFormOn:aDevice |
|
2238 |
"get a monochrome device form" |
|
2239 |
||
72 | 2240 |
|form| |
2241 |
||
2242 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm]. |
|
2243 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2244 |
form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm. |
0 | 2245 |
|
72 | 2246 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2247 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2248 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2249 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2250 |
monoDeviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2251 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2252 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2253 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2254 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2255 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2256 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2257 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2258 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2259 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2260 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2261 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2262 |
] |
0 | 2263 |
]. |
2264 |
||
72 | 2265 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2266 |
|
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 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2269 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2270 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2271 |
(i asMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2272 |
" |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2275 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2276 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2277 |
asMonochromeFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2278 |
"get a monochrome device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2279 |
|
816 | 2280 |
|monoBits clr0 clr1 mustInvert| |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2281 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2282 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2283 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2284 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2285 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2286 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2287 |
aDitherAlgorithm == #burkes ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2288 |
monoBits := self burkesDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2289 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2290 |
aDitherAlgorithm == #stevensonArce ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2291 |
monoBits := self stevensonArceDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2292 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2293 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2294 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2295 |
^ self asOrderedDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2296 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2297 |
^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2298 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2299 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2300 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2301 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2302 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2303 |
"/ make its pixel interpretation correct for the device |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2304 |
"/ |
816 | 2305 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
2306 |
||
2307 |
"Modified: 10.6.1996 / 20:18:05 / cg" |
|
89 | 2308 |
! |
2309 |
||
808 | 2310 |
asOrderedDitheredGrayFormOn:aDevice |
2311 |
"return a dithered depth-x grey form from the receiver image. |
|
2312 |
Uses an 8x8 dithermatrix." |
|
2313 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2314 |
|f depth bits| |
808 | 2315 |
|
2316 |
depth := aDevice depth. |
|
2317 |
depth == 1 ifTrue:[ |
|
2318 |
"/ for monochrome, there is highly specialized |
|
2319 |
"/ monochrome dither code available |
|
2320 |
||
2321 |
^ self asOrderedDitheredMonochromeFormOn:aDevice |
|
2322 |
]. |
|
2323 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2324 |
bits := self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2325 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
808 | 2326 |
ditherWidth:8 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2327 |
depth:depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2328 |
|
816 | 2329 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2330 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2331 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2332 |
|i| |
808 | 2333 |
|
2334 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2335 |
(i asOrderedDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2336 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2337 |
|
816 | 2338 |
"Modified: 10.6.1996 / 20:10:07 / cg" |
808 | 2339 |
! |
2340 |
||
798 | 2341 |
asOrderedDitheredGrayImageDepth:depth |
2342 |
"return a dithered depth-x grey image from the receiver image. |
|
2343 |
Uses an 8x8 dithermatrix." |
|
2344 |
||
2345 |
|dither| |
|
2346 |
||
2347 |
dither := self class orderedDitherMatrixOfSize:8. |
|
2348 |
||
2349 |
depth == 1 ifTrue:[ |
|
2350 |
"/ for monochrome, there is highly specialized |
|
2351 |
"/ monochrome dither code available |
|
2352 |
||
2353 |
^ Depth1Image |
|
2354 |
width:width |
|
2355 |
height:height |
|
2356 |
fromArray:( |
|
2357 |
self |
|
2358 |
orderedDitheredMonochromeBitsWithDitherMatrix:dither |
|
2359 |
ditherWidth:8) |
|
2360 |
]. |
|
2361 |
||
2362 |
^ (self class implementorForDepth:depth) |
|
2363 |
width:width |
|
2364 |
height:height |
|
2365 |
fromArray:( |
|
2366 |
self |
|
2367 |
orderedDitheredBitsWithDitherMatrix:dither |
|
2368 |
ditherWidth:8 |
|
2369 |
depth:depth) |
|
2370 |
||
2371 |
" |
|
2372 |
|i i1 i2 i4 i8| |
|
2373 |
||
2374 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2375 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2376 |
i1 inspect. |
|
2377 |
||
2378 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2379 |
i2 inspect. |
|
2380 |
||
2381 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2382 |
i4 inspect. |
|
2383 |
||
2384 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2385 |
i8 inspect. |
|
2386 |
" |
|
2387 |
||
2388 |
" |
|
2389 |
|i i1 i2 i4 i8| |
|
2390 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2391 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2392 |
i1 inspect. |
|
2393 |
||
2394 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2395 |
i2 inspect. |
|
2396 |
||
2397 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2398 |
i4 inspect. |
|
2399 |
||
2400 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2401 |
i8 inspect. |
|
800 | 2402 |
|
2403 |
i2 := i8 asOrderedDitheredGrayImageDepth:2. |
|
2404 |
i2 inspect. |
|
798 | 2405 |
" |
2406 |
||
2407 |
"Created: 7.6.1996 / 18:03:54 / cg" |
|
800 | 2408 |
"Modified: 7.6.1996 / 19:41:59 / cg" |
798 | 2409 |
! |
2410 |
||
2411 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2412 |
"return a dithered monochrome form from the grey image. |
|
2413 |
Uses a 4x4 dithermatrix." |
|
2414 |
||
2415 |
"/ 4x4 seems a good comprimize between: |
|
2416 |
"/ number of grey levels (8x8 is better) |
|
2417 |
"/ artifacts (4x4 is better) |
|
2418 |
"/ |
|
2419 |
"/ could look at the image and decide upon the number of |
|
2420 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2421 |
"/ 4x4 for small number of colors ... |
|
2422 |
||
2423 |
^ self |
|
2424 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2425 |
ditherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2426 |
ditherWidth:4 |
|
2427 |
||
2428 |
"/ ^ self |
|
2429 |
"/ asOrderedDitheredMonochromeFormOn:aDevice |
|
2430 |
"/ ditherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2431 |
"/ ditherWidth:8 |
|
2432 |
||
2433 |
" |
|
2434 |
|i f| |
|
2435 |
||
2436 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2437 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2438 |
||
2439 |
||
2440 |
|i f| |
|
2441 |
||
2442 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2443 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2444 |
||
2445 |
||
2446 |
|i f| |
|
2447 |
||
2448 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2449 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2450 |
||
2451 |
||
2452 |
|i f| |
|
2453 |
||
2454 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2455 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2456 |
||
2457 |
||
2458 |
|i f| |
|
2459 |
||
2460 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
2461 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2462 |
" |
|
2463 |
||
2464 |
"Created: 7.6.1996 / 14:52:32 / cg" |
|
2465 |
"Modified: 7.6.1996 / 16:37:47 / cg" |
|
2466 |
! |
|
2467 |
||
2468 |
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW |
|
2469 |
"return a dithered monochrome form from the image. |
|
2470 |
Uses the passed ditherMatrix and ditherWidth." |
|
2471 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2472 |
|monoBits clr0 clr1| |
798 | 2473 |
|
2474 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
816 | 2475 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2476 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2477 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2478 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2479 |
|i| |
798 | 2480 |
|
2481 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2482 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2483 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2484 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2485 |
|i| |
798 | 2486 |
|
2487 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2488 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2489 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2490 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2491 |
|i| |
798 | 2492 |
|
2493 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2494 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
798 | 2495 |
" |
2496 |
||
2497 |
"Created: 7.6.1996 / 14:51:42 / cg" |
|
816 | 2498 |
"Modified: 10.6.1996 / 20:18:07 / cg" |
798 | 2499 |
! |
2500 |
||
2501 |
asOrderedDitheredMonochromeImage |
|
2502 |
"return a dithered monochrome image from the receiver image. |
|
2503 |
Uses a 4x4 dithermatrix." |
|
2504 |
||
2505 |
"/ 4x4 seems a good comprimize between: |
|
2506 |
"/ number of grey levels (8x8 is better) |
|
2507 |
"/ artifacts (4x4 is better) |
|
2508 |
"/ |
|
2509 |
"/ could look at the image and decide upon the number of |
|
2510 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2511 |
"/ 4x4 for small number of colors ... |
|
2512 |
||
2513 |
^ self |
|
2514 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2515 |
ditherWidth:4 |
|
2516 |
||
2517 |
"/ ^ self |
|
2518 |
"/ asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2519 |
"/ ditherWidth:8 |
|
2520 |
||
2521 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2522 |
|i| |
798 | 2523 |
|
2524 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2525 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2526 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2527 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2528 |
|i| |
798 | 2529 |
|
2530 |
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
|
2531 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2532 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2533 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2534 |
|i| |
798 | 2535 |
|
2536 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2537 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2538 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2539 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2540 |
|i| |
798 | 2541 |
|
2542 |
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
|
2543 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2544 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2545 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2546 |
|i| |
798 | 2547 |
|
2548 |
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
|
2549 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2550 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2551 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2552 |
|i| |
798 | 2553 |
|
2554 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2555 |
i asOrderedDitheredMonochromeImage inspect |
798 | 2556 |
" |
2557 |
||
2558 |
"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
|
2559 |
"Modified: 10.6.1996 / 11:15:09 / cg" |
798 | 2560 |
! |
2561 |
||
2562 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
2563 |
"return a dithered monochrome image from the receiver image. |
|
2564 |
Uses the passed ditherMatrix and ditherWidth." |
|
2565 |
||
2566 |
|monoBits| |
|
2567 |
||
2568 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
2569 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
|
2570 |
||
2571 |
"order-4 dither: |
|
2572 |
||
2573 |
|i| |
|
2574 |
||
2575 |
i := Image fromFile:'garfield.gif'. |
|
2576 |
i |
|
2577 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4) |
|
2578 |
ditherWidth:4 |
|
2579 |
" |
|
2580 |
||
2581 |
"order-6 dither: |
|
2582 |
||
2583 |
|i| |
|
2584 |
||
2585 |
i := Image fromFile:'garfield.gif'. |
|
2586 |
i |
|
2587 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8) |
|
2588 |
ditherWidth:8 |
|
2589 |
" |
|
2590 |
||
2591 |
||
2592 |
"thresholding at:0.5 (all above 0.5 becomes white): |
|
2593 |
||
2594 |
|i| |
|
2595 |
||
2596 |
i := Image fromFile:'garfield.gif'. |
|
2597 |
i |
|
2598 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8) |
|
2599 |
ditherWidth:4 |
|
2600 |
" |
|
2601 |
||
2602 |
"thresholding at: 0.25 (all above 0.25 becomes white): |
|
2603 |
||
2604 |
|i| |
|
2605 |
||
2606 |
i := Image fromFile:'garfield.gif'. |
|
2607 |
i |
|
2608 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3) |
|
2609 |
ditherWidth:4 |
|
2610 |
" |
|
2611 |
||
2612 |
"thresholding at: 0.75 (all above 0.75 becomes white): |
|
2613 |
||
2614 |
|i| |
|
2615 |
||
2616 |
i := Image fromFile:'garfield.gif'. |
|
2617 |
i |
|
2618 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11) |
|
2619 |
ditherWidth:4 |
|
2620 |
" |
|
2621 |
||
2622 |
"Modified: 7.6.1996 / 17:23:47 / cg" |
|
2623 |
! |
|
2624 |
||
873 | 2625 |
asPseudoFormQuickOn:aDevice |
2626 |
"return a pseudo-deviceForm from the image. |
|
2627 |
Fail if colors are not fully available." |
|
2628 |
||
2629 |
|f d dDev temp temp8 bits anyMissing clr cMap idMap |
|
2630 |
nClr "{ Class: SmallInteger }" | |
|
2631 |
||
2632 |
d := self depth. |
|
2633 |
(d == 1 |
|
2634 |
or:[d == 2 |
|
2635 |
or:[d == 4 |
|
2636 |
or:[d == 8]]]) ifFalse:[^ nil]. |
|
2637 |
||
2638 |
"/ |
|
2639 |
"/ see if all of the images colors are representable |
|
2640 |
"/ on the device |
|
2641 |
||
2642 |
bits := self bitsPerPixel. |
|
2643 |
nClr := (1 bitShift:bits). |
|
2644 |
cMap := Array new:nClr. |
|
2645 |
idMap := ByteArray new:nClr. |
|
2646 |
||
2647 |
photometric == #palette ifTrue:[ |
|
2648 |
nClr := nClr min:(colorMap size) |
|
2649 |
]. |
|
2650 |
||
2651 |
1 to:nClr do:[:pixel | |
|
2652 |
clr := self colorFromValue:pixel-1. |
|
2653 |
clr := clr exactOn:aDevice. |
|
2654 |
clr isNil ifTrue:[^ nil]. |
|
2655 |
||
2656 |
cMap at:(pixel) put:clr. |
|
2657 |
idMap at:(pixel) put:(clr colorId). |
|
2658 |
]. |
|
2659 |
||
2660 |
"/ got all colors; good - simply change depth & translate pixels |
|
2661 |
||
2662 |
dDev := aDevice depth. |
|
2663 |
||
2664 |
(d == 8 and:[dDev == 8]) ifTrue:[ |
|
2665 |
"/ only translate |
|
2666 |
temp := ByteArray uninitializedNew:(width * height). |
|
2667 |
bytes expandPixels:8 "xlate only" |
|
2668 |
width:width |
|
2669 |
height:height |
|
2670 |
into:temp |
|
2671 |
mapping:idMap. |
|
2672 |
] ifFalse:[ |
|
2673 |
||
2674 |
"/ stupid: expandPixels can only handle any-to-8 |
|
2675 |
"/ compressPixels can only handle 8-to-any |
|
2676 |
||
2677 |
d ~~ 8 ifTrue:[ |
|
2678 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
2679 |
||
2680 |
bytes expandPixels:d |
|
2681 |
width:width |
|
2682 |
height:height |
|
2683 |
into:temp8 |
|
2684 |
mapping:idMap. |
|
2685 |
idMap := nil. |
|
2686 |
] ifFalse:[ |
|
2687 |
temp8 := bytes. |
|
2688 |
]. |
|
2689 |
||
2690 |
dDev ~~ 8 ifTrue:[ |
|
2691 |
temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height). |
|
2692 |
||
2693 |
temp8 compressPixels:dDev |
|
2694 |
width:width |
|
2695 |
height:height |
|
2696 |
into:temp |
|
2697 |
mapping:idMap. |
|
2698 |
] ifFalse:[ |
|
2699 |
temp := temp8 |
|
2700 |
]. |
|
2701 |
]. |
|
2702 |
||
2703 |
f := Form width:width height:height depth:dDev on:aDevice. |
|
2704 |
f isNil ifTrue:[^ nil]. |
|
2705 |
||
2706 |
f colorMap:cMap. |
|
2707 |
f initGC. |
|
2708 |
||
2709 |
aDevice |
|
2710 |
drawBits:temp |
|
2711 |
depth:dDev |
|
2712 |
width:width |
|
2713 |
height:height |
|
2714 |
x:0 y:0 |
|
2715 |
into:(f id) x:0 y:0 |
|
2716 |
width:width |
|
2717 |
height:height |
|
2718 |
with:(f gcId). |
|
2719 |
||
2720 |
^ f |
|
2721 |
||
2722 |
" |
|
2723 |
( |
|
2724 |
(((Depth4Image |
|
2725 |
width:4 |
|
2726 |
height:4 |
|
2727 |
fromArray:#[ |
|
2728 |
16r01 16r23 |
|
2729 |
16r45 16r67 |
|
2730 |
16r89 16rab |
|
2731 |
16rcd 16ref |
|
2732 |
])) |
|
2733 |
magnifiedBy:30 |
|
2734 |
) |
|
2735 |
asPseudoFormQuickOn:Display |
|
2736 |
) inspect |
|
2737 |
" |
|
2738 |
||
2739 |
"Modified: 17.6.1996 / 11:39:55 / cg" |
|
2740 |
! |
|
2741 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2742 |
asStevensonArceDitheredMonochromeImage |
837 | 2743 |
"return a stevenson-arce dithered monochrome image from the receiver image. |
2744 |
Depending on the images contents, this may or may not look better than |
|
2745 |
a floyd-steinberg dithered image. |
|
2746 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
2747 |
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
|
2748 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2749 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2750 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2751 |
monoBits := self stevensonArceDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2752 |
^ (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
|
2753 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2754 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2755 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2756 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2757 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2758 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2759 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2760 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2761 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2762 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2763 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2764 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2765 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2766 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2767 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2768 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2769 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2770 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2771 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2772 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2773 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2774 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2775 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2776 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2777 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2778 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2779 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2780 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2781 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2782 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2783 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2784 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2785 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2786 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2787 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2788 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2789 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2790 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2791 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2792 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2793 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2794 |
"Created: 10.6.1996 / 12:38:29 / cg" |
837 | 2795 |
"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
|
2796 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2797 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2798 |
asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2799 |
"return a thresholded grey form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2800 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2801 |
|depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2802 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2803 |
(depth := aDevice depth) == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2804 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2805 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2806 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2807 |
^ self |
816 | 2808 |
makeDeviceGrayPixmapOn:aDevice |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2809 |
depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2810 |
fromArray:(self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2811 |
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
|
2812 |
ditherWidth:4 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2813 |
depth:depth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2814 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2815 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2816 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2817 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2818 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2819 |
(i asThresholdGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2820 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2821 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2822 |
"Created: 10.6.1996 / 18:38:31 / cg" |
816 | 2823 |
"Modified: 10.6.1996 / 20:10:26 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2824 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2825 |
|
798 | 2826 |
asThresholdGrayImageDepth:depth |
2827 |
"return a thresholded depth-x grey image from the receiver image." |
|
2828 |
||
800 | 2829 |
depth == 1 ifTrue:[ |
2830 |
"/ for monochrome, there is highly specialized |
|
2831 |
"/ monochrome dither code available |
|
2832 |
||
2833 |
^ Depth1Image |
|
2834 |
width:width |
|
2835 |
height:height |
|
2836 |
fromArray:( |
|
2837 |
self |
|
2838 |
orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2839 |
ditherWidth:4) |
|
2840 |
]. |
|
2841 |
||
798 | 2842 |
^ (self class implementorForDepth:depth) |
2843 |
width:width |
|
2844 |
height:height |
|
2845 |
fromArray:( |
|
2846 |
self |
|
2847 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2848 |
ditherWidth:4 |
|
2849 |
depth:depth) |
|
2850 |
||
2851 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2852 |
|i| |
798 | 2853 |
|
2854 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2855 |
(i asThresholdGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2856 |
(i asThresholdGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2857 |
(i asThresholdGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2858 |
(i asThresholdGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2859 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2860 |
(i asOrderedDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2861 |
(i asOrderedDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2862 |
(i asOrderedDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2863 |
(i asOrderedDitheredGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2864 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2865 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2866 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2867 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2868 |
(i asFloydSteinbergDitheredGrayImageDepth:8) inspect. |
798 | 2869 |
" |
2870 |
||
2871 |
"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
|
2872 |
"Modified: 10.6.1996 / 14:20:56 / cg" |
798 | 2873 |
! |
2874 |
||
2875 |
asThresholdMonochromeFormOn:aDevice |
|
2876 |
"return a threshold monochrome form from the image." |
|
2877 |
||
2878 |
^ self |
|
2879 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2880 |
ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2881 |
ditherWidth:4 |
|
2882 |
||
2883 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2884 |
|i| |
798 | 2885 |
|
2886 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2887 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2888 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2889 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2890 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2891 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2892 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2893 |
i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2894 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2895 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2896 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2897 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2898 |
|i| |
798 | 2899 |
|
2900 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2901 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2902 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2903 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2904 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2905 |
|i| |
798 | 2906 |
|
2907 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2908 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2909 |
(i asThresholdMonochromeFormOn:Display) inspect |
798 | 2910 |
" |
2911 |
||
2912 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2913 |
"Modified: 10.6.1996 / 17:44:29 / cg" |
798 | 2914 |
! |
2915 |
||
2916 |
asThresholdMonochromeImage |
|
2917 |
"return a threshold monochrome image from the image. |
|
2918 |
Threshold means: brightness < 0.5 -> black / otherwise white" |
|
2919 |
||
2920 |
^ self |
|
2921 |
asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2922 |
ditherWidth:4 |
|
2923 |
||
2924 |
" |
|
2925 |
|i i2| |
|
2926 |
||
2927 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2928 |
i2 := i asThresholdMonochromeImage |
|
2929 |
||
2930 |
||
2931 |
|i i2| |
|
2932 |
||
2933 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2934 |
i2 := i asThresholdMonochromeImage |
|
2935 |
||
2936 |
||
2937 |
|i i2| |
|
2938 |
||
2939 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
2940 |
i2 := i asThresholdMonochromeImage |
|
2941 |
||
2942 |
||
2943 |
|i i2| |
|
2944 |
||
2945 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2946 |
i2 := i asThresholdMonochromeImage |
|
2947 |
" |
|
2948 |
||
2949 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
2950 |
"Modified: 7.6.1996 / 17:16:10 / cg" |
|
2951 |
! |
|
2952 |
||
808 | 2953 |
asThresholdMonochromeImage:thresholdBrighness |
2954 |
"return a threshold monochrome image from the image. |
|
2955 |
The argument (0..1) gives the threshold value; |
|
2956 |
Threshold means: brightness < threshold -> black / otherwise white" |
|
2957 |
||
2958 |
|value ditherMatrix| |
|
2959 |
||
2960 |
value := thresholdBrighness * 255. |
|
2961 |
ditherMatrix := ByteArray new:256 withAll:(value truncated). |
|
2962 |
||
2963 |
^ self |
|
2964 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix |
|
2965 |
ditherWidth:16 |
|
2966 |
||
2967 |
" |
|
2968 |
|i| |
|
2969 |
||
2970 |
i := Image width:4 height:4 depth:4 |
|
2971 |
fromArray:#[ 16r01 16r23 |
|
2972 |
16r45 16r67 |
|
2973 |
16r89 16rab |
|
2974 |
16rcd 16ref ]. |
|
2975 |
i := i magnifiedBy:30. |
|
2976 |
i inspect. |
|
2977 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
2978 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
2979 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
2980 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
2981 |
(i asThresholdMonochromeImage:1) inspect. |
|
2982 |
" |
|
2983 |
||
2984 |
" |
|
2985 |
|i| |
|
2986 |
||
2987 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2988 |
i inspect. |
|
2989 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
2990 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
2991 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
2992 |
(i asThresholdMonochromeImage:0.625) inspect. |
|
2993 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
2994 |
" |
|
2995 |
||
2996 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
2997 |
"Modified: 8.6.1996 / 14:51:57 / cg" |
|
2998 |
! |
|
2999 |
||
283 | 3000 |
fromForm:aForm |
592 | 3001 |
"setup the receiver from a form" |
283 | 3002 |
|
3003 |
|map c0 c1| |
|
3004 |
||
3005 |
width := aForm width. |
|
3006 |
height := aForm height. |
|
3007 |
bytes := aForm bits. |
|
3008 |
bitsPerSample := self bitsPerSample. |
|
3009 |
samplesPerPixel := self samplesPerPixel. |
|
3010 |
map := aForm colorMap. |
|
3011 |
||
3012 |
aForm depth == 1 ifTrue:[ |
|
592 | 3013 |
map isNil ifTrue:[ |
3014 |
photometric := #whiteIs0 |
|
3015 |
] ifFalse:[ |
|
3016 |
c0 := map at:1. |
|
3017 |
c1 := map at:2. |
|
3018 |
((c0 = Color white) |
|
3019 |
and:[c1 = Color black]) ifTrue:[ |
|
3020 |
photometric := #whiteIs0 |
|
3021 |
] ifFalse:[ |
|
3022 |
((c0 = Color black) |
|
3023 |
and:[c1 = Color white]) ifTrue:[ |
|
3024 |
photometric := #blackIs0 |
|
3025 |
] ifFalse:[ |
|
3026 |
photometric := #palette. |
|
3027 |
colorMap := Array with:c0 with:c1. |
|
3028 |
] |
|
3029 |
] |
|
3030 |
] |
|
283 | 3031 |
] ifFalse:[ |
592 | 3032 |
map notNil ifTrue:[ |
3033 |
photometric := #palette. |
|
3034 |
colorMap := map copy. |
|
3035 |
] ifFalse:[ |
|
3036 |
" |
|
3037 |
photometric stays at default |
|
3038 |
(which is rgb for d24, greyscale for others) |
|
3039 |
" |
|
3040 |
] |
|
283 | 3041 |
]. |
592 | 3042 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3043 |
"Modified: 8.6.1996 / 16:02:03 / cg" |
283 | 3044 |
! |
3045 |
||
89 | 3046 |
fromImage:anImage |
3047 |
"setup the receiver from another image. |
|
3048 |
Color precision may be lost, if conversion is from a higher depth |
|
191 | 3049 |
image. |
3050 |
WARNING: |
|
3051 |
This implementation is a slow fallback (the loop over the |
|
89 | 3052 |
source pixels is very slow). If this method is used heavily, you |
3053 |
may want to redefine it in concrete subclasses for common source images." |
|
3054 |
||
3055 |
width := anImage width. |
|
3056 |
height := anImage height. |
|
3057 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3058 |
bitsPerSample := self bitsPerSample. |
|
3059 |
samplesPerPixel := self samplesPerPixel. |
|
191 | 3060 |
self colormapFromImage:anImage. |
89 | 3061 |
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr | |
798 | 3062 |
self atX:x y:y put:clr |
89 | 3063 |
]. |
3064 |
||
3065 |
" |
|
798 | 3066 |
|i i2 i4 i8 i16 i24| |
89 | 3067 |
|
3068 |
i := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
3069 |
i inspect. |
|
3070 |
i2 := Depth2Image fromImage:i. |
|
3071 |
i2 inspect. |
|
3072 |
i4 := Depth4Image fromImage:i. |
|
3073 |
i4 inspect. |
|
3074 |
i8 := Depth8Image fromImage:i. |
|
3075 |
i8 inspect. |
|
3076 |
i24 := Depth24Image fromImage:i. |
|
3077 |
i24 inspect. |
|
3078 |
" |
|
191 | 3079 |
|
3080 |
"Created: 20.9.1995 / 00:59:03 / claus" |
|
798 | 3081 |
"Modified: 7.6.1996 / 16:23:03 / cg" |
191 | 3082 |
! |
3083 |
||
3084 |
fromSubImage:anImage in:aRectangle |
|
3085 |
"setup the receiver from another image, extracting a rectangular |
|
3086 |
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
|
3087 |
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
|
3088 |
represented. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3089 |
|
191 | 3090 |
WARNING: |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3091 |
This implementation is a slow fallback (the loop over the |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3092 |
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
|
3093 |
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
|
3094 |
of creating a subImage with the same depth & palette." |
191 | 3095 |
|
3096 |
|x0 y0| |
|
3097 |
||
3098 |
width := aRectangle width + 1. |
|
3099 |
height := aRectangle height + 1. |
|
3100 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3101 |
bitsPerSample := self bitsPerSample. |
|
3102 |
samplesPerPixel := self samplesPerPixel. |
|
3103 |
self colormapFromImage:anImage. |
|
3104 |
x0 := aRectangle left. |
|
3105 |
y0 := aRectangle top. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3106 |
|
191 | 3107 |
((photometric == anImage photometric) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3108 |
and:[self bitsPerPixel = anImage bitsPerPixel |
191 | 3109 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3110 |
"/ can do it by value |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3111 |
anImage valuesFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3112 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3113 |
do:[:x :y :pixelValue | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3114 |
self atX:x-x0 y:y-y0 putValue:pixelValue. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3115 |
] |
191 | 3116 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3117 |
"/ must do it by colors |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3118 |
anImage colorsFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3119 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3120 |
do:[:x :y :clr | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3121 |
self atX:x-x0 y:y-y0 put:clr. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3122 |
] |
191 | 3123 |
]. |
3124 |
||
3125 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3126 |
|i i2 i4 i8 i16 i24| |
191 | 3127 |
|
3128 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3129 |
i inspect. |
|
3130 |
i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200). |
|
3131 |
i4 inspect. |
|
3132 |
i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200). |
|
3133 |
i8 inspect. |
|
3134 |
i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200). |
|
3135 |
i24 inspect. |
|
3136 |
" |
|
3137 |
||
3138 |
"Created: 20.9.1995 / 01:06:02 / claus" |
|
3139 |
"Modified: 20.9.1995 / 10:15:37 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3140 |
"Modified: 10.6.1996 / 18:30:17 / cg" |
89 | 3141 |
! |
3142 |
||
283 | 3143 |
monochromeOn:aDevice |
3144 |
"return a monochrome device image of the receiver for aDevice. |
|
3145 |
(monochrome, even if device supports colors)" |
|
3146 |
||
3147 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self]. |
|
3148 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
|
3149 |
"oops, I am already accociated to another device |
|
3150 |
- need a copy ... |
|
3151 |
" |
|
3152 |
^ self copy monochromeOn:aDevice |
|
3153 |
]. |
|
3154 |
monoDeviceForm := self asMonochromeFormOn:aDevice. |
|
3155 |
! |
|
3156 |
||
3157 |
on:aDevice |
|
3158 |
"return an image with the same pixels as the receiver, but |
|
3159 |
associated to aDevice. If the receiver is not yet bound to |
|
3160 |
a device, this will be the receiver. Otherwise, a new image |
|
3161 |
is returned." |
|
3162 |
||
3163 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self]. |
|
852 | 3164 |
|
283 | 3165 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
852 | 3166 |
"oops, I am already accociated to another device |
3167 |
- need a copy ... |
|
3168 |
" |
|
3169 |
^ self copy on:aDevice |
|
283 | 3170 |
]. |
3171 |
deviceForm := self asFormOn:aDevice. |
|
3172 |
device := aDevice |
|
852 | 3173 |
|
3174 |
"Modified: 14.6.1996 / 15:28:30 / cg" |
|
283 | 3175 |
! ! |
3176 |
||
3177 |
!Image methodsFor:'converting greyscale images'! |
|
3178 |
||
3179 |
greyImageAsFormOn:aDevice |
|
3180 |
"return a thresholded grey-deviceForm from the grey image." |
|
3181 |
||
3182 |
|pictureDepth nPlanes f| |
|
3183 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3184 |
|
283 | 3185 |
nPlanes := samplesPerPixel. |
3186 |
(nPlanes == 2) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3187 |
'IMAGE: alpha plane ignored' errorPrintNL. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3188 |
nPlanes := 1 |
283 | 3189 |
]. |
3190 |
||
3191 |
pictureDepth := bitsPerSample at:1. |
|
3192 |
||
3193 |
"monochrome is very easy ..." |
|
3194 |
||
3195 |
(pictureDepth == 1) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3196 |
^ Form width:width height:height fromArray:bytes on:aDevice |
283 | 3197 |
]. |
3198 |
||
3199 |
(aDevice visualType == #TrueColor) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3200 |
^ self greyImageAsTrueColorFormOn:aDevice |
283 | 3201 |
]. |
3202 |
||
858 | 3203 |
"/ (aDevice visualType == #PseudoColor |
3204 |
"/ or:[aDevice visualType == #GrayScale |
|
3205 |
"/ or:[aDevice visualType == #StaticColor]]) ifTrue:[ |
|
3206 |
||
3207 |
"/ PseudoColor conversion also works for StaticColor, |
|
3208 |
"/ GrayScale and DirectColor; although possibly with suboptimal results |
|
3209 |
||
3210 |
^ self greyImageAsPseudoFormOn:aDevice |
|
3211 |
||
3212 |
"Modified: 14.6.1996 / 19:32:01 / cg" |
|
283 | 3213 |
! |
3214 |
||
3215 |
greyImageAsPseudoFormOn:aDevice |
|
3216 |
"return an 8-bit pseudo Form from the grey image" |
|
3217 |
||
3218 |
|wideBits pictureDepth f map |
|
3219 |
colorMap usedColors nUsed aColor |
|
3220 |
nColors "{ Class: SmallInteger }" |
|
3221 |
range id| |
|
3222 |
||
3223 |
pictureDepth := bitsPerSample at:1. |
|
3224 |
||
3225 |
(#(2 4 8) includes:pictureDepth) ifFalse:[ |
|
746 | 3226 |
self error:'currently only depth-2, 4 or 8 supported'. |
3227 |
^ nil |
|
283 | 3228 |
]. |
3229 |
||
3230 |
wideBits := ByteArray uninitializedNew:(width * height). |
|
3231 |
||
3232 |
(pictureDepth == 8) ifTrue:[ |
|
746 | 3233 |
"for 8bits, we scan for used colors first; |
3234 |
to avoid allocating too many colors" |
|
3235 |
||
3236 |
usedColors := bytes usedValues. |
|
3237 |
nUsed := usedColors max + 1. |
|
3238 |
||
3239 |
colorMap := Array new:nUsed. |
|
3240 |
photometric == #blackIs0 ifTrue:[ |
|
3241 |
usedColors do:[:grey | |
|
3242 |
colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey)) |
|
3243 |
] |
|
3244 |
] ifFalse:[ |
|
3245 |
usedColors do:[:grey | |
|
3246 |
colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey))) |
|
3247 |
] |
|
3248 |
] |
|
89 | 3249 |
] ifFalse:[ |
746 | 3250 |
nColors := (1 bitShift:pictureDepth). |
3251 |
colorMap := Array new:nColors. |
|
3252 |
range := 100 / (nColors - 1) asFloat. |
|
3253 |
photometric == #blackIs0 ifTrue:[ |
|
3254 |
1 to:nColors do:[:i | |
|
3255 |
colorMap at:i put:(Color gray:(i - 1) * range). |
|
3256 |
]. |
|
3257 |
] ifFalse:[ |
|
3258 |
1 to:nColors do:[:i | |
|
3259 |
colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range). |
|
3260 |
]. |
|
3261 |
]. |
|
283 | 3262 |
]. |
3263 |
||
3264 |
"XXX should reduce 8->6->4->2 planes, if not all colors could be allocated" |
|
3265 |
||
3266 |
"setup the translation map" |
|
3267 |
map := ByteArray uninitializedNew:256. |
|
3268 |
nColors := colorMap size. |
|
3269 |
1 to:nColors do:[:i | |
|
746 | 3270 |
aColor := colorMap at:i. |
3271 |
aColor notNil ifTrue:[ |
|
3272 |
aColor := aColor on:aDevice. |
|
3273 |
colorMap at:i put:aColor. |
|
3274 |
id := aColor colorId. |
|
3275 |
id notNil ifTrue:[ |
|
3276 |
map at:i put:id |
|
3277 |
] ifFalse:[ |
|
3278 |
map at:i put:0 |
|
3279 |
] |
|
3280 |
] |
|
89 | 3281 |
]. |
283 | 3282 |
|
3283 |
"expand & translate" |
|
3284 |
bytes expandPixels:pictureDepth |
|
746 | 3285 |
width:width |
3286 |
height:height |
|
3287 |
into:wideBits |
|
3288 |
mapping:map. |
|
283 | 3289 |
|
3290 |
f := Form width:width height:height depth:8 on:aDevice. |
|
3291 |
f isNil ifTrue:[^ nil]. |
|
3292 |
f colorMap:colorMap. |
|
3293 |
f initGC. |
|
3294 |
aDevice drawBits:wideBits depth:8 width:width height:height |
|
746 | 3295 |
x:0 y:0 |
3296 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
283 | 3297 |
^ f |
746 | 3298 |
|
3299 |
"Modified: 28.5.1996 / 20:55:57 / cg" |
|
0 | 3300 |
! |
3301 |
||
283 | 3302 |
greyImageAsTrueColorFormOn:aDevice |
3303 |
"return a true-color device-form for the grey-image receiver. |
|
3304 |
TODO: the pixel loops ought to be implemented as inline primitive code ..." |
|
3305 |
||
3306 |
|depth |
|
3307 |
myDepth "{ Class: SmallInteger }" |
|
3308 |
nColors "{ Class: SmallInteger }" |
|
3309 |
colorValues |
|
3310 |
scaleDown scaleRed scaleGreen scaleBlue redShift blueShift greenShift |
|
3311 |
form imageBitsdestIndex |
|
3312 |
bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits destIndex |
|
3313 |
nPixels| |
|
3314 |
||
3315 |
"/ this is a slow fallback method; this ought to be |
|
3316 |
"/ redefined in DepthxImage for more performance. |
|
3317 |
||
3318 |
depth := aDevice depth. |
|
3319 |
myDepth := self depth. |
|
3320 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3321 |
self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3322 |
^ nil |
0 | 3323 |
]. |
3324 |
||
283 | 3325 |
"/ compute scale to map from my pixels into devices range |
3326 |
||
3327 |
scaleDown := 1 bitShift:myDepth. |
|
3328 |
scaleRed := (1 bitShift:aDevice bitsRed). |
|
3329 |
scaleGreen := (1 bitShift:aDevice bitsGreen). |
|
3330 |
scaleBlue := (1 bitShift:aDevice bitsBlue). |
|
3331 |
redShift := aDevice shiftRed. |
|
3332 |
greenShift := aDevice shiftGreen. |
|
3333 |
blueShift := aDevice shiftBlue. |
|
3334 |
||
3335 |
nColors := (1 bitShift:myDepth). |
|
3336 |
colorValues := Array new:nColors. |
|
3337 |
1 to:nColors do:[:i | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3338 |
|v gv bv rv nv| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3339 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3340 |
"/ scale down to 0..1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3341 |
v := (i-1) / scaleDown. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3342 |
rv := (v * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3343 |
gv := (v * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3344 |
bv := (v * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3345 |
nv := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3346 |
nv := nv bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3347 |
nv := nv bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3348 |
colorValues at:i put:nv |
0 | 3349 |
]. |
283 | 3350 |
photometric == #whiteIs0 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3351 |
"/ reverse the order; 0 is brightest |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3352 |
colorValues reverse |
283 | 3353 |
]. |
193 | 3354 |
|
3355 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3356 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3357 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3358 |
|
283 | 3359 |
"/ for now, only support some depths |
3360 |
||
3361 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3362 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3363 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3364 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3365 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3366 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3367 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3368 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3369 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3370 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3371 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3372 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3373 |
imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3374 |
destIndex := destIndex + 2. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3375 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3376 |
] |
283 | 3377 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3378 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3379 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3380 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3381 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3382 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3383 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3384 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3385 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3386 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3387 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3388 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3389 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3390 |
imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3391 |
destIndex := destIndex + 4. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3392 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3393 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3394 |
] |
193 | 3395 |
]. |
3396 |
||
283 | 3397 |
imageBits isNil ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3398 |
'IMAGE: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3399 |
^ self asMonochromeFormOn:aDevice |
283 | 3400 |
]. |
3401 |
||
3402 |
form := |
|
193 | 3403 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
283 | 3404 |
form isNil ifTrue:[^ nil]. |
193 | 3405 |
form initGC. |
3406 |
||
3407 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3408 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3409 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3410 |
x:0 y:0 toX:0 y:0. |
193 | 3411 |
|
3412 |
^ form |
|
3413 |
||
283 | 3414 |
"Created: 20.10.1995 / 22:05:10 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3415 |
"Modified: 10.6.1996 / 19:15:13 / cg" |
0 | 3416 |
! ! |
3417 |
||
3418 |
!Image methodsFor:'converting palette images'! |
|
3419 |
||
3420 |
paletteImageAsFormOn:aDevice |
|
72 | 3421 |
"return a device-form for the palette-image receiver" |
3422 |
||
380 | 3423 |
|type ddepth| |
193 | 3424 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3425 |
ddepth := aDevice depth. |
379 | 3426 |
|
193 | 3427 |
((type := aDevice visualType) == #StaticGray) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3428 |
ddepth == 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3429 |
^ self paletteImageAsGray8FormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3430 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3431 |
^ self asGrayFormOn:aDevice |
0 | 3432 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3433 |
|
193 | 3434 |
(type == #TrueColor) ifTrue:[ |
854 | 3435 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
3436 |
ddepth == 8 ifTrue:[ |
|
3437 |
self depth == 8 ifTrue:[ |
|
3438 |
"/ use fixColor dither algorithm |
|
3439 |
^ self asDitheredTrueColor8FormOn:aDevice |
|
3440 |
] |
|
3441 |
] |
|
3442 |
]. |
|
3443 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3444 |
^ self paletteImageAsTrueColorFormOn:aDevice |
193 | 3445 |
]. |
858 | 3446 |
|
3447 |
"/ the PseudoColor conversion also works for |
|
3448 |
"/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results |
|
3449 |
||
3450 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
3451 |
||
3452 |
"Modified: 14.6.1996 / 19:31:01 / cg" |
|
0 | 3453 |
! |
3454 |
||
3455 |
paletteImageAsPseudoFormOn:aDevice |
|
72 | 3456 |
"return a pseudo-deviceForm from the palette image." |
0 | 3457 |
|
89 | 3458 |
|tempImage d temp8| |
3459 |
||
3460 |
d := self depth. |
|
3461 |
(#(1 2 4 8) includes:d) ifTrue:[ |
|
3462 |
" |
|
3463 |
fallback code for some depth's: |
|
3464 |
create a temporary Depth8Image and use its conversion method |
|
3465 |
" |
|
3466 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
3467 |
||
3468 |
bytes expandPixels:d |
|
3469 |
width:width |
|
3470 |
height:height |
|
3471 |
into:temp8 |
|
3472 |
mapping:nil. |
|
3473 |
||
3474 |
tempImage := Image width:width height:height depth:8 fromArray:temp8. |
|
3475 |
tempImage colorMap:colorMap. |
|
3476 |
^ tempImage paletteImageAsPseudoFormOn:aDevice |
|
3477 |
]. |
|
2 | 3478 |
^ self subclassResponsibility |
0 | 3479 |
! |
3480 |
||
193 | 3481 |
paletteImageAsTrueColorFormOn:aDevice |
3482 |
"return a true-color device-form for the palette-image receiver." |
|
3483 |
||
209 | 3484 |
|depth |
3485 |
myDepth "{ Class: SmallInteger }" |
|
3486 |
nColors "{ Class: SmallInteger }" |
|
3487 |
colorValues |
|
193 | 3488 |
scaleRed scaleGreen scaleBlue redShift greenShift blueShift |
194 | 3489 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
854 | 3490 |
destIndex| |
193 | 3491 |
|
3492 |
"/ this is a slow fallback method; this ought to be |
|
3493 |
"/ redefined in DepthxImage for more performance. |
|
3494 |
||
3495 |
depth := aDevice depth. |
|
3496 |
myDepth := self bitsPerPixel. |
|
3497 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3498 |
'IMAGE: depth > 12 not supported' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3499 |
^ nil |
193 | 3500 |
]. |
3501 |
||
3502 |
"/ gather r/g/b values for all colors in the map ... |
|
3503 |
||
3504 |
nColors := colorMap size. |
|
3505 |
||
3506 |
"/ precompute scales to map from 0..100 into devices range |
|
3507 |
"/ (this may be different for the individual components) |
|
3508 |
||
3509 |
scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100. |
|
3510 |
scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100. |
|
3511 |
scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100. |
|
3512 |
redShift := aDevice shiftRed. |
|
3513 |
greenShift := aDevice shiftGreen. |
|
3514 |
blueShift := aDevice shiftBlue. |
|
3515 |
||
3516 |
colorValues := Array uninitializedNew:nColors. |
|
3517 |
||
3518 |
1 to:nColors do:[:index | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3519 |
|clr rv gv bv v "{ Class: SmallInteger }" | |
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 |
clr := colorMap at:index. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3522 |
clr notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3523 |
rv := (clr red * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3524 |
gv := (clr green * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3525 |
bv := (clr blue * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3526 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3527 |
v := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3528 |
v := v bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3529 |
v := v bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3530 |
colorValues at:index put:v. |
193 | 3531 |
"/ clr print. ' ' print. |
3532 |
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print. |
|
3533 |
"/ ' -> ' print. v printNL. |
|
3534 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3535 |
] |
193 | 3536 |
]. |
3537 |
||
3538 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3539 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3540 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3541 |
|
3542 |
"/ for now, only support some depths |
|
3543 |
||
854 | 3544 |
"/ 16 bits/pixel |
3545 |
||
193 | 3546 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3547 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3548 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3549 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3550 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3551 |
|
854 | 3552 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3553 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3554 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3555 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3556 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3557 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3558 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3559 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3560 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3561 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3562 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3563 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3564 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3565 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3566 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3567 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3568 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3569 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3570 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3571 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3572 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3573 |
v = __intVal(clr); |
193 | 3574 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3575 |
((short *)dstPtr)[0] = v; |
193 | 3576 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3577 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3578 |
dstPtr[1] = (v) & 0xFF; |
193 | 3579 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3580 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3581 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3582 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3583 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3584 |
} |
193 | 3585 |
%}. |
3586 |
] ifFalse:[ |
|
854 | 3587 |
"/ 32 bits/pixel |
3588 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3589 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3590 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3591 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3592 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3593 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3594 |
|
854 | 3595 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3596 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3597 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3598 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3599 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3600 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3601 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3602 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3603 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3604 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3605 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3606 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3607 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3608 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3609 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3610 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3611 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3612 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3613 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3614 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3615 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3616 |
v = __intVal(clr); |
193 | 3617 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3618 |
((long *)dstPtr)[0] = v; |
193 | 3619 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3620 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3621 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3622 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3623 |
dstPtr[3] = (v) & 0xFF; |
193 | 3624 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3625 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3626 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3627 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3628 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3629 |
} |
193 | 3630 |
%}. |
854 | 3631 |
] ifFalse:[ |
3632 |
"/ 8 bits/pixel |
|
3633 |
||
3634 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
3635 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
3636 |
||
3637 |
"/ now, walk over the image and replace |
|
3638 |
"/ colorMap indices by color values in the bits array |
|
3639 |
||
3640 |
%{ |
|
3641 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
3642 |
&& __isArray(colorValues) |
|
3643 |
&& __isByteArray(_INST(bytes)) |
|
3644 |
&& (myDepth == __MKSMALLINT(8)) |
|
3645 |
&& __isByteArray(imageBits)) { |
|
3646 |
int x, y, w, h, nPix; |
|
3647 |
||
3648 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
3649 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
3650 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
|
3651 |
||
3652 |
w = __intVal(_INST(width)); |
|
3653 |
h = __intVal(_INST(height)); |
|
3654 |
nPix = w * h; |
|
3655 |
while (nPix > 0) { |
|
3656 |
unsigned idx, v; |
|
3657 |
OBJ clr; |
|
3658 |
||
3659 |
idx = *srcPtr; |
|
3660 |
clr = ap[idx]; |
|
3661 |
v = __intVal(clr); |
|
3662 |
||
3663 |
dstPtr[0] = v; |
|
3664 |
||
3665 |
dstPtr += 1; |
|
3666 |
srcPtr += 1; |
|
3667 |
nPix--; |
|
3668 |
} |
|
3669 |
} |
|
3670 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3671 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3672 |
] |
193 | 3673 |
]. |
3674 |
||
3675 |
imageBits isNil ifTrue:[ |
|
854 | 3676 |
'IMAGE: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintNL. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3677 |
^ self asMonochromeFormOn:aDevice |
193 | 3678 |
]. |
3679 |
||
3680 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
3681 |
form isNil ifTrue:[^ nil]. |
|
3682 |
form initGC. |
|
3683 |
||
3684 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3685 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3686 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3687 |
x:0 y:0 toX:0 y:0. |
193 | 3688 |
|
3689 |
^ form |
|
3690 |
||
3691 |
"Created: 20.10.1995 / 22:05:10 / cg" |
|
3692 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
|
0 | 3693 |
! ! |
3694 |
||
283 | 3695 |
!Image methodsFor:'converting rgb images'! |
3696 |
||
854 | 3697 |
asDitheredTrueColor8FormOn:aDevice |
3698 |
"convert an rgb image to a dithered depth8-form on aDevice. |
|
3699 |
Return the device-form." |
|
3700 |
||
3701 |
|fixColors pixel |
|
3702 |
dstIdx "{ Class: SmallInteger }" |
|
3703 |
shiftRed "{ Class: SmallInteger }" |
|
3704 |
shiftGreen "{ Class: SmallInteger }" |
|
3705 |
shiftBlue "{ Class: SmallInteger }" |
|
3706 |
nRed "{ Class: SmallInteger }" |
|
3707 |
nGreen "{ Class: SmallInteger }" |
|
3708 |
nBlue "{ Class: SmallInteger }"| |
|
3709 |
||
3710 |
shiftRed := aDevice shiftRed. |
|
3711 |
shiftGreen := aDevice shiftGreen. |
|
3712 |
shiftBlue := aDevice shiftBlue. |
|
3713 |
||
3714 |
nRed := (1 bitShift:aDevice bitsRed). |
|
3715 |
nGreen := (1 bitShift:aDevice bitsGreen). |
|
3716 |
nBlue := (1 bitShift:aDevice bitsBlue). |
|
3717 |
||
3718 |
fixColors := Array new:(nRed * nGreen * nBlue). |
|
3719 |
||
3720 |
dstIdx := 1. |
|
3721 |
0 to:nRed - 1 do:[:sR | |
|
3722 |
0 to:nGreen - 1 do:[:sG | |
|
3723 |
0 to:nBlue - 1 do:[:sB | |
|
3724 |
pixel := (sR bitShift:shiftRed) |
|
3725 |
+ (sG bitShift:shiftGreen) |
|
3726 |
+ (sB bitShift:shiftBlue). |
|
3727 |
fixColors at:dstIdx put:(Color colorId:(pixel)). |
|
3728 |
dstIdx := dstIdx + 1 |
|
3729 |
] |
|
3730 |
] |
|
3731 |
]. |
|
3732 |
||
3733 |
^ self |
|
3734 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
3735 |
colors:fixColors |
|
3736 |
nRed:nRed nGreen:nGreen nBlue:nBlue |
|
3737 |
||
3738 |
"Modified: 14.6.1996 / 17:18:57 / cg" |
|
3739 |
"Created: 14.6.1996 / 17:23:52 / cg" |
|
3740 |
! |
|
3741 |
||
283 | 3742 |
rgbImageAsFormOn:aDevice |
3743 |
"convert am rgb image to a device-form on aDevice. |
|
3744 |
Return the device-form." |
|
3745 |
||
3746 |
|visual| |
|
3747 |
||
3748 |
visual := aDevice visualType. |
|
3749 |
(visual == #StaticGray) ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3750 |
^ self asGrayFormOn:aDevice |
0 | 3751 |
]. |
283 | 3752 |
(visual == #TrueColor) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3753 |
^ self rgbImageAsTrueColorFormOn:aDevice |
0 | 3754 |
]. |
858 | 3755 |
|
3756 |
"/ PseudoColor conversion also works for StaticColor, GrayScale |
|
3757 |
"/ and DirectColor displays; although possibly with suboptimal results |
|
3758 |
||
283 | 3759 |
^ self rgbImageAsPseudoFormOn:aDevice |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3760 |
|
858 | 3761 |
"Modified: 14.6.1996 / 19:30:06 / cg" |
283 | 3762 |
! |
3763 |
||
3764 |
rgbImageAsPseudoFormOn:aDevice |
|
3765 |
"return a pseudocolor form from the rgb-picture" |
|
3766 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3767 |
|n "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3768 |
depth "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3769 |
palette f| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3770 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3771 |
(depth := self depth) <= 8 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3772 |
"/ 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
|
3773 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3774 |
palette := Array new:(1 bitShift:depth). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3775 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3776 |
n := (1 bitShift:depth)-1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3777 |
0 to:n do:[:pixelValue | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3778 |
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
|
3779 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3780 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3781 |
colorMap := palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3782 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3783 |
f := self paletteImageAsPseudoFormOn:aDevice. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3784 |
colorMap := nil. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3785 |
photometric := #rgb. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3786 |
^ f |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3787 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3788 |
|
283 | 3789 |
^ self subclassResponsibility |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3790 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3791 |
"Modified: 8.6.1996 / 10:58:25 / cg" |
283 | 3792 |
! |
3793 |
||
3794 |
rgbImageAsTrueColorFormOn:aDevice |
|
3795 |
"return a truecolor form from the rgb-picture." |
|
3796 |
||
3797 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
3798 |
form| |
|
193 | 3799 |
|
3800 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3801 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3802 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3803 |
|
854 | 3804 |
"/ 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
|
3805 |
usedDeviceBitsPerPixel == 15 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3806 |
usedDeviceBitsPerPixel := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3807 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3808 |
|
283 | 3809 |
"/ |
3810 |
"/ only the trivial case, where the depths match |
|
3811 |
"/ is handled here; conversions are supposed to |
|
3812 |
"/ be done in concrete subclasses (see D24Image) |
|
3813 |
"/ |
|
3814 |
self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[ |
|
854 | 3815 |
'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
|
3816 |
^ self asMonochromeFormOn:aDevice |
193 | 3817 |
]. |
3818 |
||
283 | 3819 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
3820 |
form isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3821 |
'IMAGE: display bitmap creation failed' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3822 |
^ nil |
193 | 3823 |
]. |
3824 |
form initGC. |
|
3825 |
||
3826 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3827 |
copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3828 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3829 |
x:0 y:0 toX:0 y:0. |
193 | 3830 |
|
3831 |
^ form |
|
3832 |
||
854 | 3833 |
"Modified: 14.6.1996 / 16:57:47 / cg" |
283 | 3834 |
! ! |
3835 |
||
3836 |
!Image methodsFor:'copying'! |
|
3837 |
||
3838 |
postCopy |
|
592 | 3839 |
"redefined to also copy the pixels and the colorMap |
3840 |
and clear out any device handles in the copy." |
|
3841 |
||
283 | 3842 |
bytes := bytes copy. |
3843 |
colorMap := colorMap deepCopy. |
|
3844 |
device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil |
|
592 | 3845 |
|
3846 |
"Modified: 23.4.1996 / 11:12:03 / cg" |
|
283 | 3847 |
! ! |
3848 |
||
3849 |
!Image methodsFor:'displaying'! |
|
3850 |
||
758 | 3851 |
displayFilledOn:aGC |
759 | 3852 |
"display the receiver as an opaque image. |
758 | 3853 |
This allows Images to be wrapped by a FillingWrapper" |
3854 |
||
3855 |
aGC displayOpaqueForm:self x:0 y:0. |
|
3856 |
||
3857 |
"Created: 29.5.1996 / 10:34:18 / cg" |
|
759 | 3858 |
"Modified: 29.5.1996 / 10:52:36 / cg" |
758 | 3859 |
! |
3860 |
||
283 | 3861 |
displayOn:aGC at:aPoint |
592 | 3862 |
"draw the receiver in the graphicsContext, aGC. |
283 | 3863 |
Smalltalk-80 compatibility" |
3864 |
||
672 | 3865 |
self displayOn:aGC x:aPoint x y:aPoint y. |
3866 |
||
3867 |
"Modified: 12.5.1996 / 20:16:38 / cg" |
|
3868 |
! |
|
3869 |
||
3870 |
displayOn:aGC x:x y:y |
|
3871 |
"draw the receiver in the graphicsContext, aGC. |
|
3872 |
Smalltalk-80 compatibility" |
|
3873 |
||
3874 |
aGC displayForm:self x:x y:y. |
|
592 | 3875 |
|
3876 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
|
672 | 3877 |
"Created: 12.5.1996 / 20:14:31 / cg" |
758 | 3878 |
! |
3879 |
||
3880 |
displayStrokedOn:aGC |
|
759 | 3881 |
"display the receiver as an non opaque image. |
758 | 3882 |
This allows Images to be wrapped by a StrokingWrapper" |
3883 |
||
3884 |
aGC displayForm:self x:0 y:0. |
|
3885 |
||
759 | 3886 |
"Created: 29.5.1996 / 10:34:18 / cg" |
3887 |
"Modified: 29.5.1996 / 10:52:30 / cg" |
|
283 | 3888 |
! ! |
3889 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3890 |
!Image methodsFor:'dither helpers'! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3891 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3892 |
burkesDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3893 |
"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
|
3894 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3895 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3896 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3897 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3898 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3899 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3900 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3901 |
errorArray1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3902 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3903 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3904 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3905 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3906 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3907 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3908 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3909 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3910 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3911 |
^ self floydSteinbergDitheredMonochromeBits |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3914 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3915 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3916 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3917 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3918 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3919 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3920 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3921 |
]. |
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 |
errorArray := Array new:(w+4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3924 |
errorArray1 := Array new:(w+4) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3925 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3926 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3927 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3928 |
"/ 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
|
3929 |
"/ use table-value in loop |
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 |
greyValues := self greyMapForRange:(255*1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3932 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3933 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3934 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3935 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3936 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3937 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3938 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3939 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3940 |
errorArray1 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3941 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3942 |
errorArray1 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3943 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3944 |
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
|
3945 |
|eP "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3946 |
eD |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3947 |
eI "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3948 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3949 |
xN "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3950 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3951 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3952 |
grey := greyValues at:(pixel + 1). |
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 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3955 |
xE := x + 2 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3956 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3957 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3958 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3959 |
grey > (127*1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3960 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3961 |
e := grey - (255*1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3962 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3963 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3964 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3965 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3966 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3967 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3968 |
"/ XX 8 4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3969 |
"/ 2 4 8 4 2 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3970 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3971 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3972 |
eI := e // 32. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3973 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3974 |
eP := eI * 8. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3975 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3976 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3977 |
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
|
3978 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3979 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3980 |
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
|
3981 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3982 |
eP := eI * 4. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3983 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3984 |
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
|
3985 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3986 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3987 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3988 |
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
|
3989 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3990 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3991 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3992 |
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
|
3993 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3994 |
eP := eI * 2. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3995 |
xN := xE - 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3996 |
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
|
3997 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3998 |
eD := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3999 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4000 |
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
|
4001 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4002 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4003 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4004 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4005 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4006 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4007 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4008 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4009 |
]. |
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 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4012 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4013 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4014 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4015 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4016 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4017 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4018 |
]. |
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 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4021 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4022 |
"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
|
4023 |
"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
|
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 |
floydSteinbergDitheredBitsDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4027 |
"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
|
4028 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4029 |
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
|
4030 |
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
|
4031 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4032 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4033 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4034 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4035 |
outBits greyValues greyErrors greyPixels greyLevels |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4036 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4037 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4038 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4039 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4040 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4041 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4042 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4043 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4044 |
eR eRB eB eLB | |
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 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4047 |
self error:'unimplemented conversion'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4048 |
^ nil |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4051 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4052 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4053 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4054 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4055 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4056 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4057 |
^ nil |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4060 |
greyLevels := (1 bitShift:depth) - 1. |
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 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4063 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4064 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4065 |
nextErrorArray atAllPut:0. |
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 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4068 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4069 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4070 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4071 |
"/ 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
|
4072 |
"/ use table-value in loop |
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 |
greyValues := self greyMapForRange:(greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4075 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4076 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4077 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4078 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4079 |
v truncated]]. |
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 |
greyPixels := ByteArray withAll:greyPixels. |
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 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4084 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4085 |
] ifFalse:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4086 |
((v - v truncated) * 1024) truncated |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4087 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4088 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4089 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4090 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4091 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4092 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4093 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4094 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4095 |
nextErrorArray := t. |
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 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4098 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4099 |
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
|
4100 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4101 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4102 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4103 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4104 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4105 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4106 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4107 |
pixel := greyPixels at:(value + 1). |
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 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4110 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4111 |
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
|
4112 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4113 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4114 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4115 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4116 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4117 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4118 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4119 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4120 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4121 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4122 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4123 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4124 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4125 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4126 |
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
|
4127 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4128 |
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
|
4129 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4130 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4131 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4132 |
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
|
4133 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4134 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4135 |
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
|
4136 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4137 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4138 |
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
|
4139 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4140 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4141 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4142 |
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
|
4143 |
]. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4146 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4147 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4148 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4149 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4150 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4151 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4152 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4153 |
|
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 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4156 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4157 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4158 |
bitCnt := 8. |
809
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 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4162 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4163 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4164 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4165 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4166 |
byte := 0. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4169 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4170 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4171 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4172 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4173 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4174 |
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
|
4175 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4176 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4177 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4178 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4179 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4180 |
xN "{ Class: SmallInteger }" | |
809
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 |
grey := (clr brightness * greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4183 |
pixel := grey truncated. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4184 |
error := ((grey - pixel) * 1024) truncated. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4185 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4186 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4187 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4188 |
error := error + (errorArray at:xE). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4189 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4190 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4191 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4192 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4193 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4194 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4195 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4196 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4197 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4198 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4199 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4200 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4201 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4202 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4203 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4204 |
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
|
4205 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4206 |
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
|
4207 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4208 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4209 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4210 |
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
|
4211 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4212 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4213 |
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
|
4214 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4215 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4216 |
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
|
4217 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4218 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4219 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4220 |
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
|
4221 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4222 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4223 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4224 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4225 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4226 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4227 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4228 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4229 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4230 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4231 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4232 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4233 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4234 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4235 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4236 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4237 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4238 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4239 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4240 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4241 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4242 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4243 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4244 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4245 |
"Created: 10.6.1996 / 13:28:22 / cg" |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4246 |
"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
|
4247 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4248 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4249 |
floydSteinbergDitheredDepth8BitsColors:colors |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4250 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4251 |
which must be a depth-8 image. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4252 |
This method expects an array of colors to be used for dithering |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4253 |
(which need not be a colorCubes colors)." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4254 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4255 |
|pseudoBits |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4256 |
rgbBytes ditherRGBBytes ditherColors |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4257 |
w "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4258 |
h "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4259 |
index "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4260 |
fixR "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4261 |
fixG "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4262 |
fixB "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4263 |
ditherIds failed map lastColor |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4264 |
error clr| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4265 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4266 |
self depth ~~ 8 ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4267 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4268 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4269 |
"/ collect color components as integer values (for integer arithmetic) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4270 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4271 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4272 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4273 |
photometric == #palette ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4274 |
lastColor := colorMap size - 1 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4275 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4276 |
lastColor := 255. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4277 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4278 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4279 |
0 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4280 |
clr := self colorFromValue:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4281 |
rgbBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4282 |
rgbBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4283 |
rgbBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4284 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4285 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4286 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4287 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4288 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4289 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4290 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4291 |
ditherColors := colors select:[:clr | clr notNil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4292 |
ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4293 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4294 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4295 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4296 |
lastColor := ditherColors size. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4297 |
ditherIds := ByteArray uninitializedNew:lastColor. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4298 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4299 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4300 |
1 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4301 |
clr := ditherColors at:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4302 |
ditherRGBBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4303 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4304 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4305 |
ditherIds at:pix put:clr colorId. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4306 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4307 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4308 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4309 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4310 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4311 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4312 |
w := width + 2. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4313 |
error := ByteArray uninitializedNew:w*(3*2). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4314 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4315 |
w := width. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4316 |
h := height. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4317 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4318 |
failed := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4319 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4320 |
%{ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4321 |
int __x, __y; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4322 |
int __eR, __eG, __eB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4323 |
unsigned char *srcP, *dstP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4324 |
unsigned char *rgbP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4325 |
unsigned char *idP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4326 |
unsigned char *dp; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4327 |
short *errP, *eP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4328 |
int __fR, __fG, __fB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4329 |
int iR, iG, iB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4330 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4331 |
int __w = __intVal(w); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4332 |
int __nColors = __intVal(lastColor); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4333 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4334 |
if (__isByteArray(__INST(bytes)) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4335 |
&& __isByteArray(pseudoBits) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4336 |
&& __isByteArray(rgbBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4337 |
&& __isByteArray(ditherRGBBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4338 |
&& __isByteArray(ditherIds) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4339 |
&& __isByteArray(error)) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4340 |
failed = false; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4341 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4342 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4343 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4344 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4345 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4346 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4347 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4348 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4349 |
* clear error accumulator |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4350 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4351 |
eP = errP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4352 |
bzero(eP, (__w+2) * 2 * 3); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4353 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4354 |
for (__y=__intVal(h); __y>0; __y--) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4355 |
__eR = __eG = __eB = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4356 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4357 |
eP = &(errP[3]); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4358 |
__eR = eP[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4359 |
__eG = eP[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4360 |
__eB = eP[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4361 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4362 |
for (__x=__w; __x>0; __x--) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4363 |
int __want; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4364 |
int pix; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4365 |
int __wantR, __wantG, __wantB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4366 |
int __wR, __wG, __wB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4367 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4368 |
int tR, tG, tB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4369 |
int nR, nG, nB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4370 |
int dR, dG, dB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4371 |
int minDelta, bestIdx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4372 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4373 |
pix = *srcP++; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4374 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4375 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4376 |
* wR, wG and wB is the wanted r/g/b value; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4377 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4378 |
idx = pix+pix+pix; /* pix * 3 */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4379 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4380 |
__wantR = __wR = rgbP[idx] + __eR; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4381 |
__wantG = __wG = rgbP[idx+1] + __eG; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4382 |
__wantB = __wB = rgbP[idx+2] + __eB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4383 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4384 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4385 |
if(__wR > 255) __wR = 255; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4386 |
else if (__wR < 0) __wR = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4387 |
if(__wG > 255) __wG = 255; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4388 |
else if (__wG < 0) __wG = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4389 |
if(__wB > 255) __wB = 255; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4390 |
else if (__wB < 0) __wB = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4391 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4392 |
/* find the best matching color */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4393 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4394 |
minDelta = 99999; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4395 |
bestIdx = -1; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4396 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4397 |
for (idx = 0; idx<__nColors; idx++) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4398 |
int d, delta; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4399 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4400 |
d = dp[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4401 |
delta = __wR - d; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4402 |
if (delta < 0) delta = -delta; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4403 |
d = dp[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4404 |
if (__wG > d) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4405 |
delta += (__wG - d); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4406 |
else |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4407 |
delta += (d - __wG); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4408 |
d = dp[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4409 |
if (__wB > d) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4410 |
delta += (__wB - d); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4411 |
else |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4412 |
delta += (d - __wB); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4413 |
if (delta < minDelta) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4414 |
bestIdx = idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4415 |
if (delta == 0) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4416 |
break; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4417 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4418 |
minDelta = delta; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4419 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4420 |
dp += 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4421 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4422 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4423 |
dp += bestIdx * 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4424 |
dR = dp[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4425 |
dG = dp[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4426 |
dB = dp[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4427 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4428 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4429 |
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n", |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4430 |
__wantR, __wantG, __wantB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4431 |
__wR, __wG, __wB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4432 |
dR, dG, dB); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4433 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4434 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4435 |
* store the corresponding dither colors colorId |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4436 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4437 |
*dstP++ = idP[bestIdx]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4438 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4439 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4440 |
* the new error: |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4441 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4442 |
__eR = __wantR - dR; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4443 |
__eG = __wantG - dG; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4444 |
__eB = __wantB - dB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4445 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4446 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4447 |
* distribute the error |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4448 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4449 |
tR = __eR >> 4; /* 16th of error */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4450 |
tG = __eG >> 4; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4451 |
tB = __eB >> 4; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4452 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4453 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4454 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4455 |
nB = eP[5] + (tB * 7); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4456 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4457 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4458 |
eP[1] = tG*5; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4459 |
eP[2] = tB*5; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4460 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4461 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4462 |
eP[-2] = tG*3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4463 |
eP[-1] = tB*3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4464 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4465 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4466 |
eP[4] = __eG - (tG*15); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4467 |
eP[5] = __eB - (tB*15); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4468 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4469 |
__eR = nR; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4470 |
__eG = nG; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4471 |
__eB = nB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4472 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4473 |
eP += 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4474 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4475 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4476 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4477 |
%}. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4478 |
failed ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4479 |
self primitiveFailed. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4480 |
^ nil |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4481 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4482 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4483 |
^ pseudoBits |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4484 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4485 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4486 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4487 |
|
854 | 4488 |
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
858 | 4489 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
4490 |
which must be a depth-8 image. |
|
4491 |
This is a special-cased dither method for 8-bit palette images being displayed on |
|
4492 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
|
854 | 4493 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
4494 |
colors assigned to aDevice, such as the preallocated colors of the |
|
4495 |
Color class. |
|
4496 |
By passing the ditherColors as extra array, this method can |
|
4497 |
also be used to dither an 8bit image into a smaller number of colors, |
|
4498 |
for example to create dithered Depth4Images from Depth8Images." |
|
4499 |
||
858 | 4500 |
|pseudoBits |
854 | 4501 |
rgbBytes |
4502 |
w "{Class: SmallInteger }" |
|
4503 |
h "{Class: SmallInteger }" |
|
4504 |
index "{Class: SmallInteger }" |
|
4505 |
fixR "{Class: SmallInteger }" |
|
4506 |
fixG "{Class: SmallInteger }" |
|
4507 |
fixB "{Class: SmallInteger }" |
|
4508 |
fixIds failed map lastColor |
|
4509 |
error clr| |
|
4510 |
||
858 | 4511 |
self depth ~~ 8 ifTrue:[^ nil]. |
4512 |
||
854 | 4513 |
fixR := nRed. |
4514 |
fixR == 0 ifTrue:[ ^ nil]. |
|
4515 |
fixG := nGreen. |
|
4516 |
fixG == 0 ifTrue:[ ^ nil]. |
|
4517 |
fixB := nBlue. |
|
4518 |
fixB == 0 ifTrue:[ ^ nil]. |
|
4519 |
||
4520 |
"/ simple check |
|
4521 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
4522 |
self error:'invalid color array passed'. |
|
4523 |
^ nil |
|
4524 |
]. |
|
4525 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
4526 |
||
4527 |
"/ |
|
4528 |
"/ collect color components as integer values (for integer arithmetic) |
|
4529 |
"/ |
|
4530 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
|
4531 |
||
4532 |
index := 1. |
|
4533 |
||
4534 |
photometric == #palette ifTrue:[ |
|
4535 |
lastColor := colorMap size - 1 |
|
4536 |
] ifFalse:[ |
|
4537 |
lastColor := 255. |
|
4538 |
]. |
|
4539 |
0 to:lastColor do:[:pix | |
|
4540 |
clr := self colorFromValue:pix. |
|
4541 |
rgbBytes at:index put:(clr redByte). |
|
4542 |
rgbBytes at:index+1 put:(clr greenByte). |
|
4543 |
rgbBytes at:index+2 put:(clr blueByte). |
|
4544 |
||
4545 |
index := index + 3. |
|
4546 |
]. |
|
4547 |
||
4548 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
4549 |
||
4550 |
w := width + 2. |
|
4551 |
error := ByteArray uninitializedNew:w*(3*2). |
|
4552 |
||
4553 |
w := width. |
|
4554 |
h := height. |
|
4555 |
||
4556 |
failed := true. |
|
4557 |
||
4558 |
%{ |
|
4559 |
int __x, __y; |
|
4560 |
int __eR, __eG, __eB; |
|
4561 |
unsigned char *srcP, *dstP; |
|
4562 |
unsigned char *rgbP; |
|
4563 |
unsigned char *idP; |
|
4564 |
short *errP, *eP; |
|
4565 |
int __fR, __fG, __fB; |
|
4566 |
int iR, iG, iB; |
|
4567 |
int idx; |
|
4568 |
int __w = __intVal(w); |
|
4569 |
||
4570 |
if (__isByteArray(__INST(bytes)) |
|
4571 |
&& __isByteArray(pseudoBits) |
|
4572 |
&& __isByteArray(rgbBytes) |
|
4573 |
&& __isByteArray(fixIds) |
|
4574 |
&& __isByteArray(error) |
|
4575 |
&& __bothSmallInteger(fixR, fixG) |
|
4576 |
&& __isSmallInteger(fixB)) { |
|
4577 |
failed = false; |
|
4578 |
||
4579 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
4580 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
4581 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
|
4582 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
4583 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
|
4584 |
__fR = __intVal(fixR)-1; |
|
4585 |
__fG = __intVal(fixG)-1; |
|
4586 |
__fB = __intVal(fixB)-1; |
|
4587 |
||
4588 |
/* |
|
4589 |
* clear error accumulator |
|
4590 |
*/ |
|
4591 |
eP = errP; |
|
4592 |
bzero(eP, (__w+2) * 2 * 3); |
|
4593 |
||
4594 |
for (__y=__intVal(h); __y>0; __y--) { |
|
4595 |
__eR = __eG = __eB = 0; |
|
4596 |
||
4597 |
eP = &(errP[3]); |
|
4598 |
__eR = eP[0]; |
|
4599 |
__eG = eP[1]; |
|
4600 |
__eB = eP[2]; |
|
4601 |
||
4602 |
for (__x=__w; __x>0; __x--) { |
|
4603 |
int __want; |
|
4604 |
int pix; |
|
4605 |
int __wantR, __wantG, __wantB; |
|
4606 |
int idx; |
|
4607 |
int tR, tG, tB; |
|
4608 |
int nR, nG, nB; |
|
4609 |
||
4610 |
pix = *srcP++; |
|
4611 |
||
4612 |
/* |
|
4613 |
* wR, wG and wB is the wanted r/g/b value; |
|
4614 |
*/ |
|
4615 |
idx = pix+pix+pix; /* pix * 3 */ |
|
4616 |
||
4617 |
__wantR = __want = rgbP[idx] + __eR; |
|
4618 |
if (__want > 255) __want = 255; |
|
4619 |
else if (__want < 0) __want = 0; |
|
4620 |
iR = (__want * __fR + 128) / 255; /* red index rounded */ |
|
4621 |
||
4622 |
__wantG = __want = rgbP[idx+1] + __eG; |
|
4623 |
if (__want > 255) __want = 255; |
|
4624 |
else if (__want < 0) __want = 0; |
|
4625 |
iG = (__want * __fG + 128) / 255; /* green index rounded */ |
|
4626 |
||
4627 |
__wantB = __want = rgbP[idx+2] + __eB; |
|
4628 |
if (__want > 255) __want = 255; |
|
4629 |
else if (__want < 0) __want = 0; |
|
4630 |
iB = (__want * __fB + 128) / 255; /* blue index rounded */ |
|
4631 |
||
4632 |
idx = iR * (__fG+1); |
|
4633 |
idx = (idx + iG) * (__fB+1); |
|
4634 |
idx = idx + iB; |
|
4635 |
||
4636 |
/* |
|
4637 |
* store the corresponding dither colors colorId |
|
4638 |
*/ |
|
4639 |
*dstP++ = idP[idx]; |
|
4640 |
||
4641 |
/* |
|
4642 |
* the new error: |
|
4643 |
*/ |
|
4644 |
__eR = __wantR - (iR * 255 / __fR); |
|
4645 |
__eG = __wantG - (iG * 255 / __fG); |
|
4646 |
__eB = __wantB - (iB * 255 / __fB); |
|
4647 |
||
4648 |
/* |
|
4649 |
* distribute the error |
|
4650 |
*/ |
|
4651 |
tR = __eR >> 4; /* 16th of error */ |
|
4652 |
tG = __eG >> 4; |
|
4653 |
tB = __eB >> 4; |
|
4654 |
||
4655 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
4656 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
4657 |
nB = eP[5] + (tB * 7); |
|
4658 |
||
4659 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
4660 |
eP[1] = tG*5; |
|
4661 |
eP[2] = tB*5; |
|
4662 |
||
4663 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
4664 |
eP[-2] = tG*3; |
|
4665 |
eP[-1] = tB*3; |
|
4666 |
||
4667 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
4668 |
eP[4] = __eG - (tG*15); |
|
4669 |
eP[5] = __eB - (tB*15); |
|
4670 |
||
4671 |
__eR = nR; |
|
4672 |
__eG = nG; |
|
4673 |
__eB = nB; |
|
4674 |
||
4675 |
eP += 3; |
|
4676 |
} |
|
4677 |
} |
|
4678 |
} |
|
4679 |
%}. |
|
4680 |
failed ifTrue:[ |
|
4681 |
self primitiveFailed. |
|
4682 |
^ nil |
|
4683 |
]. |
|
4684 |
||
4685 |
^ pseudoBits |
|
4686 |
||
4687 |
||
4688 |
! |
|
4689 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4690 |
floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4691 |
"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
|
4692 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4693 |
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
|
4694 |
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
|
4695 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4696 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4697 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4698 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4699 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4700 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4701 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4702 |
e eD t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4703 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4704 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4705 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4706 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4707 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4708 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4709 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4710 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4711 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4712 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4713 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4714 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4715 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4716 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4717 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4718 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4719 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4720 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4721 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4722 |
nextErrorArray atAllPut:0. |
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 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4725 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4726 |
byte := 0. |
809
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 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4729 |
"/ 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
|
4730 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4731 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4732 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4733 |
greyValues := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4734 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4735 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4736 |
v rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4737 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4738 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4739 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4740 |
nextDst := dstIndex + bytesPerMonoRow. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4743 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4744 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4745 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4746 |
nextErrorArray atAllPut:0. |
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 |
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
|
4749 |
%{ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4750 |
int __grey, __e; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4751 |
int __byte = __intVal(byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4752 |
OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4753 |
OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4754 |
int __x = __intVal(x); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4755 |
int __eR, __eB, __eRB, __eLB, __eI; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4756 |
int __bitCnt = __intVal(bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4757 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4758 |
__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4759 |
__grey += __intVal(__errorArray[__x+1]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4760 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4761 |
__byte <<= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4762 |
if (__grey > 127*1024) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4763 |
__e = __grey - (255*1024); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4764 |
__byte |= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4765 |
} else { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4766 |
__e = __grey; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4767 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4768 |
if (__e) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4769 |
__eI = __e >> 4; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4770 |
__eR = __eI * 7; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4771 |
__eRB = __eI * 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4772 |
__eB = __eI * 5; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4773 |
__eLB = __e - __eR - __eRB - __eB; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4774 |
__errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4775 |
__nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4776 |
__nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4777 |
__nextErrorArray[__x ] = __MKSMALLINT(__intVal(__nextErrorArray[__x ]) + __eLB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4778 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4779 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4780 |
__bitCnt--; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4781 |
if (__bitCnt == 0) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4782 |
int __dstIndex = __intVal(dstIndex); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4783 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4784 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4785 |
dstIndex = __MKSMALLINT(__dstIndex + 1); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4786 |
__byte = 0; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4787 |
__bitCnt = 8; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4788 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4789 |
byte = __MKSMALLINT(__byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4790 |
bitCnt = __MKSMALLINT(__bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4791 |
%}. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4792 |
|
829 | 4793 |
"/ |eI "{ Class: SmallInteger }" |
4794 |
"/ xE "{ Class: SmallInteger }" |
|
4795 |
"/ xN "{ Class: SmallInteger }" | |
|
4796 |
"/ |
|
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4797 |
"/ "/ get the colors grey value [0 .. 1] |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4798 |
"/ grey := greyValues at:(pixel + 1). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4799 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4800 |
"/ "/ adjust error |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4801 |
"/ xE := x + 2. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4802 |
"/ grey := (grey + (errorArray at:xE)). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4803 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4804 |
"/ byte := byte bitShift:1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4805 |
"/ grey > (127*1024) ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4806 |
"/ byte := byte bitOr:1. "/ white |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4807 |
"/ e := grey - (255*1024) |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4808 |
"/ ] ifFalse:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4809 |
"/ e := grey "/ black |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4810 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4811 |
"/ e ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4812 |
"/ eD := e. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4813 |
"/ eI := e // 16. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4814 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4815 |
"/ eR := eI * 7. "/ 7/16 to right |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4816 |
"/ eRB := eI * 1. "/ 1/16 to right below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4817 |
"/ eB := eI * 5. "/ 5/16 to below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4818 |
"/ eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4819 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4820 |
"/ xN := xE + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4821 |
"/ eR ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4822 |
"/ errorArray at:xN put:(errorArray at:xN) + eR. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4823 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4824 |
"/ eRB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4825 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4826 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4827 |
"/ eB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4828 |
"/ nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4829 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4830 |
"/ eLB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4831 |
"/ xN := xE - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4832 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4833 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4834 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4835 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4836 |
"/ bitCnt := bitCnt - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4837 |
"/ bitCnt == 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4838 |
"/ monoBits at:dstIndex put:byte. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4839 |
"/ dstIndex := dstIndex + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4840 |
"/ byte := 0. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4841 |
"/ bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4842 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4843 |
0 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4844 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4845 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4846 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4847 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4848 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4849 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4850 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4851 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4852 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4853 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4854 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4855 |
'IMAGE: slow floydSteinberg dither ..' infoPrintCR. |
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 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4858 |
nextDst := dstIndex + bytesPerMonoRow. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4861 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4862 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4863 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4864 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4865 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4866 |
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
|
4867 |
|eI "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4868 |
xE "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4869 |
xN "{ Class: SmallInteger }" | |
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 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4872 |
grey := (clr brightness * 255). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4873 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4874 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4875 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4876 |
grey := (grey + (errorArray at:xE)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4877 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4878 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4879 |
grey > 127 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4880 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4881 |
e := grey - 255 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4882 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4883 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4884 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4885 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4886 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4887 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4888 |
eI := e // 16. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4889 |
eR := eI * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4890 |
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
|
4891 |
eB := eI * 5. "/ 5/16 to below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4892 |
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
|
4893 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4894 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4895 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4896 |
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
|
4897 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4898 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4899 |
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
|
4900 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4901 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4902 |
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
|
4903 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4904 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4905 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4906 |
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
|
4907 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4908 |
]. |
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 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4911 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4912 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4913 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4914 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4915 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4916 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4917 |
|
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 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4920 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4921 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4922 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4923 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4924 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4925 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4926 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4927 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4928 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4929 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4930 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4931 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4932 |
"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
|
4933 |
"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
|
4934 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4935 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4936 |
orderedDitheredBitsDepth:depth |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4937 |
"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
|
4938 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4939 |
^ self |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4940 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4941 |
ditherWidth:8 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4942 |
depth:depth. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4943 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4944 |
"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
|
4945 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
4946 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4947 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4948 |
"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
|
4949 |
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
|
4950 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4951 |
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
|
4952 |
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
|
4953 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4954 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4955 |
greyLevels greyValues greyPixels greyErrors |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4956 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4957 |
nextDst |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4958 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4959 |
pixelsPerByte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4960 |
outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4961 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4962 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4963 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4964 |
byte "{Class: SmallInteger }" | |
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 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4967 |
'IMAGE: unimplemented orderedDither conversion' errorPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4968 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4969 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4970 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4971 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4972 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4973 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4974 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4975 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4976 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4977 |
greyLevels := 1 bitShift:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4978 |
pixelsPerByte := 8 / depth. |
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 |
bytesPerOutRow := (w * depth + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4981 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4982 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4983 |
^ nil |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4986 |
dstIndex := 1. |
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 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4989 |
"/ 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
|
4990 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4991 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4992 |
greyValues := self greyMapForRange:(greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4993 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4994 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4995 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4996 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4997 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4998 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4999 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5000 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5001 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5002 |
((v - v truncated) * nDither) rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5003 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5004 |
greyErrors := ByteArray withAll:greyErrors. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5005 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5006 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5007 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5008 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5009 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5010 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5011 |
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
|
5012 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5013 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5014 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5015 |
int __value = __intVal(value); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5016 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5017 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5018 |
int __pixel, __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5019 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5020 |
unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5021 |
unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5022 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5023 |
__pixel = __greyPixels[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5024 |
__grey = __greyErrors[__value]; |
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 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5027 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5028 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5029 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5030 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5031 |
__pixel++; |
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 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5034 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5035 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5036 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5037 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5038 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5039 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5040 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5041 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5042 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5043 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5044 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5045 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5046 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5047 |
0 |
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 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5050 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5051 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5052 |
outBits at:dstIndex put:byte. |
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 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5055 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5056 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5057 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5058 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5059 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5060 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5061 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5062 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5063 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5064 |
"/ this is the representaion independent (but slow) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5065 |
"/ 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
|
5066 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5067 |
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
|
5068 |
|dstClr grey dT pixel| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5069 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5070 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5071 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5072 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5073 |
"/ remap into [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5074 |
grey := grey * (greyLevels-1). |
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 |
"/ get threshold pixel [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5077 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5078 |
pixel := grey truncated. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5079 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5080 |
"/ compute the error [0..1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5081 |
grey := grey - pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5082 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5083 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5084 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5085 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5086 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5087 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5088 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5089 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5090 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5091 |
int __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5092 |
int __bitCnt = __intVal(bitCnt); |
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 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5095 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5096 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5097 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5098 |
__pixel = __intVal(pixel); |
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 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5101 |
__pixel++; |
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 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5104 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5105 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5106 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5107 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5108 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5109 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5110 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5111 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5112 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5113 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5114 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5115 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5116 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5117 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5118 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5119 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5120 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5121 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5122 |
outBits at:dstIndex put:byte. |
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 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5125 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5126 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5127 |
^ outBits |
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 |
|
831 | 5130 |
orderedDitheredMonochromeBits |
5131 |
"return the bitmap for a dithered monochrome bitmap from the image; |
|
5132 |
using a default ditherMatrix." |
|
5133 |
||
5134 |
^ self |
|
5135 |
orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
5136 |
ditherWidth:8 |
|
5137 |
||
5138 |
"Created: 11.6.1996 / 16:48:57 / cg" |
|
5139 |
! |
|
5140 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5141 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5142 |
"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
|
5143 |
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
|
5144 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5145 |
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
|
5146 |
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
|
5147 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5148 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5149 |
greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5150 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5151 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5152 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5153 |
monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5154 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5155 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5156 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5157 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5158 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5159 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5160 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5161 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5162 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5163 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5164 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5165 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5166 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5167 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5168 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5169 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5170 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5171 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5172 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5173 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5174 |
"/ 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
|
5175 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5176 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5177 |
greyValues := self greyByteMapForRange:nDither. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5178 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5179 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5180 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5181 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5182 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5183 |
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
|
5184 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5185 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5186 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5187 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5188 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5189 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5190 |
int __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5191 |
unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5192 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5193 |
__grey = __greyValues[__intVal(value)]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5194 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5195 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5196 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5197 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5198 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5199 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5200 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5201 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5202 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5203 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5204 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5205 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5206 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5207 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5208 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5209 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5210 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5211 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5212 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5213 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5214 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5215 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5216 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5217 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5218 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5219 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5220 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5221 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5222 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5223 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5224 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5225 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5226 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5227 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5228 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5229 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5230 |
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
|
5231 |
|dstClr grey dT| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5232 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5233 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5234 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5235 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5236 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5237 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5238 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5239 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5240 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5241 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5242 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5243 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5244 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5245 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5246 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5247 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5248 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5249 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5250 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5251 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5252 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5253 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5254 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5255 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5256 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5257 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5258 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5259 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5260 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5261 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5262 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5263 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5264 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5265 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5266 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5267 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5268 |
"/ 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
|
5269 |
"/ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5270 |
"/ byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5271 |
"/ grey < dT ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5272 |
"/ byte := byte bitOr:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5273 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5274 |
"/ bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5275 |
"/ bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5276 |
"/ monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5277 |
"/ dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5278 |
"/ byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5279 |
"/ bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5280 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5281 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5282 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5283 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5284 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5285 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5286 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5287 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5288 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5289 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5290 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5291 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5292 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5293 |
stevensonArceDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5294 |
"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
|
5295 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5296 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5297 |
|f last |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5298 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5299 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5300 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5301 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5302 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5303 |
errorArray1 errorArray2 errorArray3 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5304 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5305 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5306 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5307 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5308 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5309 |
direction "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5310 |
dstClr grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5311 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5312 |
xN "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5313 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5314 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5315 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5316 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5317 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5318 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5319 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5320 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5321 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5322 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5323 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5324 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5325 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5326 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5327 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5328 |
errorArray := Array new:(w+6). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5329 |
errorArray1 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5330 |
errorArray2 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5331 |
errorArray3 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5332 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5333 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5334 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5335 |
"/ 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
|
5336 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5337 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5338 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5339 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5340 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5341 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5342 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5343 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5344 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5345 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5346 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5347 |
errorArray1 := errorArray2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5348 |
errorArray2 := errorArray3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5349 |
errorArray3 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5350 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5351 |
errorArray3 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5352 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5353 |
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
|
5354 |
|eP eD| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5355 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5356 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5357 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5358 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5359 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5360 |
xE := x + 3 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5361 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5362 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5363 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5364 |
grey > (127 * 1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5365 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5366 |
e := grey - (255 * 1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5367 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5368 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5369 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5370 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5371 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5372 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5373 |
"/ XX 32 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5374 |
"/ 12 26 30 16 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5375 |
"/ 12 26 12 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5376 |
"/ 5 12 12 5 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5377 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5378 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5379 |
e := e // 200. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5380 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5381 |
eP := e * 32. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5382 |
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
|
5383 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5384 |
eP := e * 30. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5385 |
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
|
5386 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5387 |
eP := e * 16. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5388 |
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
|
5389 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5390 |
eP := e * 26. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5391 |
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
|
5392 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5393 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5394 |
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
|
5395 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5396 |
eP := e * 12. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5397 |
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
|
5398 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5399 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5400 |
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
|
5401 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5402 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5403 |
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
|
5404 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5405 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5406 |
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
|
5407 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5408 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5409 |
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
|
5410 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5411 |
eP := e * 5. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5412 |
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
|
5413 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5414 |
eP := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5415 |
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
|
5416 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5417 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5418 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5419 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5420 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5421 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5422 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5423 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5424 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5425 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5426 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5427 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5428 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5429 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5430 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5431 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5432 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5433 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5434 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5435 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5436 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5437 |
"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
|
5438 |
"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
|
5439 |
! ! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5440 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5441 |
!Image methodsFor:'drawing'! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5442 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5443 |
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
|
5444 |
|pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5445 |
xI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5446 |
yI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5447 |
wI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5448 |
hI "{ Class: SmallInteger }"| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5449 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5450 |
pixel := self valueFromColor:aColor. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5451 |
xI := x. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5452 |
yI := y. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5453 |
wI := w. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5454 |
hI := h. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5455 |
yI to:yI+hI-1 do:[:yRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5456 |
xI to:xI+wI-1 do:[:xRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5457 |
self atX:xRun y:yRun putValue:pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5458 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5459 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5460 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5461 |
"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
|
5462 |
"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
|
5463 |
! ! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5464 |
|
283 | 5465 |
!Image methodsFor:'enumerating'! |
5466 |
||
5467 |
atY:y from:x1 to:x2 do:aBlock |
|
5468 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5469 |
The block is passed the color at each pixel. |
|
5470 |
The code here provides a generic and slow implementation, and |
|
5471 |
should be redefined in concrete subclasses, to avoid some processing |
|
5472 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5473 |
and also the color allocation)." |
|
5474 |
||
798 | 5475 |
self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'. |
5476 |
self colorsAtY:y from:x1 to:x2 do:aBlock |
|
5477 |
||
5478 |
"Modified: 7.6.1996 / 19:13:30 / cg" |
|
5479 |
! |
|
5480 |
||
5481 |
colorsAtY:y from:x1 to:x2 do:aBlock |
|
5482 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5483 |
The block is passed the color at each pixel. |
|
5484 |
The code here provides a generic and slow implementation, and |
|
5485 |
should be redefined in concrete subclasses, to avoid some processing |
|
5486 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5487 |
and also the color allocation)." |
|
5488 |
||
283 | 5489 |
|xStart "{Class: SmallInteger }" |
5490 |
xEnd "{Class: SmallInteger }"| |
|
5491 |
||
5492 |
xStart := x1. |
|
5493 |
xEnd := x2. |
|
5494 |
xStart to:xEnd do:[:xRun | |
|
798 | 5495 |
aBlock value:xRun value:(self atX:xRun y:y) |
283 | 5496 |
] |
798 | 5497 |
|
5498 |
"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
|
5499 |
"Modified: 10.6.1996 / 10:27:29 / cg" |
283 | 5500 |
! |
5501 |
||
5502 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5503 |
"perform aBlock for each color in a rectangular area of the image. |
|
5504 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5505 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5506 |
The code here provides a generic and slow implementation, and |
|
5507 |
should be redefined in concrete subclasses, to avoid some processing |
|
5508 |
when going from pixel to pixel (i.e. the byte-index and mask computations, |
|
5509 |
and especially, the color allocations)." |
|
5510 |
||
5511 |
|xS "{Class: SmallInteger }" |
|
5512 |
xE "{Class: SmallInteger }"| |
|
5513 |
||
5514 |
xS := xStart. |
|
5515 |
xE := xEnd. |
|
5516 |
yStart to:yEnd do:[:yRun | |
|
798 | 5517 |
self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color | |
5518 |
aBlock value:xRun value:yRun value:color |
|
5519 |
] |
|
283 | 5520 |
] |
798 | 5521 |
|
5522 |
"Modified: 7.6.1996 / 19:11:39 / cg" |
|
283 | 5523 |
! |
5524 |
||
5525 |
valueAtY:y from:x1 to:x2 do:aBlock |
|
5526 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
798 | 5527 |
Obsolete - remains for backward compatibility." |
5528 |
||
5529 |
self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'. |
|
5530 |
self valuesAtY:y from:x1 to:x2 do:aBlock |
|
5531 |
||
5532 |
"Modified: 7.6.1996 / 19:11:06 / cg" |
|
5533 |
! |
|
5534 |
||
5535 |
valuesAtY:y from:x1 to:x2 do:aBlock |
|
5536 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
283 | 5537 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
5538 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
5539 |
(see also Image>>atY:from:to:do:). |
|
5540 |
The code here provides a generic and slow implementation, and |
|
5541 |
should be redefined in concrete subclasses, to avoid some processing |
|
5542 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
5543 |
||
5544 |
|xStart "{Class: SmallInteger }" |
|
5545 |
xEnd "{Class: SmallInteger }"| |
|
5546 |
||
5547 |
xStart := x1. |
|
5548 |
xEnd := x2. |
|
5549 |
xStart to:xEnd do:[:xRun | |
|
692 | 5550 |
aBlock value:xRun value:(self valueAtX:xRun y:y) |
283 | 5551 |
] |
692 | 5552 |
|
5553 |
"Modified: 17.5.1996 / 12:03:59 / cg" |
|
798 | 5554 |
"Created: 7.6.1996 / 19:09:51 / cg" |
283 | 5555 |
! |
5556 |
||
5557 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5558 |
"perform aBlock for each pixelValue in a rectangular area of the image. |
|
5559 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5560 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5561 |
The code here provides a generic and slow implementation, and |
|
5562 |
should be redefined in concrete subclasses, to avoid some processing |
|
5563 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
5564 |
||
5565 |
|xS "{Class: SmallInteger }" |
|
5566 |
xE "{Class: SmallInteger }"| |
|
5567 |
||
5568 |
xS := xStart. |
|
5569 |
xE := xEnd. |
|
5570 |
yStart to:yEnd do:[:yRun | |
|
798 | 5571 |
self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel | |
5572 |
aBlock value:xRun value:yRun value:pixel |
|
5573 |
] |
|
283 | 5574 |
] |
798 | 5575 |
|
5576 |
"Modified: 7.6.1996 / 19:09:29 / cg" |
|
0 | 5577 |
! ! |
5578 |
||
5579 |
!Image methodsFor:'image manipulations'! |
|
5580 |
||
283 | 5581 |
colorMapProcessing:aBlock |
5582 |
"a helper for all kinds of colormap manipulations. |
|
592 | 5583 |
The argument, aBlock is called for every colormap entry, |
5584 |
and the returned value will replace the original entry in the map. |
|
283 | 5585 |
This will fail for non-palette images. |
592 | 5586 |
See examples in Image>>copyWithColorMapProcessing:" |
283 | 5587 |
|
5588 |
|nColors "{ Class: SmallInteger }"| |
|
5589 |
||
5590 |
colorMap isNil ifTrue:[ |
|
592 | 5591 |
^ self error:'image has no colormap' |
283 | 5592 |
]. |
5593 |
||
5594 |
nColors := colorMap size. |
|
5595 |
1 to:nColors do:[:index | |
|
592 | 5596 |
|clr| |
5597 |
||
5598 |
clr := colorMap at:index. |
|
5599 |
clr notNil ifTrue:[ |
|
5600 |
colorMap at:index put:(aBlock value:clr) |
|
5601 |
] |
|
283 | 5602 |
] |
592 | 5603 |
|
5604 |
"Modified: 23.4.1996 / 11:13:55 / cg" |
|
283 | 5605 |
! |
5606 |
||
89 | 5607 |
copyWithColorMapProcessing:aBlock |
81 | 5608 |
"a helper to create & return new images based on the receiver with |
89 | 5609 |
some colorMap processing. The receiver is copied, and the copied images |
5610 |
colormap is modified by replacing entries with the result of the processing block, |
|
5611 |
which is called with the original color values. The block is supposed to return |
|
5612 |
a color." |
|
81 | 5613 |
|
5614 |
|newImage| |
|
5615 |
||
5616 |
newImage := self copy. |
|
5617 |
newImage colorMap isNil ifTrue:[ |
|
5618 |
self error:'no colormap in image'. |
|
5619 |
^ nil |
|
5620 |
]. |
|
5621 |
||
5622 |
" |
|
5623 |
the code below manipulates the colormap. |
|
5624 |
For non-palette images, special code is required |
|
5625 |
" |
|
89 | 5626 |
newImage colorMapProcessing:aBlock. |
81 | 5627 |
^ newImage |
5628 |
||
5629 |
" |
|
5630 |
leave red component only: |
|
5631 |
||
5632 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5633 |
copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] |
81 | 5634 |
" |
89 | 5635 |
|
81 | 5636 |
" |
5637 |
make it reddish: |
|
5638 |
||
5639 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5640 |
copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] |
81 | 5641 |
" |
89 | 5642 |
|
81 | 5643 |
" |
5644 |
invert: |
|
5645 |
||
5646 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5647 |
copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] |
81 | 5648 |
" |
89 | 5649 |
|
81 | 5650 |
" |
5651 |
lighter: |
|
5652 |
||
5653 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5654 |
copyWithColorMapProcessing:[:clr | |r g b| |
5655 |
r := clr red. g := clr green. b := clr blue. |
|
5656 |
Color red:(r + (100-r//2)) |
|
5657 |
green:(g + (100-g//2)) |
|
5658 |
blue:(b + (100-b//2))] |
|
81 | 5659 |
" |
89 | 5660 |
|
81 | 5661 |
" |
5662 |
darker: |
|
5663 |
||
5664 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5665 |
copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] |
81 | 5666 |
" |
5667 |
! |
|
5668 |
||
283 | 5669 |
darkened |
5670 |
"return a new image which is slightly darker than the receiver. |
|
5671 |
The receiver must be a palette image (currently). |
|
592 | 5672 |
CAVEAT: Need an argument, which specifies by how much it should be darker." |
283 | 5673 |
|
5674 |
^ self |
|
592 | 5675 |
copyWithColorMapProcessing:[:clr | |
5676 |
Color red:(clr red // 2) |
|
5677 |
green:(clr green // 2) |
|
5678 |
blue:(clr blue // 2)] |
|
283 | 5679 |
|
5680 |
" |
|
5681 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
5682 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
5683 |
" |
|
592 | 5684 |
|
5685 |
"Modified: 23.4.1996 / 11:14:34 / cg" |
|
283 | 5686 |
! |
5687 |
||
5688 |
flipHorizontal |
|
5689 |
"inplace horizontal flip" |
|
5690 |
||
5691 |
|w "{Class: SmallInteger }" |
|
5692 |
h "{Class: SmallInteger }" |
|
5693 |
c2 "{Class: SmallInteger }" |
|
5694 |
value | |
|
5695 |
||
5696 |
w := width - 1. |
|
5697 |
h := height - 1. |
|
5698 |
||
5699 |
0 to:h do:[:row | |
|
5700 |
c2 := w. |
|
5701 |
0 to:(w // 2) do:[:col | |
|
5702 |
value := self valueAtX:col y:row. |
|
5703 |
self atX:col y:row putValue:(self valueAtX:c2 y:row). |
|
5704 |
self atX:c2 y:row putValue:value. |
|
5705 |
c2 := c2 - 1. |
|
5706 |
] |
|
81 | 5707 |
]. |
283 | 5708 |
"flush device info" |
5709 |
self restored |
|
5710 |
! |
|
5711 |
||
5712 |
flipVertical |
|
5713 |
"inplace vertical flip" |
|
5714 |
||
5715 |
|h "{Class: SmallInteger }" |
|
5716 |
bytesPerRow "{Class: SmallInteger }" |
|
5717 |
buffer |
|
5718 |
indexLow "{Class: SmallInteger }" |
|
5719 |
indexHi "{Class: SmallInteger }"| |
|
5720 |
||
5721 |
bytesPerRow := self bytesPerRow. |
|
5722 |
buffer := ByteArray new:bytesPerRow. |
|
5723 |
||
5724 |
h := height - 1. |
|
5725 |
||
5726 |
indexLow := 1. |
|
5727 |
indexHi := bytesPerRow * h + 1. |
|
5728 |
||
5729 |
0 to:(h // 2) do:[:row | |
|
5730 |
buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow. |
|
5731 |
bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi. |
|
5732 |
bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1. |
|
5733 |
indexLow := indexLow + bytesPerRow. |
|
5734 |
indexHi := indexHi - bytesPerRow. |
|
5735 |
]. |
|
5736 |
"flush device info" |
|
5737 |
self restored |
|
5738 |
! |
|
5739 |
||
5740 |
hardMagnifiedBy:scalePoint |
|
5741 |
"return a new image magnified by scalePoint, aPoint. |
|
5742 |
This is the general magnification method, handling non-integral values. |
|
5743 |
It is slower than the integral magnification method." |
|
5744 |
||
5745 |
|mX |
|
5746 |
mY |
|
5747 |
newWidth "{ Class: SmallInteger }" |
|
5748 |
newHeight "{ Class: SmallInteger }" |
|
5749 |
w "{ Class: SmallInteger }" |
|
5750 |
h "{ Class: SmallInteger }" |
|
5751 |
newImage newBits bitsPerPixel newBytesPerRow |
|
5752 |
value srcRow| |
|
5753 |
||
5754 |
mX := scalePoint x. |
|
5755 |
mY := scalePoint y. |
|
5756 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
5757 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
5758 |
||
5759 |
newWidth := (width * mX) truncated. |
|
5760 |
newHeight := (height * mY) truncated. |
|
5761 |
||
5762 |
bitsPerPixel := self depth. |
|
5763 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
5764 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
5765 |
||
5766 |
newImage := self species new. |
|
5767 |
newImage bits:newBits. |
|
5768 |
newImage width:newWidth. |
|
5769 |
newImage height:newHeight. |
|
5770 |
newImage photometric:photometric. |
|
5771 |
newImage samplesPerPixel:samplesPerPixel. |
|
5772 |
newImage bitsPerSample:bitsPerSample. |
|
5773 |
newImage colorMap:colorMap copy. |
|
5774 |
||
5775 |
"walk over destination image fetching pixels from source image" |
|
5776 |
||
5777 |
w := newWidth - 1. |
|
5778 |
h := newHeight - 1. |
|
5779 |
||
5780 |
0 to:h do:[:row | |
|
5781 |
srcRow := (row // mY). |
|
5782 |
0 to:w do:[:col | |
|
5783 |
value := self valueAtX:(col // mX) y:srcRow. |
|
5784 |
newImage atX:col y:row putValue:value. |
|
89 | 5785 |
] |
283 | 5786 |
]. |
5787 |
||
5788 |
^ newImage |
|
5789 |
||
5790 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
|
5791 |
! |
|
5792 |
||
5793 |
hardRotated:degrees |
|
592 | 5794 |
"raise an error - rotation by arbitrary angles is not yet implemented" |
5795 |
||
283 | 5796 |
self error:'not yet implemented' |
592 | 5797 |
|
5798 |
"Modified: 23.4.1996 / 11:15:33 / cg" |
|
81 | 5799 |
! |
5800 |
||
54 | 5801 |
lightened |
89 | 5802 |
"return a new image which is slightly brighter than the receiver. |
5803 |
The receiver must be a palette image (currently). |
|
592 | 5804 |
CAVEAT: Need an argument, which specifies by how much it should be lighter." |
54 | 5805 |
|
81 | 5806 |
^ self |
592 | 5807 |
copyWithColorMapProcessing:[:clr | |r g b| |
5808 |
r := clr red. |
|
5809 |
g := clr green. |
|
5810 |
b := clr blue. |
|
5811 |
Color red:(r + (100-r//2)) |
|
5812 |
green:(g + (100-g//2)) |
|
5813 |
blue:(b + (100-b//2))] |
|
81 | 5814 |
|
5815 |
" |
|
5816 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
5817 |
(Image fromFile:'bitmaps/claus.gif') lightened inspect |
|
5818 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
5819 |
(Image fromFile:'bitmaps/claus.gif') darkened darkened inspect |
|
5820 |
" |
|
592 | 5821 |
|
5822 |
"Modified: 23.4.1996 / 11:14:41 / cg" |
|
54 | 5823 |
! |
5824 |
||
134 | 5825 |
magnifiedBy:scale |
81 | 5826 |
"return a new image magnified by scalePoint, aPoint. |
72 | 5827 |
If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:' |
5828 |
while simple (integral) magnifications are handled here." |
|
0 | 5829 |
|
81 | 5830 |
|scalePoint mX mY |
46 | 5831 |
magX "{ Class: SmallInteger }" "new version of stc can find this out itself..." |
5832 |
magY "{ Class: SmallInteger }" |
|
5833 |
srcOffset "{ Class: SmallInteger }" |
|
5834 |
dstOffset "{ Class: SmallInteger }" |
|
5835 |
w "{ Class: SmallInteger }" |
|
5836 |
h "{ Class: SmallInteger }" |
|
5837 |
first |
|
81 | 5838 |
newWidth newHeight newImage newBits |
5839 |
bitsPerPixel newBytesPerRow oldBytesPerRow| |
|
0 | 5840 |
|
81 | 5841 |
scalePoint := scale asPoint. |
5842 |
mX := scalePoint asPoint x. |
|
5843 |
mY := scalePoint asPoint y. |
|
46 | 5844 |
((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil]. |
0 | 5845 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
5846 |
||
12 | 5847 |
((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[ |
134 | 5848 |
^ self hardMagnifiedBy:scalePoint |
0 | 5849 |
]. |
5850 |
||
2 | 5851 |
bitsPerPixel := self depth. |
0 | 5852 |
oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8. |
5853 |
||
46 | 5854 |
w := width. |
5855 |
h := height. |
|
5856 |
magX := mX. |
|
5857 |
magY := mY. |
|
5858 |
||
5859 |
newWidth := w * mX. |
|
5860 |
newHeight := h * mY. |
|
0 | 5861 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
5862 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
5863 |
||
5864 |
newImage := self species new. |
|
2 | 5865 |
newImage bits:newBits. |
0 | 5866 |
newImage width:newWidth. |
5867 |
newImage height:newHeight. |
|
5868 |
newImage photometric:photometric. |
|
5869 |
newImage samplesPerPixel:samplesPerPixel. |
|
5870 |
newImage bitsPerSample:bitsPerSample. |
|
5871 |
newImage colorMap:colorMap copy. |
|
5872 |
||
5873 |
mX = 1 ifTrue:[ |
|
72 | 5874 |
"expand rows only" |
5875 |
srcOffset := 1. |
|
5876 |
dstOffset := 1. |
|
0 | 5877 |
|
72 | 5878 |
1 to:h do:[:row | |
5879 |
1 to:mY do:[:i | |
|
5880 |
newBits replaceFrom:dstOffset |
|
5881 |
to:(dstOffset + oldBytesPerRow - 1) |
|
5882 |
with:bytes |
|
5883 |
startingAt:srcOffset. |
|
5884 |
dstOffset := dstOffset + newBytesPerRow |
|
5885 |
]. |
|
5886 |
srcOffset := srcOffset + oldBytesPerRow. |
|
5887 |
]. |
|
0 | 5888 |
] ifFalse:[ |
72 | 5889 |
"expand cols" |
5890 |
(mX > 1) ifTrue:[ |
|
5891 |
dstOffset := 1. |
|
5892 |
srcOffset := 1. |
|
5893 |
1 to:h do:[:row | |
|
5894 |
self magnifyRowFrom:bytes |
|
5895 |
offset:srcOffset |
|
5896 |
into:newBits |
|
5897 |
offset:dstOffset |
|
5898 |
factor:mX. |
|
0 | 5899 |
|
72 | 5900 |
first := dstOffset. |
5901 |
dstOffset := dstOffset + newBytesPerRow. |
|
5902 |
" and copy for row expansion " |
|
5903 |
2 to:mY do:[:i | |
|
5904 |
newBits replaceFrom:dstOffset |
|
5905 |
to:(dstOffset + newBytesPerRow - 1) |
|
5906 |
with:newBits |
|
5907 |
startingAt:first. |
|
5908 |
dstOffset := dstOffset + newBytesPerRow |
|
5909 |
]. |
|
5910 |
srcOffset := srcOffset + oldBytesPerRow. |
|
5911 |
]. |
|
5912 |
] |
|
0 | 5913 |
]. |
5914 |
^ newImage |
|
5915 |
||
134 | 5916 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)" |
2 | 5917 |
! |
5918 |
||
154 | 5919 |
magnifiedPreservingRatioTo:anExtent |
5920 |
"return a new image magnified to fit into anExtent, |
|
5921 |
preserving the receivers width/height ratio. |
|
5922 |
(i.e. not distorting the image). |
|
5923 |
See also #magnifiedTo: and #magnifiedBy:" |
|
5924 |
||
5925 |
|rX rY| |
|
5926 |
||
5927 |
rX := anExtent x / self width. |
|
5928 |
rY := anExtent y / self height. |
|
5929 |
^ self magnifiedBy:(rX min:rY) |
|
5930 |
||
5931 |
" |
|
5932 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
5933 |
||
5934 |
in contrast to: |
|
5935 |
||
5936 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
|
5937 |
" |
|
5938 |
! |
|
5939 |
||
134 | 5940 |
magnifiedTo:anExtent |
154 | 5941 |
"return a new image magnified to have the size specified by extent. |
5942 |
This may distort the image if the arguments ratio is not the images ratio. |
|
5943 |
See also #magnifiedPreservingRatioTo: and #magnifiedBy:" |
|
89 | 5944 |
|
134 | 5945 |
^ self magnifiedBy:(anExtent / self extent) |
89 | 5946 |
|
5947 |
" |
|
134 | 5948 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
154 | 5949 |
|
5950 |
in contrast to: |
|
5951 |
||
5952 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
89 | 5953 |
" |
5954 |
! |
|
5955 |
||
12 | 5956 |
rotated:degrees |
5957 |
"return a new image from the old one, by rotating the image |
|
46 | 5958 |
degrees clockwise. |
592 | 5959 |
CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented." |
12 | 5960 |
|
46 | 5961 |
|w "{Class: SmallInteger }" |
5962 |
h "{Class: SmallInteger }" |
|
12 | 5963 |
c2 "{Class: SmallInteger }" |
692 | 5964 |
r2 "{Class: SmallInteger }" |
5965 |
nW "{Class: SmallInteger }" |
|
5966 |
nH "{Class: SmallInteger }" |
|
24 | 5967 |
newImage newBits newBytesPerRow d| |
12 | 5968 |
|
5969 |
d := degrees. |
|
5970 |
[d < 0] whileTrue:[d := d + 360]. |
|
5971 |
d >= 360 ifTrue:[d := d \\ 360]. |
|
46 | 5972 |
d := d truncated. |
5973 |
d == 0 ifTrue:[^ self]. |
|
5974 |
((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[ |
|
592 | 5975 |
^ self hardRotated:d |
12 | 5976 |
]. |
5977 |
||
692 | 5978 |
d == 180 ifTrue:[ |
5979 |
nW := width. |
|
5980 |
nH := height. |
|
5981 |
] ifFalse:[ |
|
5982 |
nW := height. |
|
5983 |
nH := width. |
|
5984 |
]. |
|
5985 |
||
5986 |
newBytesPerRow := ((nW * self depth) + 7) // 8. |
|
5987 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * nH). |
|
12 | 5988 |
|
5989 |
newImage := self species new. |
|
5990 |
newImage bits:newBits. |
|
692 | 5991 |
newImage width:nW. |
5992 |
newImage height:nH. |
|
12 | 5993 |
newImage photometric:photometric. |
5994 |
newImage samplesPerPixel:samplesPerPixel. |
|
5995 |
newImage bitsPerSample:bitsPerSample. |
|
5996 |
newImage colorMap:colorMap copy. |
|
5997 |
||
5998 |
w := width - 1. |
|
5999 |
h := height - 1. |
|
6000 |
||
6001 |
d == 90 ifTrue:[ |
|
592 | 6002 |
0 to:h do:[:row | |
6003 |
c2 := h-row. |
|
798 | 6004 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6005 |
newImage atX:c2 y:col putValue:pixel. |
592 | 6006 |
] |
692 | 6007 |
"/ 0 to:w do:[:col | |
6008 |
"/ newImage atX:c2 y:col putValue:(self valueAtX:col y:row). |
|
6009 |
"/ ] |
|
592 | 6010 |
] |
12 | 6011 |
]. |
46 | 6012 |
d == 180 ifTrue:[ |
592 | 6013 |
0 to:h do:[:row | |
692 | 6014 |
r2 := h - row. |
798 | 6015 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6016 |
newImage atX:(w-col) y:r2 putValue:pixel. |
592 | 6017 |
] |
692 | 6018 |
"/ 0 to:w do:[:col | |
6019 |
"/ newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row). |
|
6020 |
"/ ] |
|
592 | 6021 |
] |
46 | 6022 |
]. |
12 | 6023 |
d == 270 ifTrue:[ |
592 | 6024 |
0 to:h do:[:row | |
798 | 6025 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6026 |
newImage atX:row y:(w-col) putValue:pixel. |
592 | 6027 |
] |
692 | 6028 |
"/ 0 to:w do:[:col | |
6029 |
"/ newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row). |
|
6030 |
"/ ] |
|
592 | 6031 |
] |
12 | 6032 |
]. |
6033 |
^ newImage |
|
592 | 6034 |
|
692 | 6035 |
" |
6036 |
|i| |
|
6037 |
||
6038 |
i := Image fromFile:'claus.gif'. |
|
6039 |
i inspect. |
|
6040 |
(i rotated:90) inspect. |
|
6041 |
(i rotated:180) inspect. |
|
6042 |
(i rotated:270) inspect. |
|
6043 |
" |
|
6044 |
||
798 | 6045 |
"Modified: 7.6.1996 / 19:09:22 / cg" |
692 | 6046 |
! |
6047 |
||
6048 |
withPixelFunctionApplied:pixelFunctionBlock |
|
6049 |
"return a new image from the old one, by applying a pixel processor |
|
6050 |
(read `Behond photography, by Gerard J. Holzmann; |
|
6051 |
ISBM 0-13-074410-7) |
|
6052 |
See blurred / oilPointed as examples ...)" |
|
6053 |
||
6054 |
|w "{Class: SmallInteger }" |
|
6055 |
h "{Class: SmallInteger }" |
|
6056 |
newImage newBits newBytesPerRow d| |
|
6057 |
||
6058 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
6059 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
6060 |
||
6061 |
newImage := self species new. |
|
6062 |
newImage bits:newBits. |
|
6063 |
newImage width:width. |
|
6064 |
newImage height:height. |
|
6065 |
newImage photometric:photometric. |
|
6066 |
newImage samplesPerPixel:samplesPerPixel. |
|
6067 |
newImage bitsPerSample:bitsPerSample. |
|
6068 |
newImage colorMap:colorMap copy. |
|
6069 |
||
6070 |
w := width - 1. |
|
6071 |
h := height - 1. |
|
6072 |
||
6073 |
0 to:h do:[:y | |
|
6074 |
0 to:w do:[:x | |
|
6075 |
newImage atX:x y:y put:(pixelFunctionBlock |
|
6076 |
value:self |
|
6077 |
value:x |
|
6078 |
value:y) |
|
6079 |
] |
|
6080 |
]. |
|
6081 |
^ newImage |
|
6082 |
||
6083 |
" |
|
6084 |
|i| |
|
6085 |
||
6086 |
i := Image fromFile:'claus.gif'. |
|
6087 |
i inspect. |
|
6088 |
(i withPixelFunctionApplied:[:oldImage :x :y | |
|
6089 |
((x between:100 and:200) |
|
6090 |
and:[y between:100 and:200]) ifTrue:[ |
|
6091 |
oldImage atX:x y:y |
|
6092 |
] ifFalse:[ |
|
6093 |
Color black. |
|
6094 |
] |
|
6095 |
]) inspect. |
|
6096 |
" |
|
6097 |
||
6098 |
"Modified: 17.5.1996 / 12:31:44 / cg" |
|
283 | 6099 |
! ! |
6100 |
||
6101 |
!Image methodsFor:'inspecting'! |
|
6102 |
||
6103 |
inspectorClass |
|
6104 |
"redefined to launch an ImageInspector |
|
6105 |
(instead of the default InspectorView)." |
|
6106 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6107 |
(width notNil and:[height notNil]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6108 |
^ ImageInspectorView |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6109 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6110 |
^ super inspectorClass |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6111 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6112 |
"Modified: 10.6.1996 / 18:23:55 / cg" |
283 | 6113 |
! ! |
6114 |
||
6115 |
!Image methodsFor:'instance release'! |
|
6116 |
||
6117 |
disposed |
|
6118 |
"some Image has been collected - nothing to do" |
|
12 | 6119 |
! |
6120 |
||
283 | 6121 |
release |
6122 |
"release device resources" |
|
6123 |
||
6124 |
device := nil. |
|
6125 |
deviceForm := nil. |
|
6126 |
monoDeviceForm := nil. |
|
6127 |
fullColorDeviceForm := nil. |
|
6128 |
Lobby unregister:self |
|
46 | 6129 |
! |
6130 |
||
283 | 6131 |
restored |
6132 |
"flush device specifics after a snapin or binary restore" |
|
6133 |
||
6134 |
self release |
|
6135 |
! ! |
|
6136 |
||
592 | 6137 |
!Image methodsFor:'obsolete'! |
6138 |
||
6139 |
magnifyBy:scale |
|
6140 |
"obsolete: has been renamed to magnifiedBy: for ST-80 compatibility |
|
6141 |
and name consistency ..." |
|
6142 |
||
6143 |
self obsoleteMethodWarning. |
|
6144 |
^ self magnifiedBy:scale |
|
6145 |
! ! |
|
6146 |
||
283 | 6147 |
!Image methodsFor:'pixel copying'! |
6148 |
||
6149 |
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
6150 |
"replace a rectangulat area by pixels from another image. |
|
6151 |
WARNING: |
|
6152 |
This implementation is a slow fallback (the loop over the |
|
6153 |
source pixels is very slow). If this method is used heavily, you |
|
6154 |
may want to redefine it in concrete subclasses for the common case of |
|
6155 |
of copying from an Image with the same depth & palette." |
|
6156 |
||
6157 |
|dX dY| |
|
6158 |
||
6159 |
dX := srcX-dstX. |
|
6160 |
dY := srcY-dstY. |
|
6161 |
((photometric == anImage photometric) |
|
6162 |
and:[self bitsPerPixel == anImage bitsPerPixel |
|
6163 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
|
6164 |
"/ can loop over values |
|
6165 |
anImage valuesFromX:srcX y:srcY |
|
6166 |
toX:srcX+w-1 y:srcY+h-1 |
|
6167 |
do:[:x :y :pixelValue | |
|
6168 |
self atX:x-dX y:y-dY putValue:pixelValue. |
|
6169 |
] |
|
6170 |
] ifFalse:[ |
|
6171 |
"/ must loop over colors |
|
6172 |
anImage colorsFromX:srcX y:srcY |
|
6173 |
toX:srcX+w-1 y:srcY+h-1 |
|
6174 |
do:[:x :y :clr | |
|
6175 |
self atX:x-dX y:y-dY put:clr. |
|
6176 |
] |
|
6177 |
] |
|
6178 |
||
6179 |
" |
|
6180 |
|i1 i8 i4| |
|
6181 |
||
6182 |
i8 := Image fromFile:'bitmaps/garfield.gif'. |
|
6183 |
i8 inspect. |
|
6184 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
6185 |
i1 inspect. |
|
6186 |
||
6187 |
i4 := Depth4Image fromImage:i8. |
|
6188 |
i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30. |
|
6189 |
i4 inspect. |
|
6190 |
" |
|
6191 |
||
6192 |
"Created: 20.9.1995 / 10:14:01 / claus" |
|
6193 |
"Modified: 20.9.1995 / 10:25:31 / claus" |
|
6194 |
! |
|
6195 |
||
6196 |
subImageIn:aRectangle |
|
6197 |
"create and return a new image consisting of a subArea of myself" |
|
6198 |
||
6199 |
^ self class fromSubImage:self in:aRectangle |
|
6200 |
||
6201 |
" |
|
6202 |
|i| |
|
6203 |
||
6204 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
6205 |
i inspect. |
|
6206 |
(i subImageIn:(300@160 corner:340@200)) inspect |
|
6207 |
" |
|
6208 |
||
6209 |
"Created: 20.9.1995 / 01:24:20 / claus" |
|
6210 |
! ! |
|
6211 |
||
6212 |
!Image methodsFor:'printing & storing'! |
|
6213 |
||
6214 |
storeOn:aStream |
|
592 | 6215 |
"append a printed representation of the receiver to aStream, |
6216 |
from which a copy of it can be reconstructed." |
|
6217 |
||
283 | 6218 |
aStream nextPutAll:'(' , self class name , ' new)'. |
6219 |
aStream nextPutAll:' width: '. width storeOn:aStream. |
|
6220 |
aStream nextPutAll:'; height: '. height storeOn:aStream. |
|
6221 |
aStream nextPutAll:'; photometric:('. photometric storeOn:aStream. |
|
6222 |
aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream. |
|
6223 |
aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. |
|
6224 |
aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '. |
|
6225 |
colorMap notNil ifTrue:[ |
|
592 | 6226 |
aStream nextPutAll:'; colorMap:('. |
6227 |
colorMap storeOn:aStream. |
|
6228 |
aStream nextPutAll:')'. |
|
283 | 6229 |
]. |
6230 |
aStream nextPutAll:'; yourself' |
|
592 | 6231 |
|
6232 |
"Modified: 23.4.1996 / 11:18:05 / cg" |
|
0 | 6233 |
! ! |
6234 |
||
6235 |
!Image methodsFor:'private'! |
|
6236 |
||
193 | 6237 |
bestSupportedImageFormatFor:aDevice |
6238 |
"scan through the image formats as supported by aDevice, |
|
6239 |
and return the best to use when the receiver is to be represented |
|
6240 |
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
|
6241 |
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
|
6242 |
|
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6243 |
|bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel | |
193 | 6244 |
|
6245 |
myDepth := self bitsPerPixel. |
|
6246 |
maxBitsPerPixel := 0. |
|
6247 |
||
6248 |
aDevice supportedImageFormats do:[:entry | |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6249 |
|deviceImageDepth deviceImageBitsPerPixel| |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6250 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6251 |
deviceImageDepth := entry at:#depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6252 |
deviceImageBitsPerPixel := entry at:#bitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6253 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6254 |
deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6255 |
maxInfo := entry. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6256 |
"/ maxBitsPerPixel := deviceImageBitsPerPixel. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6257 |
"/ maxDepth := deviceImageDepth. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6258 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6259 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6260 |
deviceImageDepth >= myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6261 |
deviceImageDepth == myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6262 |
"/ take the better one ... |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6263 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6264 |
or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth) |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6265 |
and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6266 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6267 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6268 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6269 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6270 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6271 |
"/ take the next-larger depth |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6272 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6273 |
or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6274 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6275 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6276 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6277 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6278 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6279 |
]. |
193 | 6280 |
]. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6281 |
|
193 | 6282 |
bestDeviceDepth isNil ifTrue:[ |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6283 |
maxBitsPerPixel == 0 ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6284 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6285 |
"/ oops - nothing appropriate |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6286 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6287 |
maxInfo notNil ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6288 |
^ maxInfo |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6289 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6290 |
bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6291 |
bestInfo := IdentityDictionary new. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6292 |
bestInfo at:#depth put:bestDeviceDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6293 |
bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6294 |
bestInfo at:#padding put:32. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6295 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6296 |
bestInfo := maxInfo. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6297 |
] |
193 | 6298 |
]. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6299 |
^ bestInfo |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6300 |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6301 |
"Modified: 14.6.1996 / 14:46:40 / cg" |
283 | 6302 |
! |
6303 |
||
6304 |
colormapFromImage:anImage |
|
6305 |
"setup the receivers colormap from another image. |
|
6306 |
Color precision may be lost, if conversion is from a higher depth |
|
6307 |
image. This does not convert any pixel values; it is non-public helper |
|
6308 |
for fromImage:/fromSubImake:" |
|
6309 |
||
6310 |
samplesPerPixel == 3 ifTrue:[ |
|
6311 |
photometric := #rgb |
|
6312 |
] ifFalse:[ |
|
6313 |
photometric := anImage photometric. |
|
6314 |
photometric == #palette ifTrue:[ |
|
6315 |
colorMap := anImage colorMap copy. |
|
6316 |
" |
|
6317 |
must compress the colormap, if source image has higher depth |
|
6318 |
than myself. |
|
6319 |
" |
|
6320 |
anImage bitsPerPixel > self bitsPerPixel ifTrue:[ |
|
6321 |
" |
|
6322 |
get used colors are extracted into our colorMap |
|
6323 |
(the at-put below will set the pixelValue according the |
|
6324 |
new colorIndex |
|
6325 |
" |
|
6326 |
colorMap := anImage usedColors asArray. |
|
6327 |
colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[ |
|
6328 |
'IMAGE: possibly too many colors in image' errorPrintNL |
|
6329 |
] |
|
6330 |
] |
|
6331 |
] |
|
6332 |
]. |
|
6333 |
||
6334 |
"Created: 20.9.1995 / 00:58:42 / claus" |
|
6335 |
! |
|
6336 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6337 |
greyByteMapForRange:range |
798 | 6338 |
"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
|
6339 |
in the range 0..range. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6340 |
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
|
6341 |
The values are rounded towards the nearest pixel." |
798 | 6342 |
|
808 | 6343 |
|d n greyMap r| |
6344 |
||
6345 |
r := range. |
|
6346 |
r == 256 ifTrue:[ |
|
6347 |
r := 255 |
|
798 | 6348 |
]. |
6349 |
||
6350 |
photometric == #palette ifTrue:[ |
|
808 | 6351 |
n := colorMap size. |
6352 |
greyMap := ByteArray new:n. |
|
6353 |
||
6354 |
1 to:n do:[:i | |
|
6355 |
greyMap at:i put:(r * (colorMap at:i) brightness) rounded |
|
798 | 6356 |
]. |
6357 |
] ifFalse:[ |
|
808 | 6358 |
d := self bitsPerPixel. |
6359 |
n := 1 bitShift:d. |
|
6360 |
n >= 4096 ifTrue:[ |
|
6361 |
self error:'size not supported - too large'. |
|
6362 |
^ nil |
|
6363 |
]. |
|
6364 |
greyMap := ByteArray new:n. |
|
6365 |
||
6366 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6367 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6368 |
1 to:n do:[:i | |
808 | 6369 |
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
|
6370 |
]. |
798 | 6371 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6372 |
1 to:n do:[:i | |
808 | 6373 |
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
|
6374 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6375 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6376 |
"/ we are done |
798 | 6377 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6378 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6379 |
greyMap reverse |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6380 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6381 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6382 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6383 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6384 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6385 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6386 |
]. |
808 | 6387 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6388 |
^ greyMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6389 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6390 |
" |
808 | 6391 |
Depth8Image new greyByteMapForRange:256 |
6392 |
||
6393 |
Depth8Image new greyByteMapForRange:64 |
|
6394 |
Depth4Image new greyByteMapForRange:64 |
|
6395 |
||
6396 |
Depth4Image new greyByteMapForRange:1 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6397 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6398 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6399 |
"Created: 8.6.1996 / 08:34:14 / cg" |
808 | 6400 |
"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
|
6401 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6402 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6403 |
greyMapForRange:range |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6404 |
"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
|
6405 |
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
|
6406 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6407 |
|d r |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6408 |
n "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6409 |
greyArray| |
804
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 |
d := self bitsPerPixel. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6412 |
n := 1 bitShift:d. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6413 |
n >= 4096 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6414 |
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
|
6415 |
^ nil |
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 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6418 |
greyArray := Array new:n. |
804
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 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6421 |
1 to:(colorMap size) do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6422 |
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
|
6423 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6424 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6425 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6426 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6427 |
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
|
6428 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6429 |
] ifFalse:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6430 |
r := range asFloat. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6431 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6432 |
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
|
6433 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6434 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6435 |
"/ we are done |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6436 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6437 |
photometric == #whiteIs0 ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6438 |
greyArray reverse |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6439 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6440 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6441 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6442 |
] |
798 | 6443 |
] |
6444 |
] |
|
6445 |
]. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6446 |
^ greyArray |
798 | 6447 |
|
6448 |
" |
|
6449 |
Depth8Image new greyMapForRange:64 |
|
6450 |
Depth4Image new greyMapForRange:64 |
|
6451 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6452 |
Depth16Image new greyMapForRange:1 |
798 | 6453 |
Depth4Image new greyMapForRange:1 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6454 |
Depth2Image new greyMapForRange:1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6455 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6456 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6457 |
"Modified: 10.6.1996 / 10:37:40 / cg" |
798 | 6458 |
! |
6459 |
||
283 | 6460 |
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels |
6461 |
into:dstBytes offset:dstStart factor:mX |
|
6462 |
||
6463 |
"magnify a single pixel row - can only magnify by integer factors, |
|
6464 |
can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast." |
|
6465 |
||
6466 |
^ self subclassResponsibility |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6467 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6468 |
|
816 | 6469 |
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
6470 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6471 |
pixels interpreted as greyValues, 0 is black, |
|
6472 |
create a device form for it" |
|
6473 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6474 |
|f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6475 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6476 |
f := Form width:width height:height depth:depth on:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6477 |
f isNil ifTrue:[^ nil]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6478 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6479 |
f bits:bits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6480 |
f initGC. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6481 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6482 |
(aDevice blackpixel ~~ 0) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6483 |
"/ have to invert bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6484 |
f function:#copyInverted |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6485 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6486 |
aDevice drawBits:bits depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6487 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6488 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6489 |
into:(f id) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6490 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6491 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6492 |
with:(f gcId). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6493 |
^ f |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6494 |
|
816 | 6495 |
"Created: 10.6.1996 / 20:10:31 / cg" |
6496 |
! |
|
6497 |
||
6498 |
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
6499 |
"given the bits of a monochrome bitmap, 8-bit padded and |
|
6500 |
0-bits as black, create a device form for it" |
|
6501 |
||
6502 |
monoBits invert. |
|
6503 |
^ (Form width:width height:height fromArray:monoBits on:aDevice) |
|
6504 |
colorMap:(Array with:Color black with:Color white). |
|
6505 |
||
6506 |
"Created: 10.6.1996 / 20:18:09 / cg" |
|
6507 |
"Modified: 10.6.1996 / 20:31:24 / cg" |
|
6508 |
! |
|
6509 |
||
6510 |
makeDevicePixmapOn:aDevice depth:depth fromArray:bits |
|
6511 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6512 |
pixels interpreted as in the devices colormap, |
|
6513 |
create a device form for it" |
|
6514 |
||
6515 |
|f| |
|
6516 |
||
6517 |
f := Form width:width height:height depth:depth on:aDevice. |
|
6518 |
f isNil ifTrue:[^ nil]. |
|
6519 |
||
6520 |
f bits:bits. |
|
6521 |
f initGC. |
|
6522 |
||
6523 |
aDevice drawBits:bits depth:depth |
|
6524 |
width:width height:height |
|
6525 |
x:0 y:0 |
|
6526 |
into:(f id) |
|
6527 |
x:0 y:0 |
|
6528 |
width:width height:height |
|
6529 |
with:(f gcId). |
|
6530 |
^ f |
|
6531 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6532 |
"Created: 10.6.1996 / 17:56:08 / cg" |
816 | 6533 |
"Modified: 10.6.1996 / 20:11:27 / cg" |
2 | 6534 |
! ! |
0 | 6535 |
|
283 | 6536 |
!Image methodsFor:'queries'! |
6537 |
||
6538 |
averageColor |
|
6539 |
"return the average color of the image. |
|
6540 |
This usually only makes sense for textures and patterns |
|
6541 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
6542 |
Notice, that for the above purpose, it is usually ok to process |
|
6543 |
a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle" |
|
6544 |
||
6545 |
^ self averageColorIn:(0@0 corner:(width-1)@(height-1)) |
|
6546 |
! |
|
6547 |
||
6548 |
averageColorIn:aRectangle |
|
6549 |
"return the images average color in an area. |
|
6550 |
The implementation below is slow - so you may want to |
|
6551 |
create tuned versions for DepthXImage if you plan to do |
|
6552 |
heavy image processing ... |
|
6553 |
(also, creating tuned versions of the enumeration messages helps a lot)" |
|
6554 |
||
6555 |
|x0 "{ Class:SmallInteger }" |
|
6556 |
y0 "{ Class:SmallInteger }" |
|
6557 |
x1 "{ Class:SmallInteger }" |
|
6558 |
y1 "{ Class:SmallInteger }" |
|
6559 |
sumRed sumGreen sumBlue n| |
|
6560 |
||
6561 |
sumRed := sumGreen := sumBlue := 0. |
|
6562 |
y0 := aRectangle top. |
|
6563 |
y1 := aRectangle bottom. |
|
6564 |
x0 := aRectangle left. |
|
6565 |
x1 := aRectangle right. |
|
6566 |
||
6567 |
self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY | |
|
6568 |
sumRed := sumRed + colorAtXY red. |
|
6569 |
sumGreen := sumGreen + colorAtXY green. |
|
6570 |
sumBlue := sumBlue + colorAtXY blue. |
|
6571 |
]. |
|
6572 |
n := (x1 - x0 + 1) * (y1 - y0 + 1). |
|
6573 |
^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n) |
|
6574 |
! |
|
6575 |
||
6576 |
bitsPerPixel |
|
6577 |
"return the number of bits per pixel" |
|
6578 |
||
6579 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
|
6580 |
! |
|
6581 |
||
6582 |
bitsPerRow |
|
6583 |
"return the number of bits in one scanline of the image" |
|
6584 |
||
6585 |
^ width * (self bitsPerPixel). |
|
6586 |
! |
|
6587 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6588 |
blueBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6589 |
"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
|
6590 |
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
|
6591 |
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
|
6592 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6593 |
|blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6594 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6595 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6596 |
"/ 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
|
6597 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6598 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6599 |
blueBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6600 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6601 |
^ pixel bitAnd:(1 bitShift:blueBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6602 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6603 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6604 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6605 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6606 |
"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
|
6607 |
"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
|
6608 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6609 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6610 |
blueComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6611 |
"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
|
6612 |
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
|
6613 |
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
|
6614 |
|
854 | 6615 |
|blueBits "{ Class: SmallInteger }" |
6616 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6617 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6618 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6619 |
"/ 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
|
6620 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6621 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6622 |
blueBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6623 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6624 |
s := (1 bitShift:blueBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6625 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6626 |
^ 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
|
6627 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6628 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6629 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6630 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6631 |
"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
|
6632 |
"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
|
6633 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6634 |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6635 |
bounds |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6636 |
"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
|
6637 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6638 |
^ 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
|
6639 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6640 |
"Created: 13.5.1996 / 10:27:06 / cg" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6641 |
! |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6642 |
|
283 | 6643 |
brightness |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6644 |
"return the (average) brightness of the image. |
283 | 6645 |
This usually only makes sense for textures and patterns |
6646 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
6647 |
Notice, that for the above purpose, only a subimage is inspected here" |
|
6648 |
||
6649 |
^ (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
|
6650 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6651 |
"Modified: 8.6.1996 / 08:46:46 / cg" |
283 | 6652 |
! |
6653 |
||
6654 |
bytesPerRow |
|
6655 |
"return the number of bytes in one scanline of the image" |
|
6656 |
||
6657 |
|bitsPerRow bytesPerRow| |
|
6658 |
||
6659 |
bitsPerRow := width * (self bitsPerPixel). |
|
6660 |
bytesPerRow := bitsPerRow // 8. |
|
6661 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
6662 |
bytesPerRow := bytesPerRow + 1 |
|
6663 |
]. |
|
6664 |
^ bytesPerRow |
|
6665 |
! |
|
6666 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6667 |
colorFromValue:pixelValue |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6668 |
"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
|
6669 |
Pixel values start with 0." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6670 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6671 |
|maxPixel r g b| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6672 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6673 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6674 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6675 |
^ Color gray:(pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6676 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6677 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6678 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6679 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6680 |
^ Color gray:100 - (pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6681 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6682 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6683 |
photometric == #palette ifTrue:[ |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6684 |
pixelValue >= colorMap size ifTrue:[ |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6685 |
^ Color black |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6686 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6687 |
^ colorMap at:(pixelValue + 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6688 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6689 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6690 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6691 |
r := self redComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6692 |
g := self greenComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6693 |
b := self blueComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6694 |
^ 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
|
6695 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6696 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6697 |
self error:'invalid photometric' |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6698 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6699 |
"Created: 8.6.1996 / 08:46:18 / cg" |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
6700 |
"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
|
6701 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6702 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6703 |
greenBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6704 |
"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
|
6705 |
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
|
6706 |
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
|
6707 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6708 |
|blueBits greenBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6709 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6710 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6711 |
"/ 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
|
6712 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6713 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6714 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6715 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6716 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6717 |
^ (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
|
6718 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6719 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6720 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6721 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6722 |
"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
|
6723 |
"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
|
6724 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6725 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6726 |
greenComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6727 |
"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
|
6728 |
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
|
6729 |
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
|
6730 |
|
854 | 6731 |
|greenBits "{ Class: SmallInteger }" |
6732 |
blueBits "{ Class: SmallInteger }" |
|
6733 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6734 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6735 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6736 |
"/ 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
|
6737 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6738 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6739 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6740 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6741 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6742 |
s := (1 bitShift:greenBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6743 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6744 |
^ 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
|
6745 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6746 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6747 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6748 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6749 |
"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
|
6750 |
"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
|
6751 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6752 |
|
674 | 6753 |
heightOn:aGC |
6754 |
"return my height, if displayed on aGC; |
|
6755 |
since my height is independent of the device (the number of pixels), |
|
6756 |
return the pixel-height" |
|
6757 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6758 |
^ height |
674 | 6759 |
|
6760 |
"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
|
6761 |
"Modified: 13.5.1996 / 10:26:36 / cg" |
674 | 6762 |
! |
6763 |
||
283 | 6764 |
isImage |
6765 |
"return true, if the receiver is some kind of image; |
|
6766 |
true is returned here - the method is redefined from Object." |
|
6767 |
||
6768 |
^ true |
|
6769 |
! |
|
6770 |
||
6771 |
isImageOrForm |
|
6772 |
"return true, if the receiver is some kind of image or form; |
|
6773 |
true is returned here - the method is redefined from Object." |
|
6774 |
||
6775 |
^ true |
|
6776 |
! |
|
6777 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6778 |
redBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6779 |
"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
|
6780 |
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
|
6781 |
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
|
6782 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6783 |
|redBits greenBits blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6784 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6785 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6786 |
"/ 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
|
6787 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6788 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6789 |
redBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6790 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6791 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6792 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6793 |
^ (pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6794 |
bitAnd:(1 bitShift:redBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6795 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6796 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6797 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6798 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6799 |
"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
|
6800 |
"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
|
6801 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6802 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6803 |
redComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6804 |
"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
|
6805 |
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
|
6806 |
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
|
6807 |
|
854 | 6808 |
|redBits "{ Class: SmallInteger }" |
6809 |
greenBits "{ Class: SmallInteger }" |
|
6810 |
blueBits "{ Class: SmallInteger }" |
|
6811 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6812 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6813 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6814 |
"/ 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
|
6815 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6816 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6817 |
redBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6818 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6819 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6820 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6821 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6822 |
s := (1 bitShift:redBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6823 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6824 |
^ 100.0 / s * |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6825 |
((pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6826 |
bitAnd:(1 bitShift:redBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6827 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6828 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6829 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6830 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6831 |
"Created: 8.6.1996 / 08:45:30 / cg" |
854 | 6832 |
"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
|
6833 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6834 |
|
283 | 6835 |
usedColors |
6836 |
"return a collection of colors used in the receiver." |
|
6837 |
||
6838 |
|usedValues max| |
|
6839 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6840 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6841 |
"/ 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
|
6842 |
"/ 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
|
6843 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6844 |
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
|
6845 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6846 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6847 |
|
283 | 6848 |
usedValues := self usedValues asArray. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6849 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6850 |
^ usedValues collect:[:val | (colorMap at:val+1)] |
283 | 6851 |
]. |
6852 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6853 |
"/ (photometric == #blackIs0 or:[photometric == #whiteIs0]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6854 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6855 |
max := (1 bitShift:self depth) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6856 |
^ usedValues collect:[:val | (Color gray:(100 * val / max ))] |
283 | 6857 |
|
6858 |
" |
|
6859 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
6860 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
6861 |
(Image fromFile:'ttt.tiff') usedColors |
|
6862 |
" |
|
746 | 6863 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6864 |
"Modified: 8.6.1996 / 09:04:56 / cg" |
283 | 6865 |
! |
6866 |
||
6867 |
usedValues |
|
6868 |
"return a collection of color values used in the receiver. |
|
6869 |
Notice, that the interpretation of the pixels depends on the photometric |
|
6870 |
of the image. |
|
6871 |
This is a general and therefore slow implementation; subclasses |
|
6872 |
may want to redefine this method for more performance." |
|
6873 |
||
6874 |
|set| |
|
6875 |
||
6876 |
set := IdentitySet new. |
|
6877 |
self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel | |
|
6878 |
set add:pixel |
|
6879 |
]. |
|
6880 |
^ set |
|
6881 |
||
6882 |
" |
|
6883 |
(Image fromFile:'bitmaps/garfield.gif') usedValues |
|
6884 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedValues |
|
6885 |
(Image fromFile:'ttt.tiff') usedValues |
|
6886 |
" |
|
674 | 6887 |
! |
6888 |
||
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6889 |
valueFromColor:color |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6890 |
"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
|
6891 |
Non-representable colors return nil." |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6892 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6893 |
|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
|
6894 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6895 |
photometric == #whiteIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6896 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6897 |
^ maxPixel - (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6898 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6899 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6900 |
photometric == #blackIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6901 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6902 |
^ (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6903 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6904 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6905 |
photometric == #palette ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6906 |
pixel := colorMap indexOf:color. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6907 |
pixel == 0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6908 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6909 |
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
|
6910 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6911 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6912 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6913 |
^ pixel - 1 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6914 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6915 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6916 |
photometric == #rgb ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6917 |
samplesPerPixel >= 3 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6918 |
redBits := bitsPerSample at:1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6919 |
greenBits := bitsPerSample at:2. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6920 |
blueBits := bitsPerSample at:3. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6921 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6922 |
"/ map r/g/b to 0..255 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6923 |
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
|
6924 |
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
|
6925 |
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
|
6926 |
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
|
6927 |
^ pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6928 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6929 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6930 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6931 |
self error:'format not supported'. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6932 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6933 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6934 |
"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
|
6935 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6936 |
|
674 | 6937 |
widthOn:aGC |
6938 |
"return my width, if displayed on aGC; |
|
6939 |
since my width is independent of the device (the number of pixels), |
|
6940 |
return the pixel-width" |
|
6941 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6942 |
^ width |
674 | 6943 |
|
6944 |
"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
|
6945 |
"Modified: 13.5.1996 / 10:26:42 / cg" |
283 | 6946 |
! ! |
6947 |
||
6948 |
!Image methodsFor:'saving on file'! |
|
6949 |
||
6950 |
saveOn:aFileName |
|
6951 |
"save the image in a aFileName. The suffix of the filename |
|
6952 |
controls the format. Currently, not all formats may be supported |
|
6953 |
(see ImageReader subclasses implementing save:onFile:)" |
|
6954 |
||
6955 |
" |
|
6956 |
from the extension, get the imageReader class |
|
6957 |
(which should know how to write images as well) |
|
6958 |
" |
|
6959 |
FileFormats associationsDo:[:a | |
|
6960 |
(aFileName endsWith:(a key)) ifTrue:[ |
|
6961 |
^ (a value) save:self onFile:aFileName |
|
6962 |
] |
|
6963 |
]. |
|
6964 |
||
6965 |
" |
|
6966 |
no known extension - could ask user for the format here. |
|
6967 |
currently default to tiff format. |
|
6968 |
" |
|
6969 |
'IMAGE: unknown extension - cannot figure out format - using tiff' errorPrintNL. |
|
6970 |
^ self saveOn:aFileName using:TIFFReader |
|
89 | 6971 |
! |
6972 |
||
283 | 6973 |
saveOn:aFileName using:readerClass |
6974 |
"save the receiver using the representation class" |
|
6975 |
||
6976 |
readerClass save:self onFile:aFileName |
|
6977 |
||
6978 |
" |
|
6979 |
anImage saveOn:'myImage' using:TIFFReader |
|
6980 |
anImage saveOn:'myImage' using:XBMReader |
|
6981 |
" |
|
0 | 6982 |
! ! |
283 | 6983 |
|
6984 |
!Image methodsFor:'screen capture'! |
|
6985 |
||
6986 |
fromScreen:aRectangle |
|
6987 |
"read an image from the display screen" |
|
6988 |
||
6989 |
^ self fromScreen:aRectangle on:Screen current |
|
6990 |
! |
|
6991 |
||
6992 |
fromScreen:aRectangle on:aDevice |
|
6993 |
"read an image from aDevices display screen. |
|
6994 |
Since I have no other displays, only the MonoChrome, StaticGrey |
|
6995 |
and PseudoColor cases have been tested ... |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6996 |
(especially True- and DirectColor may be wrong). |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
6997 |
Late note: 24bit rgb now also works." |
283 | 6998 |
|
6999 |
|depth visType |
|
7000 |
x "{ Class: SmallInteger }" |
|
7001 |
y "{ Class: SmallInteger }" |
|
7002 |
w "{ Class: SmallInteger }" |
|
7003 |
h "{ Class: SmallInteger }" |
|
7004 |
dstIndex "{ Class: SmallInteger }" |
|
7005 |
srcIndex "{ Class: SmallInteger }" |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7006 |
srcRow "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7007 |
dstRow "{ Class: SmallInteger }" |
283 | 7008 |
inData tmpData usedPixels mapSize |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7009 |
map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7010 |
info bitsPerPixelIn bytesPerLineIn curs cid rootView |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7011 |
maskR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7012 |
maskG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7013 |
maskB "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7014 |
shR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7015 |
shG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7016 |
shB "{ Class: SmallInteger }" |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7017 |
shR2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7018 |
shG2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7019 |
shB2 "{ Class: SmallInteger }" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7020 |
r "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7021 |
g "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7022 |
b "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7023 |
word| |
283 | 7024 |
|
7025 |
curs := Cursor sourceForm:(Form fromFile:'Camera.xbm') |
|
518 | 7026 |
maskForm:(Form fromFile:'Camera_m.xbm') |
7027 |
hotSpot:16@16. |
|
283 | 7028 |
curs notNil ifTrue:[ |
518 | 7029 |
cid := (curs on:aDevice) id |
283 | 7030 |
]. |
7031 |
||
7032 |
" |
|
7033 |
get some attributes of the display device |
|
7034 |
" |
|
7035 |
visType := aDevice visualType. |
|
7036 |
depth := aDevice depth. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7037 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7038 |
"/ kludge for 15bit XFree server |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7039 |
depth == 15 ifTrue:[ |
518 | 7040 |
depth := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7041 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7042 |
|
283 | 7043 |
(visType == #StaticGray) ifTrue:[ |
518 | 7044 |
(aDevice blackpixel == 0) ifTrue:[ |
7045 |
photometric := #blackIs0 |
|
7046 |
] ifFalse:[ |
|
7047 |
photometric := #whiteIs0 |
|
7048 |
]. |
|
7049 |
samplesPerPixel := 1. |
|
7050 |
bitsPerPixel := depth. |
|
7051 |
bitsPerSample := Array with:bitsPerPixel. |
|
283 | 7052 |
] ifFalse:[ |
518 | 7053 |
((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[ |
7054 |
photometric := #palette. |
|
7055 |
samplesPerPixel := 1. |
|
7056 |
bitsPerPixel := depth. |
|
7057 |
bitsPerSample := Array with:bitsPerPixel. |
|
7058 |
] ifFalse:[ |
|
7059 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
7060 |
photometric := #rgb. |
|
7061 |
samplesPerPixel := 3. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7062 |
"/ bitsPerPixel := depth. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7063 |
"/ 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
|
7064 |
"/ with:aDevice bitsGreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7065 |
"/ with:aDevice bitsBlue |
518 | 7066 |
bitsPerPixel := 24. |
7067 |
bitsPerSample := #(8 8 8). |
|
7068 |
] ifFalse:[ |
|
7069 |
self error:'screen visual not supported'. |
|
7070 |
^ nil |
|
7071 |
] |
|
7072 |
] |
|
283 | 7073 |
]. |
7074 |
||
7075 |
" |
|
7076 |
dont know yet, how the display pads; assume worst case, |
|
7077 |
offering enough space for 32 bit padding |
|
7078 |
" |
|
7079 |
w := width := aRectangle width. |
|
7080 |
h := height := aRectangle height. |
|
7081 |
x := aRectangle left. |
|
7082 |
y := aRectangle top. |
|
7083 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7084 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7085 |
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
|
7086 |
(its too late when info is present ...) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7087 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7088 |
spaceBitsPerPixel := bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7089 |
(bitsPerPixel > 8) ifTrue:[ |
518 | 7090 |
spaceBitsPerPixel := 16. |
7091 |
(bitsPerPixel > 16) ifTrue:[ |
|
7092 |
spaceBitsPerPixel := 32. |
|
7093 |
(bitsPerPixel > 32) ifTrue:[ |
|
7094 |
spaceBitsPerPixel := bitsPerPixel. |
|
7095 |
] |
|
7096 |
] |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7097 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7098 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7099 |
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4. |
283 | 7100 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
7101 |
||
7102 |
" |
|
7103 |
actually have to grabServer ... but thats not yet available |
|
7104 |
" |
|
728 | 7105 |
rootView := aDevice rootView. |
283 | 7106 |
aDevice setActivePointerGrab:rootView. |
7107 |
aDevice grabPointerIn:rootView id |
|
518 | 7108 |
withCursor:cid pointerMode:#async keyboardMode:#sync confineTo:nil. |
283 | 7109 |
|
7110 |
" |
|
7111 |
get the pixels |
|
7112 |
" |
|
7113 |
info := aDevice getBitsFrom:rootView id x:x y:y width:w height:h into:inData. |
|
7114 |
||
7115 |
" |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7116 |
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
|
7117 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7118 |
byteOrder := info at:#byteOrder. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7119 |
bitsPerPixelIn := info at:#bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7120 |
byteOrder ~~ #msbFirst ifTrue:[ |
518 | 7121 |
bitsPerPixelIn == 16 ifTrue:[ |
7122 |
"/ must swap bytes |
|
7123 |
inData swapBytes |
|
7124 |
] ifFalse:[ |
|
7125 |
bitsPerPixelIn == 32 ifTrue:[ |
|
7126 |
"/ must swap longs |
|
7127 |
inData swapLongs |
|
7128 |
] |
|
7129 |
] |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7130 |
]. |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7131 |
|
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7132 |
" |
283 | 7133 |
check, if the devices padding is different .. |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7134 |
or if the bitsPerPixels are different |
283 | 7135 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7136 |
bytesPerLineIn := (info at:#bytesPerLine). "what I got" |
283 | 7137 |
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
|
7138 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7139 |
((bytesPerLine ~~ bytesPerLineIn) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7140 |
or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[ |
518 | 7141 |
tmpData := inData. |
7142 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
7143 |
||
7144 |
srcRow := 1. |
|
7145 |
dstRow := 1. |
|
7146 |
||
7147 |
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[ |
|
7148 |
"/ for now, only 32 -> 24 is supported |
|
7149 |
||
7150 |
maskR := (1 bitShift:aDevice bitsRed) - 1. |
|
7151 |
maskG := (1 bitShift:aDevice bitsGreen) - 1. |
|
7152 |
maskB := (1 bitShift:aDevice bitsBlue) - 1. |
|
7153 |
shR := aDevice shiftRed negated. |
|
7154 |
shG := aDevice shiftGreen negated. |
|
7155 |
shB := aDevice shiftBlue negated. |
|
7156 |
shR2 := (8 - aDevice bitsRed). |
|
7157 |
shG2 := (8 - aDevice bitsGreen). |
|
7158 |
shB2 := (8 - aDevice bitsBlue). |
|
7159 |
||
7160 |
((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[ |
|
7161 |
"/ 'reformatting 32->24...' printNL. |
|
7162 |
1 to:h do:[:hi | |
|
7163 |
srcIndex := srcRow. |
|
7164 |
dstIndex := dstRow. |
|
7165 |
||
7166 |
1 to:w do:[:wi | |
|
7167 |
word := tmpData doubleWordAt:srcIndex MSB:true. |
|
7168 |
r := (word bitShift:shR) bitAnd:maskR. |
|
7169 |
g := (word bitShift:shG) bitAnd:maskG. |
|
7170 |
b := (word bitShift:shB) bitAnd:maskB. |
|
7171 |
||
7172 |
inData at:dstIndex put:r. |
|
7173 |
inData at:dstIndex+1 put:g. |
|
7174 |
inData at:dstIndex+2 put:b. |
|
7175 |
srcIndex := srcIndex + 4. |
|
7176 |
dstIndex := dstIndex + 3. |
|
7177 |
]. |
|
7178 |
dstRow := dstRow + bytesPerLine. |
|
7179 |
srcRow := srcRow + bytesPerLineIn |
|
7180 |
] |
|
7181 |
] ifFalse:[ |
|
7182 |
((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[ |
|
7183 |
"/ 'reformatting 16->24...' printNL. |
|
7184 |
1 to:h do:[:hi | |
|
7185 |
srcIndex := srcRow. |
|
7186 |
dstIndex := dstRow. |
|
7187 |
||
7188 |
1 to:w do:[:wi | |
|
7189 |
word := tmpData wordAt:srcIndex MSB:true. |
|
7190 |
r := (word bitShift:shR) bitAnd:maskR. |
|
7191 |
g := (word bitShift:shG) bitAnd:maskG. |
|
7192 |
b := (word bitShift:shB) bitAnd:maskB. |
|
7193 |
||
7194 |
inData at:dstIndex put:(r bitShift:shR2). |
|
7195 |
inData at:dstIndex+1 put:(g bitShift:shG2). |
|
7196 |
inData at:dstIndex+2 put:(b bitShift:shB2). |
|
7197 |
srcIndex := srcIndex + 2. |
|
7198 |
dstIndex := dstIndex + 3. |
|
7199 |
]. |
|
7200 |
dstRow := dstRow + bytesPerLine. |
|
7201 |
srcRow := srcRow + bytesPerLineIn |
|
7202 |
] |
|
7203 |
] ifFalse:[ |
|
7204 |
('IMAGE: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' , |
|
7205 |
bitsPerPixel printString) errorPrintNL. |
|
7206 |
^ nil |
|
7207 |
] |
|
7208 |
]. |
|
7209 |
] ifFalse:[ |
|
7210 |
" |
|
7211 |
repad in the buffer |
|
7212 |
" |
|
7213 |
1 to:h do:[:hi | |
|
7214 |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1) |
|
7215 |
with:tmpData startingAt:srcRow. |
|
7216 |
dstRow := dstRow + bytesPerLine. |
|
7217 |
srcRow := srcRow + bytesPerLineIn |
|
7218 |
] |
|
7219 |
] |
|
283 | 7220 |
] ifFalse:[ |
518 | 7221 |
(bytesPerLine * height) ~~ inData size ifTrue:[ |
7222 |
tmpData := inData. |
|
7223 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
7224 |
inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1 |
|
7225 |
] |
|
283 | 7226 |
]. |
7227 |
bytes := inData. |
|
7228 |
||
7229 |
"info printNL." |
|
7230 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7231 |
((visType == #StaticGray) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7232 |
or:[visType == #TrueColor |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7233 |
or:[visType == #DirectColor]]) ifTrue:[ |
518 | 7234 |
" |
7235 |
were done, the pixel values are the rgb/grey values |
|
7236 |
" |
|
283 | 7237 |
] ifFalse:[ |
518 | 7238 |
" |
7239 |
what we have now are the color numbers - still need the r/g/b values. |
|
7240 |
find out, which colors are in the picture |
|
7241 |
" |
|
7242 |
usedPixels := inData usedValues. |
|
7243 |
mapSize := usedPixels max + 1. |
|
7244 |
||
7245 |
"get the palette" |
|
7246 |
map := Array new:mapSize. |
|
7247 |
usedPixels do:[:colorIndex | |
|
7248 |
|i| |
|
7249 |
||
7250 |
i := colorIndex + 1. |
|
7251 |
aDevice getRGBFrom:colorIndex into:[:r :g :b | |
|
7252 |
map at:i put:(Color red:r green:g blue:b) |
|
7253 |
] |
|
7254 |
]. |
|
7255 |
colorMap := map. |
|
283 | 7256 |
]. |
7257 |
||
7258 |
aDevice ungrabPointer. |
|
7259 |
||
7260 |
" |
|
7261 |
(Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display |
|
7262 |
(Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display |
|
7263 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7264 |
|
518 | 7265 |
"Modified: 7.3.1996 / 19:17:33 / cg" |
283 | 7266 |
! ! |
7267 |
||
7268 |
!Image class methodsFor:'documentation'! |
|
7269 |
||
7270 |
version |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
7271 |
^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.101 1996-06-17 12:47:28 cg Exp $' |
650 | 7272 |
! ! |
283 | 7273 |
Image initialize! |