author | Claus Gittinger <cg@exept.de> |
Mon, 17 Jun 1996 20:28:45 +0200 | |
changeset 882 | a3181765132b |
parent 879 | 2adf7645e7e6 |
child 883 | 15b0fb66d2a5 |
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 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
883 |
ditherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
884 |
"return the way we dither - |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
885 |
#threshold, or nil -> no dither |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
886 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
887 |
#error or #floydSteinberg -> errorDiffusion; much better |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
888 |
#burkes -> errorDiffusion; even better." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
889 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
890 |
^ DitherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
891 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
892 |
"Created: 17.6.1996 / 18:57:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
893 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
894 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
895 |
ditherAlgorithm:aSymbol |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
896 |
"define how to dither - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
897 |
#threshold, or nil -> no dither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
898 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
899 |
#error or #floydSteinberg -> errorDiffusion; much better |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
900 |
#burkes -> errorDiffusion; even better." |
283 | 901 |
|
902 |
DitherAlgorithm := aSymbol |
|
903 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
904 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
905 |
Image dither:#pattern |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
906 |
Image dither:#floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
907 |
Image dither:#burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
908 |
Image dither:nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
909 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
910 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
911 |
"Modified: 10.6.1996 / 12:27:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
912 |
"Created: 17.6.1996 / 18:57:19 / cg" |
283 | 913 |
! |
914 |
||
915 |
numberOfDitherColors:n |
|
916 |
"define how many colors (i.e. patterns) to use when |
|
917 |
doing a pattern dither" |
|
918 |
||
919 |
NumberOfDitherColors := n |
|
798 | 920 |
! |
921 |
||
922 |
orderedDitherMatrixOfSize:sz |
|
923 |
sz == 2 ifTrue:[ |
|
924 |
^ #[ |
|
925 |
0 2 |
|
926 |
3 1 |
|
927 |
]. |
|
928 |
]. |
|
929 |
||
930 |
sz == 4 ifTrue:[ |
|
931 |
^ #[ |
|
932 |
0 8 2 10 |
|
933 |
12 4 14 6 |
|
934 |
3 11 1 9 |
|
935 |
15 7 13 5 |
|
936 |
]. |
|
937 |
]. |
|
938 |
||
939 |
sz == 8 ifTrue:[ |
|
940 |
^ #[ |
|
941 |
0 32 8 40 2 34 10 42 |
|
942 |
48 16 56 24 50 18 58 26 |
|
943 |
12 44 4 36 14 46 6 38 |
|
944 |
60 28 52 20 62 30 54 22 |
|
945 |
||
946 |
3 35 11 43 1 33 9 41 |
|
947 |
51 19 59 27 49 17 57 25 |
|
948 |
15 47 7 39 13 45 5 37 |
|
949 |
63 31 55 23 61 29 53 21 |
|
950 |
]. |
|
951 |
]. |
|
952 |
||
953 |
^ nil |
|
954 |
||
955 |
"Created: 7.6.1996 / 14:15:05 / cg" |
|
283 | 956 |
! ! |
957 |
||
958 |
!Image class methodsFor:'queries'! |
|
959 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
960 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
961 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
962 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
963 |
^ #blackIs0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
964 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
965 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
966 |
"Created: 10.6.1996 / 18:08:12 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
967 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
968 |
|
283 | 969 |
imageDepth |
579 | 970 |
"return the depth of images represented by instances of |
971 |
this class. |
|
972 |
Must be redefined in concrete subclasses" |
|
973 |
||
974 |
^ self shouldNotImplement |
|
975 |
||
976 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
|
191 | 977 |
! |
978 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
979 |
implementorForDepth:depth |
283 | 980 |
"return the class, which best implements images of depth" |
981 |
||
982 |
depth == 1 ifTrue:[^ Depth1Image]. |
|
983 |
depth == 2 ifTrue:[^ Depth2Image]. |
|
984 |
depth == 4 ifTrue:[^ Depth4Image]. |
|
985 |
depth == 8 ifTrue:[^ Depth8Image]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
986 |
depth == 15 ifTrue:[^ Depth16Image]. "/ kludge for 15bit XFree |
283 | 987 |
depth == 16 ifTrue:[^ Depth16Image]. |
988 |
depth == 24 ifTrue:[^ Depth24Image]. |
|
989 |
^ self |
|
990 |
! ! |
|
991 |
||
992 |
!Image class methodsFor:'screen capture'! |
|
993 |
||
994 |
fromScreen |
|
995 |
"return an image of the full screen" |
|
996 |
||
997 |
|display| |
|
998 |
||
999 |
display := Screen current. |
|
1000 |
^ 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
|
1001 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1002 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1003 |
Image fromScreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1004 |
" |
283 | 1005 |
! |
1006 |
||
1007 |
fromScreen:aRectangle |
|
1008 |
"return an image of a part of the screen" |
|
1009 |
||
1010 |
^ self fromScreen:aRectangle on:Screen current |
|
1011 |
||
401
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 |
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
|
1014 |
" |
283 | 1015 |
! |
1016 |
||
1017 |
fromScreen:aRectangle on:aDisplay |
|
1018 |
"return an image of a part of the screen, which may be on |
|
1019 |
another Display." |
|
1020 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1021 |
|depth vis img| |
283 | 1022 |
|
1023 |
depth := aDisplay depth. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1024 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1025 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1026 |
"/ 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
|
1027 |
"/ (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
|
1028 |
"/ 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
|
1029 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1030 |
vis := aDisplay visualType. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1031 |
(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
|
1032 |
depth > 8 ifTrue:[ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1033 |
depth := 24. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1034 |
] |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1035 |
]. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1036 |
|
283 | 1037 |
img := (self implementorForDepth: depth) new. |
1038 |
^ img fromScreen:aRectangle on:aDisplay |
|
1039 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1040 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1041 |
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
|
1042 |
" |
283 | 1043 |
! |
1044 |
||
1045 |
fromScreenArea |
|
1046 |
"return an image of a part of the screen; |
|
1047 |
let user specify screen area." |
|
1048 |
||
1049 |
^ self fromScreen:(Rectangle fromUser) |
|
1050 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1051 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1052 |
Image fromScreenArea |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1053 |
" |
283 | 1054 |
! |
1055 |
||
1056 |
fromUser |
|
1057 |
"return an image of a part of the screen; let user specify screen area. |
|
1058 |
Same as fromScreenArea, for ST-80 compatibility" |
|
1059 |
||
1060 |
^ self fromScreenArea |
|
1061 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1062 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1063 |
Image fromUser |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1064 |
" |
283 | 1065 |
! |
1066 |
||
1067 |
fromView:aView |
|
1068 |
"return an image taken from a views contents as currently |
|
1069 |
on the screen. The returned image has the same depth and photometric |
|
1070 |
as the Display. Notice, that for invisible or partial covered |
|
1071 |
views, the returned Image is NOT correct. You may want to raise |
|
1072 |
the view before using this method." |
|
1073 |
||
1074 |
|org dev| |
|
1075 |
||
744 | 1076 |
dev := aView graphicsDevice. |
283 | 1077 |
org := dev translatePoint:(0@0) |
744 | 1078 |
from:(aView id) |
1079 |
to:dev rootWindowId. |
|
283 | 1080 |
^ self fromScreen:(org extent:aView extent) on:dev |
191 | 1081 |
|
1082 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1083 |
Image fromView:(NewLauncher allInstances first topView) |
283 | 1084 |
Image fromView:(SystemBrowser allInstances first topView) |
191 | 1085 |
" |
744 | 1086 |
|
1087 |
"Modified: 28.5.1996 / 20:23:32 / cg" |
|
157 | 1088 |
! ! |
1089 |
||
0 | 1090 |
!Image methodsFor:'accessing'! |
1091 |
||
592 | 1092 |
bitsPerSample |
1093 |
"return the number of bits per sample. |
|
1094 |
The return value is an array of bits-per-plane." |
|
1095 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1096 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1097 |
^ Array with:self depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1098 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1099 |
"Modified: 10.6.1996 / 18:04:21 / cg" |
592 | 1100 |
! |
1101 |
||
1102 |
colorMap |
|
1103 |
"return the colormap" |
|
1104 |
||
1105 |
^ colorMap |
|
1106 |
! |
|
1107 |
||
852 | 1108 |
colorMap:aColorMap |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1109 |
"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
|
1110 |
|
852 | 1111 |
|sz "{ Class: SmallInteger }" |
1112 |
sameColors| |
|
1113 |
||
1114 |
(aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self]. |
|
1115 |
photometric == #palette ifTrue:[ |
|
1116 |
"/ any change at all ? |
|
1117 |
(sz := aColorMap size) == colorMap size ifTrue:[ |
|
1118 |
sameColors := true. |
|
1119 |
||
1120 |
1 to:sz do:[:idx | |
|
1121 |
(aColorMap at:idx) = (colorMap at:idx) ifFalse:[ |
|
1122 |
sameColors := false. |
|
1123 |
] |
|
1124 |
]. |
|
1125 |
sameColors ifTrue:[^ self]. |
|
1126 |
] |
|
1127 |
]. |
|
1128 |
||
1129 |
colorMap := aColorMap. |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1130 |
colorMap notNil ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1131 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1132 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1133 |
(photometric == #palette) ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1134 |
photometric := #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1135 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1136 |
]. |
852 | 1137 |
deviceForm notNil ifTrue:[ |
1138 |
self release |
|
1139 |
] |
|
592 | 1140 |
|
1141 |
"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
|
1142 |
"Modified: 15.6.1996 / 09:32:09 / cg" |
592 | 1143 |
! |
1144 |
||
757 | 1145 |
container:aVisualContainer |
1146 |
"ignored here - added to allow images to be used like |
|
1147 |
VisualComponents (later, Image should inherit from it)" |
|
1148 |
||
1149 |
"Created: 28.5.1996 / 23:43:49 / cg" |
|
1150 |
"Modified: 29.5.1996 / 10:22:23 / cg" |
|
1151 |
! |
|
1152 |
||
592 | 1153 |
depth |
1154 |
"return the depth of the image" |
|
1155 |
||
1156 |
^ self bitsPerPixel |
|
1157 |
! |
|
1158 |
||
1159 |
device |
|
1160 |
"return the device, the receiver is associated with. |
|
1161 |
Return nil, if the image is unassigned." |
|
1162 |
||
1163 |
^ device |
|
1164 |
! |
|
1165 |
||
1166 |
extent |
|
1167 |
"return the images extent" |
|
1168 |
||
1169 |
^ width@height |
|
1170 |
! |
|
1171 |
||
1172 |
fullColorId |
|
1173 |
"return the id of the full color image on the device. |
|
1174 |
Return nil, if the image is unassigned." |
|
1175 |
||
1176 |
fullColorDeviceForm isNil ifTrue:[^ nil]. |
|
1177 |
^ fullColorDeviceForm id |
|
1178 |
! |
|
1179 |
||
728 | 1180 |
graphicsDevice |
1181 |
"same as #device - for ST-80 compatibility" |
|
1182 |
||
1183 |
^ device |
|
1184 |
! |
|
744 | 1185 |
|
592 | 1186 |
height |
1187 |
"return the height of the image" |
|
1188 |
||
1189 |
^ height |
|
1190 |
! |
|
1191 |
||
1192 |
id |
|
1193 |
"return the id of the image on the device. |
|
1194 |
Return nil, if the image is unassigned." |
|
1195 |
||
1196 |
deviceForm isNil ifTrue:[^ nil]. |
|
1197 |
^ deviceForm id |
|
1198 |
! |
|
1199 |
||
1200 |
monochromeId |
|
1201 |
"return the id of the monochrome image on the device. |
|
1202 |
Return nil, if the image is unassigned." |
|
1203 |
||
1204 |
monoDeviceForm isNil ifTrue:[^ nil]. |
|
1205 |
^ monoDeviceForm id |
|
1206 |
! |
|
1207 |
||
1208 |
palette |
|
1209 |
"return the colormap; ST-80 compatibility" |
|
1210 |
||
1211 |
^ colorMap |
|
1212 |
! |
|
1213 |
||
1214 |
palette:aColormap |
|
1215 |
"set the colormap; ST-80 compatibility" |
|
1216 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1217 |
self colorMap:aColormap |
592 | 1218 |
|
1219 |
"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
|
1220 |
"Modified: 8.6.1996 / 09:54:02 / cg" |
592 | 1221 |
! |
1222 |
||
1223 |
photometric |
|
1224 |
"return the photometric, a symbol such as #palette, #rgb etc." |
|
1225 |
||
1226 |
^ photometric |
|
1227 |
! |
|
1228 |
||
1229 |
samplesPerPixel |
|
1230 |
"return the number of samples per pixel in the image. |
|
1231 |
The return value is an array of bits-per-plane." |
|
1232 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1233 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1234 |
^ 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1235 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1236 |
"Modified: 10.6.1996 / 18:03:30 / cg" |
592 | 1237 |
! |
1238 |
||
1239 |
width |
|
1240 |
"return the width of the image" |
|
1241 |
||
1242 |
^ width |
|
1243 |
! ! |
|
1244 |
||
1245 |
!Image methodsFor:'accessing - pixels'! |
|
1246 |
||
0 | 1247 |
at:aPoint |
2 | 1248 |
"retrieve the pixel at aPoint; return a color. |
1249 |
Pixels start at 0@0 for upper left pixel, end at |
|
81 | 1250 |
(width-1)@(height-1) for lower right pixel. |
2 | 1251 |
You should not use this method for image-processing, its |
81 | 1252 |
very slow ... |
1253 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
0 | 1254 |
|
1255 |
^ self atX:aPoint x y:aPoint y |
|
1256 |
! |
|
1257 |
||
283 | 1258 |
at:aPoint put:aColor |
1259 |
"set the pixel at aPoint to aColor. |
|
1260 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1261 |
(width-1)@(height-1) for lower right pixel. |
|
1262 |
You should not use this method for image-processing, its |
|
1263 |
very slow ... |
|
1264 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1265 |
||
1266 |
^ self atX:aPoint x y:aPoint y put:aColor |
|
1267 |
! |
|
1268 |
||
1269 |
atPoint:aPoint |
|
1270 |
"ST-80 compatibility: return the pixelValue at:aPoint." |
|
1271 |
||
1272 |
^ self valueAtX:aPoint x y:aPoint y |
|
1273 |
! |
|
1274 |
||
0 | 1275 |
atX:x y:y |
2 | 1276 |
"retrieve a pixel at x/y; return a color. |
81 | 1277 |
Pixels start at 0@0 for upper left pixel, end at |
1278 |
(width-1)@(height-1) for lower right pixel. |
|
2 | 1279 |
You should not use this method for image-processing, its |
81 | 1280 |
very slow ... |
1281 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1282 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1283 |
|pixel maxPixel| |
89 | 1284 |
|
1285 |
pixel := self valueAtX:x y:y. |
|
1286 |
photometric == #blackIs0 ifTrue:[ |
|
746 | 1287 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1288 |
^ Color gray:(pixel * (100 / maxPixel)). |
|
89 | 1289 |
]. |
1290 |
photometric == #whiteIs0 ifTrue:[ |
|
746 | 1291 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1292 |
^ Color gray:100 - (pixel * (100 / maxPixel)). |
|
89 | 1293 |
]. |
1294 |
photometric == #palette ifTrue:[ |
|
746 | 1295 |
^ colorMap at:(pixel + 1) |
89 | 1296 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1297 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1298 |
^ self colorFromValue:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1299 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1300 |
"Modified: 8.6.1996 / 10:53:22 / cg" |
2 | 1301 |
! |
1302 |
||
1303 |
atX:x y:y put:aColor |
|
1304 |
"set the pixel at x/y to aColor. |
|
81 | 1305 |
Pixels start at 0@0 for the upper left pixel, end at |
1306 |
(width-1)@(height-1) for the lower right pixel. |
|
89 | 1307 |
This method checks if the color can be stored in the image. |
1308 |
(i.e. if the receiver is a palette image, the color must be present in there). |
|
1309 |
You should not use this method for image-processing, it is very slow ... |
|
81 | 1310 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
1311 |
||
89 | 1312 |
|pixel maxPixel| |
1313 |
||
1314 |
photometric == #whiteIs0 ifTrue:[ |
|
798 | 1315 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1316 |
pixel := maxPixel - (aColor brightness * maxPixel) rounded. |
|
89 | 1317 |
] ifFalse:[ |
798 | 1318 |
photometric == #blackIs0 ifTrue:[ |
1319 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
|
1320 |
pixel := (aColor brightness * maxPixel) rounded. |
|
1321 |
] ifFalse:[ |
|
1322 |
photometric ~~ #palette ifTrue:[ |
|
1323 |
self error:'format not supported'. |
|
1324 |
^ nil |
|
1325 |
]. |
|
1326 |
pixel := colorMap indexOf:aColor. |
|
1327 |
pixel == 0 ifTrue:[ |
|
1328 |
" |
|
1329 |
the color to be stored is not in the images colormap |
|
1330 |
" |
|
1331 |
self error:'invalid color - not in colorMap' |
|
1332 |
]. |
|
1333 |
pixel := pixel - 1 |
|
1334 |
] |
|
89 | 1335 |
]. |
1336 |
self atX:x y:y putValue:pixel. |
|
798 | 1337 |
|
1338 |
"Modified: 7.6.1996 / 19:17:48 / cg" |
|
81 | 1339 |
! |
1340 |
||
283 | 1341 |
atX:x y:y putValue:aPixelValue |
1342 |
"set the pixel at x/y to aPixelValue. |
|
1343 |
The interpretation of the pixelValue depends on the photometric |
|
1344 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1345 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1346 |
(width-1) @ (height-1) for the lower right pixel. |
|
1347 |
You should not use this method for image-processing, its |
|
1348 |
very slow ... |
|
1349 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1350 |
||
1351 |
^ self subclassResponsibility |
|
1352 |
! |
|
1353 |
||
1354 |
bits |
|
1355 |
"return the raw image data; depending on the photometric, |
|
1356 |
this has to be interpreted as monochrome, greyscale, |
|
1357 |
palette or rgb data. It is also packed to be dense, so |
|
1358 |
a 4 bitPerSample palette image will store 2 pixels per byte." |
|
1359 |
||
1360 |
^ bytes |
|
1361 |
! |
|
1362 |
||
1363 |
data |
|
1364 |
"for backward compatibility - will vanish" |
|
1365 |
||
1366 |
^ bytes |
|
1367 |
! |
|
1368 |
||
1369 |
data:aByteArray |
|
1370 |
"for backward compatibility - will vanish" |
|
1371 |
||
1372 |
bytes := aByteArray |
|
1373 |
! |
|
1374 |
||
81 | 1375 |
valueAt:aPoint |
1376 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1377 |
Pixels start at 0@0 for upper left pixel, 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:) |
|
2 | 1381 |
You should not use this method for image-processing, its |
81 | 1382 |
very slow ... |
1383 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1384 |
||
1385 |
^ self valueAtX:aPoint x y:aPoint y |
|
1386 |
! |
|
1387 |
||
1388 |
valueAtX:x y:y |
|
1389 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
1390 |
Pixels start at 0/0 for upper left pixel, and end at |
|
1391 |
width-1@height-1 for lower right pixel. |
|
1392 |
The returned numbers interpretation depends on the photometric |
|
1393 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
1394 |
You should not use this method for image-processing of |
|
1395 |
big images, its very slow ... |
|
1396 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1397 |
|
1398 |
^ self subclassResponsibility |
|
592 | 1399 |
! ! |
1400 |
||
1401 |
!Image methodsFor:'accessing - private'! |
|
1402 |
||
1403 |
bits:aByteArray |
|
1404 |
"set the raw data. |
|
1405 |
||
1406 |
This interface is only to be used when initializing |
|
1407 |
instances or by image readers. Calling for a change of an |
|
1408 |
existing image may confuse later pixel interpretation." |
|
1409 |
||
1410 |
bytes := aByteArray |
|
1411 |
||
1412 |
"Modified: 23.4.1996 / 11:08:28 / cg" |
|
2 | 1413 |
! |
1414 |
||
592 | 1415 |
bitsPerSample:aNumber |
1416 |
"set the number of bits per sample. |
|
1417 |
||
1418 |
This interface is only to be used when initializing |
|
1419 |
instances or by image readers. Calling for a change of an |
|
1420 |
existing image may confuse later pixel interpretation." |
|
1421 |
||
1422 |
bitsPerSample := aNumber |
|
1423 |
||
1424 |
"Modified: 23.4.1996 / 11:08:31 / cg" |
|
1425 |
! |
|
1426 |
||
1427 |
depth:d |
|
1428 |
"set the depth of the image. |
|
1429 |
||
1430 |
This interface is only to be used when initializing |
|
1431 |
instances or by image readers. Calling for a change of an |
|
1432 |
existing image may confuse later pixel interpretation." |
|
1433 |
||
1434 |
d == 24 ifTrue:[ |
|
1435 |
samplesPerPixel := 3. |
|
1436 |
bitsPerSample := #(8 8 8) |
|
1437 |
] ifFalse:[ |
|
1438 |
samplesPerPixel := 1. |
|
1439 |
bitsPerSample := Array with:d |
|
1440 |
] |
|
1441 |
||
1442 |
"Modified: 23.4.1996 / 11:08:34 / cg" |
|
1443 |
! |
|
1444 |
||
1445 |
extent:anExtent |
|
1446 |
"set the images extent. |
|
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 |
width := anExtent x. |
|
1453 |
height := anExtent y |
|
1454 |
||
1455 |
"Modified: 23.4.1996 / 11:08:38 / cg" |
|
1456 |
! |
|
1457 |
||
1458 |
height:aNumber |
|
1459 |
"set the height of the image. |
|
1460 |
||
1461 |
This interface is only to be used when initializing |
|
1462 |
instances or by image readers. Calling for a change of an |
|
1463 |
existing image may confuse later pixel interpretation." |
|
1464 |
||
1465 |
height := aNumber |
|
1466 |
||
1467 |
"Modified: 23.4.1996 / 11:08:40 / cg" |
|
1468 |
! |
|
1469 |
||
1470 |
photometric:aSymbol |
|
1471 |
"set the photometric interpretation of the pixel values. |
|
1472 |
The argument, aSymbol is one of: |
|
1473 |
#blackIs0, #whiteIs0, #palette, #rgb |
|
1474 |
See TIFF documentation, from which the photometric concept is borrowed. |
|
1475 |
||
1476 |
This interface is only to be used when initializing |
|
1477 |
instances or by image readers. Calling for a change of an |
|
1478 |
existing image may confuse later pixel interpretation." |
|
1479 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1480 |
|b| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1481 |
|
798 | 1482 |
photometric := aSymbol. |
1483 |
bitsPerSample isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1484 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1485 |
b := self class imageDepth // 3. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1486 |
bitsPerSample := Array with:b with:b with:b |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1487 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1488 |
bitsPerSample := Array with:(self class imageDepth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1489 |
]. |
798 | 1490 |
]. |
1491 |
samplesPerPixel isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1492 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1493 |
samplesPerPixel := 3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1494 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1495 |
samplesPerPixel := 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1496 |
] |
798 | 1497 |
]. |
1498 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1499 |
"Modified: 10.6.1996 / 18:21:29 / cg" |
592 | 1500 |
! |
1501 |
||
1502 |
samplesPerPixel:aNumber |
|
1503 |
"set the array of samples per pixel. |
|
1504 |
||
1505 |
This interface is only to be used when initializing |
|
1506 |
instances or by image readers. Calling for a change of an |
|
1507 |
existing image may confuse later pixel interpretation." |
|
1508 |
||
1509 |
samplesPerPixel := aNumber |
|
1510 |
||
1511 |
"Modified: 23.4.1996 / 11:08:45 / cg" |
|
81 | 1512 |
! |
1513 |
||
283 | 1514 |
width:aNumber |
592 | 1515 |
"set the width of the image. |
1516 |
||
1517 |
This interface is only to be used when initializing |
|
1518 |
instances or by image readers. Calling for a change of an |
|
1519 |
existing image may confuse later pixel interpretation." |
|
283 | 1520 |
|
1521 |
width := aNumber |
|
592 | 1522 |
|
1523 |
"Modified: 23.4.1996 / 11:08:48 / cg" |
|
100 | 1524 |
! |
1525 |
||
283 | 1526 |
width:w height:h |
592 | 1527 |
"set the width and height 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 |
|
592 | 1535 |
|
1536 |
"Modified: 23.4.1996 / 11:08:53 / cg" |
|
81 | 1537 |
! |
2 | 1538 |
|
283 | 1539 |
width:w height:h depth:d |
592 | 1540 |
"set the width, height and depth of the image. |
1541 |
||
1542 |
This interface is only to be used when initializing |
|
1543 |
instances or by image readers. Calling for a change of an |
|
1544 |
existing image may confuse later pixel interpretation." |
|
283 | 1545 |
|
1546 |
width := w. |
|
1547 |
height := h. |
|
1548 |
self depth:d. |
|
592 | 1549 |
|
1550 |
"Modified: 23.4.1996 / 11:08:56 / cg" |
|
89 | 1551 |
! |
1552 |
||
283 | 1553 |
width:w height:h depth:d fromArray:bits |
592 | 1554 |
"set the width, height, depth and pixels of the image. |
1555 |
||
1556 |
This interface is only to be used when initializing |
|
1557 |
instances or by image readers. Calling for a change of an |
|
1558 |
existing image may confuse later pixel interpretation." |
|
283 | 1559 |
|
1560 |
width := w. |
|
1561 |
height := h. |
|
1562 |
self depth:d. |
|
1563 |
bytes := bits |
|
592 | 1564 |
|
1565 |
"Modified: 23.4.1996 / 11:08:59 / cg" |
|
1566 |
! |
|
1567 |
||
1568 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels |
|
1569 |
"set all relevant internal state of the image. |
|
1570 |
||
1571 |
This interface is only to be used when initializing |
|
1572 |
instances or by image readers. Calling for a change of an |
|
1573 |
existing image may confuse later pixel interpretation." |
|
1574 |
||
1575 |
width := w. |
|
1576 |
height := h. |
|
1577 |
photometric := p. |
|
1578 |
samplesPerPixel := spp. |
|
1579 |
bitsPerSample := bps. |
|
1580 |
colorMap := cm. |
|
1581 |
bytes := pixels. |
|
1582 |
||
1583 |
"Created: 23.4.1996 / 11:06:40 / cg" |
|
1584 |
"Modified: 23.4.1996 / 11:09:02 / cg" |
|
0 | 1585 |
! ! |
1586 |
||
283 | 1587 |
!Image methodsFor:'binary storage'! |
1588 |
||
1589 |
readBinaryContentsFrom: stream manager: manager |
|
1590 |
"read a binary representation of an image from stream. |
|
1591 |
Redefined to flush any device data." |
|
1592 |
||
1593 |
super readBinaryContentsFrom: stream manager: manager. |
|
1594 |
device := nil. |
|
1595 |
deviceForm := nil. |
|
1596 |
monoDeviceForm := nil. |
|
1597 |
fullColorDeviceForm := nil. |
|
0 | 1598 |
! |
1599 |
||
283 | 1600 |
storeBinaryDefinitionOn: stream manager: manager |
1601 |
"store a binary representation of the receiver on stream. |
|
592 | 1602 |
This is an internal interface for binary storage mechanism. |
283 | 1603 |
Redefined to not store the device form (which is recreated at |
1604 |
load time anyway)" |
|
1605 |
||
1606 |
|tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm| |
|
1607 |
||
1608 |
tDevice := device. |
|
1609 |
tDeviceForm := deviceForm. |
|
1610 |
tMonoDeviceForm := monoDeviceForm. |
|
1611 |
tFullColorDeviceForm := fullColorDeviceForm. |
|
1612 |
||
1613 |
device := nil. |
|
1614 |
deviceForm := nil. |
|
1615 |
monoDeviceForm := nil. |
|
1616 |
fullColorDeviceForm := nil. |
|
1617 |
||
1618 |
super storeBinaryDefinitionOn: stream manager: manager. |
|
1619 |
||
1620 |
device := tDevice. |
|
1621 |
deviceForm := tDeviceForm. |
|
1622 |
monoDeviceForm := tMonoDeviceForm. |
|
1623 |
fullColorDeviceForm := tFullColorDeviceForm. |
|
592 | 1624 |
|
1625 |
"Modified: 23.4.1996 / 09:30:50 / cg" |
|
0 | 1626 |
! ! |
1627 |
||
1628 |
!Image methodsFor:'converting'! |
|
1629 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1630 |
asBurkesDitheredMonochromeImage |
837 | 1631 |
"return a burkes dithered monochrome image from the receiver image. |
1632 |
Depending on the images contents, this may or may not look better than |
|
1633 |
a floyd-steinberg dithered image. |
|
1634 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
1635 |
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
|
1636 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1637 |
|monoBits| |
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 |
monoBits := self burkesDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1640 |
^ 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
|
1641 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1642 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1643 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1644 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1645 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1646 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1647 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1648 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1649 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1650 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1651 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1652 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1653 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1654 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1655 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1656 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1657 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1658 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1659 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1662 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1663 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1664 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1665 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1666 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1667 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1668 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1669 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1670 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1671 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1672 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1673 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1674 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1675 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1676 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1677 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1678 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1679 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1680 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1681 |
"Created: 10.6.1996 / 12:34:44 / cg" |
837 | 1682 |
"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
|
1683 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1684 |
|
283 | 1685 |
asCachedImage |
592 | 1686 |
"return the receiver associated to the current screens device. |
1687 |
For ST-80 compatibility |
|
1688 |
(ST/X uses Image for both device- and nonDevice-images)" |
|
283 | 1689 |
|
1690 |
^ self on:Screen current |
|
592 | 1691 |
|
1692 |
"Modified: 23.4.1996 / 11:10:32 / cg" |
|
0 | 1693 |
! |
1694 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1695 |
asErrorDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1696 |
"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
|
1697 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1698 |
DitherAlgorithm == #burkes ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1699 |
^ self asBurkesDitheredMonochromeImage |
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 |
DitherAlgorithm == #stevensonArce ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1702 |
^ self asStevensonArgceDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1703 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1704 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1705 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1706 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1707 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1708 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1709 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1710 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1711 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1712 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1715 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1716 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1717 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1718 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1719 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1720 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1721 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1724 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1725 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1726 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1727 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1728 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1729 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1730 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1731 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1732 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1733 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1734 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1735 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1736 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1737 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1738 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1739 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1740 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1741 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1742 |
"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
|
1743 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1744 |
|
854 | 1745 |
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
1746 |
"return a floyd-steinberg dithered pseudoForm from the palette picture. |
|
1747 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
|
1748 |
colors assigned to aDevice, such as the preallocated colors of the |
|
1749 |
Color class. |
|
1750 |
By passing the ditherColors as extra array, this method can |
|
1751 |
also be used to dither an 8bit image into a smaller number of colors, |
|
1752 |
for example to create dithered Depth4Images from Depth8Images." |
|
1753 |
||
1754 |
|pseudoBits f has8BitImage deviceDepth |
|
1755 |
map | |
|
1756 |
||
1757 |
deviceDepth := aDevice depth. |
|
1758 |
deviceDepth == 8 ifTrue:[ |
|
1759 |
has8BitImage := true. |
|
1760 |
] ifFalse:[ |
|
1761 |
has8BitImage := false. |
|
1762 |
aDevice supportedImageFormats do:[:fmt | |
|
1763 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
1764 |
has8BitImage := true. |
|
1765 |
] |
|
1766 |
] |
|
1767 |
]. |
|
1768 |
has8BitImage ifFalse:[^ nil]. |
|
1769 |
||
1770 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
|
1771 |
pseudoBits isNil ifTrue:[^ nil]. |
|
1772 |
||
1773 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
|
1774 |
f isNil ifTrue:[^ nil]. |
|
1775 |
||
1776 |
"/ |
|
1777 |
"/ have to create a funny colorMap, where |
|
1778 |
"/ color at:index == color colorId:index |
|
1779 |
"/ |
|
1780 |
map := Array new:256. |
|
1781 |
fixColors do:[:clr | |
|
1782 |
map at:clr colorId + 1 put:clr |
|
1783 |
]. |
|
1784 |
f colorMap:map. |
|
1785 |
f initGC. |
|
1786 |
f bits:pseudoBits. |
|
1787 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
|
1788 |
width:width height:height |
|
1789 |
x:0 y:0 |
|
1790 |
into:(f id) x:0 y:0 |
|
1791 |
width:width height:height with:(f gcId). |
|
1792 |
^ f |
|
1793 |
||
1794 |
" |
|
1795 |
example: |
|
1796 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
|
1797 |
||
1798 |
|img8 reducedImg8 img4 map form| |
|
1799 |
||
1800 |
map := #( |
|
1801 |
(0 0 0) |
|
1802 |
(0 0 100) |
|
1803 |
(0 50 0) |
|
1804 |
(0 50 100) |
|
1805 |
(0 100 0) |
|
1806 |
(0 100 100) |
|
1807 |
(100 0 0) |
|
1808 |
(100 0 100) |
|
1809 |
(100 50 0) |
|
1810 |
(100 50 100) |
|
1811 |
(100 100 0) |
|
1812 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
|
1813 |
green:(rgb at:2) |
|
1814 |
blue:(rgb at:3)) on:Display]. |
|
1815 |
||
1816 |
img8 := Image fromFile:'bitmaps/bf.im8'. |
|
1817 |
form := img8 paletteImageAsDitheredPseudoFormOn:Display |
|
1818 |
colors:map |
|
1819 |
nRed:2 |
|
1820 |
nGreen:3 |
|
1821 |
nBlue:2. |
|
1822 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
|
1823 |
img4 := Depth4Image fromImage:img8. |
|
1824 |
" |
|
1825 |
||
1826 |
"Modified: 14.6.1996 / 16:52:34 / cg" |
|
1827 |
! |
|
1828 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1829 |
asFloydSteinbergDitheredGrayFormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1830 |
"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
|
1831 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1832 |
|f depth bits| |
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 |
depth := aDevice depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1835 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1836 |
"/ for monochrome, there is specialized |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1837 |
"/ monochrome dither code available |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1838 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1839 |
bits := self floydSteinbergDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1840 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1841 |
bits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1842 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1843 |
|
816 | 1844 |
^ 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
|
1845 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1846 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1847 |
|i f| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1848 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1849 |
i := Image fromFile:'bitmaps/claus.gif'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1850 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1851 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1852 |
|
841 | 1853 |
" |
1854 |
|i f| |
|
1855 |
||
1856 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1857 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
|
1858 |
" |
|
1859 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1860 |
"Created: 10.6.1996 / 14:11:39 / cg" |
841 | 1861 |
"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
|
1862 |
! |
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 |
asFloydSteinbergDitheredGrayImageDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1865 |
"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
|
1866 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1867 |
|ditheredBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1868 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1869 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1870 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1871 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1872 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1873 |
ditheredBits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1874 |
^ (self class implementorForDepth:depth) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1875 |
width:width height:height fromArray:ditheredBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1876 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1877 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1878 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1879 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1880 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1881 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1882 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1883 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1884 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1885 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1886 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1887 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1888 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1889 |
|
829 | 1890 |
i := Depth24Image width:4 height:1 |
1891 |
fromArray:#[ |
|
1892 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1893 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1894 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
1895 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00]. |
|
1896 |
i := i magnifiedBy:4@1. |
|
1897 |
i inspect. |
|
1898 |
||
1899 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1900 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1901 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1902 |
" |
|
1903 |
||
1904 |
" |
|
1905 |
|i| |
|
1906 |
||
1907 |
i := Depth24Image width:4 height:6 |
|
1908 |
fromArray:#[ |
|
1909 |
16r00 16r00 16r00 16r00 16r00 16r80 16r00 16r00 16rff 16r00 16r80 16r00 |
|
1910 |
16r00 16r80 16r80 16r00 16rFF 16r00 16r00 16rFF 16r80 16r00 16rFF 16rFF |
|
1911 |
16r80 16r00 16r00 16r80 16r00 16r80 16r80 16r00 16rff 16r80 16r80 16r00 |
|
1912 |
16r80 16r80 16r80 16r80 16rFF 16r00 16r80 16rFF 16r80 16r80 16rFF 16rFF |
|
1913 |
16rFF 16r00 16r00 16rFF 16r00 16r80 16rFF 16r00 16rff 16rFF 16r80 16r00 |
|
1914 |
16rFF 16r80 16r80 16rFF 16rFF 16r00 16rFF 16rFF 16r80 16rFF 16rFF 16rFF]. |
|
1915 |
i := i magnifiedBy:30. |
|
1916 |
i inspect. |
|
1917 |
||
1918 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1919 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1920 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1921 |
" |
|
1922 |
" |
|
1923 |
|i| |
|
1924 |
||
1925 |
i := Image fromFile:'granite.tiff'. |
|
1926 |
i inspect. |
|
1927 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
1928 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
1929 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
1930 |
" |
|
1931 |
||
1932 |
" |
|
1933 |
|i| |
|
1934 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1935 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1936 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1937 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1938 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1939 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1942 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1943 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1944 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1945 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1946 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1947 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1948 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1949 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1950 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1951 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1952 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1953 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1954 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1955 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1956 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1957 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1958 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1959 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1960 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1961 |
"Created: 10.6.1996 / 12:33:47 / cg" |
829 | 1962 |
"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
|
1963 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1964 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1965 |
asFloydSteinbergDitheredMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1966 |
"return a dithered moncohrome form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1967 |
|
816 | 1968 |
|monoBits clr0 clr1| |
1969 |
||
1970 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
|
1971 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1972 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1973 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1974 |
|i f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1975 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1976 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1977 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1978 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1979 |
|
816 | 1980 |
" |
1981 |
|i f| |
|
1982 |
||
1983 |
i := Depth2Image width:8 height:8 |
|
1984 |
fromArray:#[ |
|
1985 |
4r0000 4r0000 |
|
1986 |
4r0000 4r0000 |
|
1987 |
4r1111 4r1111 |
|
1988 |
4r1111 4r1111 |
|
1989 |
4r2222 4r2222 |
|
1990 |
4r2222 4r2222 |
|
1991 |
4r3333 4r3333 |
|
1992 |
4r3333 4r3333 |
|
1993 |
]. |
|
1994 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
|
1995 |
" |
|
1996 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1997 |
"Created: 10.6.1996 / 14:11:39 / cg" |
816 | 1998 |
"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
|
1999 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2000 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2001 |
asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2002 |
"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
|
2003 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2004 |
|monoBits| |
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 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2007 |
^ 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
|
2008 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2009 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2010 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2011 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2012 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2013 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2014 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2015 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2016 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2017 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2018 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2019 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2020 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2021 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2022 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2023 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2024 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2025 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2026 |
i asOrderedDitheredMonochromeImage inspect. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2029 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2030 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2031 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2032 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2033 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2034 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2035 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2036 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2037 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2038 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2039 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2040 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2041 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2042 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2043 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2044 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2045 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2046 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2047 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2048 |
"Created: 10.6.1996 / 12:33:47 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2049 |
"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
|
2050 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2051 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2052 |
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2053 |
"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
|
2054 |
using colors in colors for dithering." |
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 |
|pseudoBits f has8BitImage deviceDepth |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2057 |
map | |
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 |
deviceDepth := aDevice depth. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2060 |
deviceDepth == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2061 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2062 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2063 |
has8BitImage := false. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2064 |
aDevice supportedImageFormats do:[:fmt | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2065 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2066 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2067 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2068 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2069 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2070 |
has8BitImage ifFalse:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2071 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2072 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:colors. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2073 |
pseudoBits isNil ifTrue:[^ nil]. |
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 := 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
|
2076 |
f isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2077 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2078 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2079 |
"/ have to create a funny colorMap, where |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2080 |
"/ color at:index == color colorId:index |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2081 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2082 |
map := Array new:256 withAll:0. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2083 |
colors do:[:clr | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2084 |
clr notNil ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2085 |
map at:clr colorId + 1 put:clr |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2086 |
] |
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 |
f colorMap:map. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2089 |
f initGC. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2090 |
f bits:pseudoBits. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2091 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2092 |
width:width height:height |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2093 |
x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2094 |
into:(f id) x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2095 |
width:width height:height with:(f gcId). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2096 |
^ f |
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 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2099 |
|i| |
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 |
i := Image fromFile:'bitmaps/garfield.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2102 |
(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
|
2103 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2104 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2105 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2106 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2107 |
i := Image fromFile:'bitmaps/claus.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2108 |
(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
|
2109 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2110 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2111 |
"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
|
2112 |
"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
|
2113 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2114 |
|
0 | 2115 |
asFormOn:aDevice |
72 | 2116 |
"get a device form, with best possible approximation. |
2117 |
remember it in case someone asks again." |
|
2118 |
||
2119 |
|form| |
|
2120 |
||
2121 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
|
0 | 2122 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2123 |
aDevice depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2124 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2125 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2126 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2127 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2128 |
^ self asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2129 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2130 |
|
873 | 2131 |
(aDevice visualType == #PseudoColor) ifTrue:[ |
2132 |
form := self asPseudoFormQuickOn:aDevice. |
|
2133 |
form notNil ifTrue:[ |
|
2134 |
^ form |
|
2135 |
]. |
|
2136 |
]. |
|
2137 |
||
0 | 2138 |
(photometric == #palette) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2139 |
form := self paletteImageAsFormOn:aDevice |
72 | 2140 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2141 |
(photometric == #rgb) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2142 |
form := self rgbImageAsFormOn:aDevice |
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 |
form := self greyImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2145 |
] |
0 | 2146 |
]. |
2147 |
||
72 | 2148 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2149 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2150 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2151 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2152 |
deviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2153 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2154 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2155 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2156 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2157 |
Lobby registerChange:self |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2160 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2161 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2162 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2163 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2164 |
] |
0 | 2165 |
]. |
2166 |
||
72 | 2167 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2168 |
|
873 | 2169 |
"Modified: 17.6.1996 / 10:41:02 / cg" |
813
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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2172 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2173 |
"get a gray device form" |
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 |
^ self asGrayFormOn:aDevice dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2176 |
|
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 |
|i| |
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 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2181 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2182 |
" |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2185 |
"Created: 10.6.1996 / 18:44:42 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2186 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2187 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2188 |
asGrayFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2189 |
"get a greyscale device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2190 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2191 |
|grayBits depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2192 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2193 |
depth := aDevice depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2194 |
depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2195 |
^ self asMonochromeFormOn: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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2198 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2199 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2200 |
^ self asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2201 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2202 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2203 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2204 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2205 |
^ self asOrderedDitheredGrayFormOn:aDevice |
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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2208 |
^ self asFloydSteinbergDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2209 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2210 |
"Created: 10.6.1996 / 18:42:01 / cg" |
852 | 2211 |
"Modified: 14.6.1996 / 15:17:28 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2212 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2213 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2214 |
asGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2215 |
"get a gray image from the receiver" |
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 |
^ self asGrayImageDepth:depth dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2218 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2219 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2220 |
|i| |
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 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2223 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2224 |
" |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2227 |
"Created: 10.6.1996 / 19:07:08 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2228 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2229 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2230 |
asGrayImageDepth:depth dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2231 |
"get a greyscale image, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2232 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2233 |
|grayBits| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2234 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2235 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2236 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2237 |
^ self asThresholdGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2238 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2239 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2240 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2241 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2242 |
^ self asOrderedDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2243 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2244 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2245 |
^ self asFloydSteinbergDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2246 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2247 |
"Created: 10.6.1996 / 19:08:21 / cg" |
0 | 2248 |
! |
2249 |
||
2250 |
asMonochromeFormOn:aDevice |
|
2251 |
"get a monochrome device form" |
|
2252 |
||
72 | 2253 |
|form| |
2254 |
||
2255 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm]. |
|
2256 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2257 |
form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm. |
0 | 2258 |
|
72 | 2259 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2260 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2261 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2262 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2263 |
monoDeviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2264 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2265 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2266 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2267 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2268 |
Lobby registerChange:self |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2271 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2272 |
twice (here and in the device form) |
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 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2275 |
] |
0 | 2276 |
]. |
2277 |
||
72 | 2278 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2279 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2280 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2281 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2282 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2283 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2284 |
(i asMonochromeFormOn:Display) inspect. |
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 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2288 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2289 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2290 |
asMonochromeFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2291 |
"get a monochrome device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2292 |
|
816 | 2293 |
|monoBits clr0 clr1 mustInvert| |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2294 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2295 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2296 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2297 |
^ self asThresholdMonochromeFormOn: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 |
aDitherAlgorithm == #burkes ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2301 |
monoBits := self burkesDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2302 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2303 |
aDitherAlgorithm == #stevensonArce ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2304 |
monoBits := self stevensonArceDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2305 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2306 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2307 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2308 |
^ self asOrderedDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2309 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2310 |
^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2311 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2312 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2313 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2314 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2315 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2316 |
"/ make its pixel interpretation correct for the device |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2317 |
"/ |
816 | 2318 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
2319 |
||
2320 |
"Modified: 10.6.1996 / 20:18:05 / cg" |
|
89 | 2321 |
! |
2322 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2323 |
asNearestPaintDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2324 |
"return a nearest paint pseudoForm from the palette picture. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2325 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2326 |
colors assigned to aDevice, such as the preallocated colors of the |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2327 |
Color class. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2328 |
By passing the ditherColors as extra array, this method can |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2329 |
also be used to dither an 8bit image into a smaller number of colors, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2330 |
for example to create dithered Depth4Images from Depth8Images." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2331 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2332 |
|pseudoBits f has8BitImage deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2333 |
map | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2334 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2335 |
deviceDepth := aDevice depth. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2336 |
deviceDepth == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2337 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2338 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2339 |
has8BitImage := false. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2340 |
aDevice supportedImageFormats do:[:fmt | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2341 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2342 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2343 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2344 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2345 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2346 |
has8BitImage ifFalse:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2347 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2348 |
pseudoBits := self nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2349 |
pseudoBits isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2350 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2351 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2352 |
f isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2353 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2354 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2355 |
"/ have to create a funny colorMap, where |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2356 |
"/ color at:index == color colorId:index |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2357 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2358 |
map := Array new:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2359 |
fixColors do:[:clr | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2360 |
map at:clr colorId + 1 put:clr |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2361 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2362 |
f colorMap:map. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2363 |
f initGC. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2364 |
f bits:pseudoBits. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2365 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2366 |
width:width height:height |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2367 |
x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2368 |
into:(f id) x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2369 |
width:width height:height with:(f gcId). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2370 |
^ f |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2371 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2372 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2373 |
example: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2374 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2375 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2376 |
|img8 reducedImg8 img4 map form| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2377 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2378 |
map := #( |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2379 |
(0 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2380 |
(0 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2381 |
(0 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2382 |
(0 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2383 |
(0 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2384 |
(0 100 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2385 |
(100 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2386 |
(100 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2387 |
(100 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2388 |
(100 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2389 |
(100 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2390 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2391 |
green:(rgb at:2) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2392 |
blue:(rgb at:3)) on:Display]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2393 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2394 |
img8 := Image fromFile:'bitmaps/claus.gif'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2395 |
form := img8 asNearestPaintDepth8FormOn:Display |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2396 |
colors:map |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2397 |
nRed:2 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2398 |
nGreen:3 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2399 |
nBlue:2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2400 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2401 |
img4 := Depth4Image fromImage:img8. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2402 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2403 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2404 |
"Created: 17.6.1996 / 18:47:46 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2405 |
"Modified: 17.6.1996 / 18:52:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2406 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
2407 |
|
808 | 2408 |
asOrderedDitheredGrayFormOn:aDevice |
2409 |
"return a dithered depth-x grey form from the receiver image. |
|
2410 |
Uses an 8x8 dithermatrix." |
|
2411 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2412 |
|f depth bits| |
808 | 2413 |
|
2414 |
depth := aDevice depth. |
|
2415 |
depth == 1 ifTrue:[ |
|
2416 |
"/ for monochrome, there is highly specialized |
|
2417 |
"/ monochrome dither code available |
|
2418 |
||
2419 |
^ self asOrderedDitheredMonochromeFormOn:aDevice |
|
2420 |
]. |
|
2421 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2422 |
bits := self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2423 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
808 | 2424 |
ditherWidth:8 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2425 |
depth:depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2426 |
|
816 | 2427 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2428 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2429 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2430 |
|i| |
808 | 2431 |
|
2432 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2433 |
(i asOrderedDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2434 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2435 |
|
816 | 2436 |
"Modified: 10.6.1996 / 20:10:07 / cg" |
808 | 2437 |
! |
2438 |
||
798 | 2439 |
asOrderedDitheredGrayImageDepth:depth |
2440 |
"return a dithered depth-x grey image from the receiver image. |
|
2441 |
Uses an 8x8 dithermatrix." |
|
2442 |
||
2443 |
|dither| |
|
2444 |
||
2445 |
dither := self class orderedDitherMatrixOfSize:8. |
|
2446 |
||
2447 |
depth == 1 ifTrue:[ |
|
2448 |
"/ for monochrome, there is highly specialized |
|
2449 |
"/ monochrome dither code available |
|
2450 |
||
2451 |
^ Depth1Image |
|
2452 |
width:width |
|
2453 |
height:height |
|
2454 |
fromArray:( |
|
2455 |
self |
|
2456 |
orderedDitheredMonochromeBitsWithDitherMatrix:dither |
|
2457 |
ditherWidth:8) |
|
2458 |
]. |
|
2459 |
||
2460 |
^ (self class implementorForDepth:depth) |
|
2461 |
width:width |
|
2462 |
height:height |
|
2463 |
fromArray:( |
|
2464 |
self |
|
2465 |
orderedDitheredBitsWithDitherMatrix:dither |
|
2466 |
ditherWidth:8 |
|
2467 |
depth:depth) |
|
2468 |
||
2469 |
" |
|
2470 |
|i i1 i2 i4 i8| |
|
2471 |
||
2472 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2473 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2474 |
i1 inspect. |
|
2475 |
||
2476 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2477 |
i2 inspect. |
|
2478 |
||
2479 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2480 |
i4 inspect. |
|
2481 |
||
2482 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2483 |
i8 inspect. |
|
2484 |
" |
|
2485 |
||
2486 |
" |
|
2487 |
|i i1 i2 i4 i8| |
|
2488 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2489 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
2490 |
i1 inspect. |
|
2491 |
||
2492 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
2493 |
i2 inspect. |
|
2494 |
||
2495 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
2496 |
i4 inspect. |
|
2497 |
||
2498 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
2499 |
i8 inspect. |
|
800 | 2500 |
|
2501 |
i2 := i8 asOrderedDitheredGrayImageDepth:2. |
|
2502 |
i2 inspect. |
|
798 | 2503 |
" |
2504 |
||
2505 |
"Created: 7.6.1996 / 18:03:54 / cg" |
|
800 | 2506 |
"Modified: 7.6.1996 / 19:41:59 / cg" |
798 | 2507 |
! |
2508 |
||
2509 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2510 |
"return a dithered monochrome form from the grey image. |
|
2511 |
Uses a 4x4 dithermatrix." |
|
2512 |
||
2513 |
"/ 4x4 seems a good comprimize between: |
|
2514 |
"/ number of grey levels (8x8 is better) |
|
2515 |
"/ artifacts (4x4 is better) |
|
2516 |
"/ |
|
2517 |
"/ could look at the image and decide upon the number of |
|
2518 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2519 |
"/ 4x4 for small number of colors ... |
|
2520 |
||
2521 |
^ self |
|
2522 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2523 |
ditherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2524 |
ditherWidth:4 |
|
2525 |
||
2526 |
"/ ^ self |
|
2527 |
"/ asOrderedDitheredMonochromeFormOn:aDevice |
|
2528 |
"/ ditherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2529 |
"/ ditherWidth:8 |
|
2530 |
||
2531 |
" |
|
2532 |
|i f| |
|
2533 |
||
2534 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
2535 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2536 |
||
2537 |
||
2538 |
|i f| |
|
2539 |
||
2540 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
2541 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2542 |
||
2543 |
||
2544 |
|i f| |
|
2545 |
||
2546 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
2547 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2548 |
||
2549 |
||
2550 |
|i f| |
|
2551 |
||
2552 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
2553 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2554 |
||
2555 |
||
2556 |
|i f| |
|
2557 |
||
2558 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
2559 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2560 |
" |
|
2561 |
||
2562 |
"Created: 7.6.1996 / 14:52:32 / cg" |
|
2563 |
"Modified: 7.6.1996 / 16:37:47 / cg" |
|
2564 |
! |
|
2565 |
||
2566 |
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW |
|
2567 |
"return a dithered monochrome form from the image. |
|
2568 |
Uses the passed ditherMatrix and ditherWidth." |
|
2569 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2570 |
|monoBits clr0 clr1| |
798 | 2571 |
|
2572 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
816 | 2573 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2574 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2575 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2576 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2577 |
|i| |
798 | 2578 |
|
2579 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2580 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2581 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2582 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2583 |
|i| |
798 | 2584 |
|
2585 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2586 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2587 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2588 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2589 |
|i| |
798 | 2590 |
|
2591 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2592 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
798 | 2593 |
" |
2594 |
||
2595 |
"Created: 7.6.1996 / 14:51:42 / cg" |
|
816 | 2596 |
"Modified: 10.6.1996 / 20:18:07 / cg" |
798 | 2597 |
! |
2598 |
||
2599 |
asOrderedDitheredMonochromeImage |
|
2600 |
"return a dithered monochrome image from the receiver image. |
|
2601 |
Uses a 4x4 dithermatrix." |
|
2602 |
||
2603 |
"/ 4x4 seems a good comprimize between: |
|
2604 |
"/ number of grey levels (8x8 is better) |
|
2605 |
"/ artifacts (4x4 is better) |
|
2606 |
"/ |
|
2607 |
"/ could look at the image and decide upon the number of |
|
2608 |
"/ distinct colors present. Use 8x8 for high-number, |
|
2609 |
"/ 4x4 for small number of colors ... |
|
2610 |
||
2611 |
^ self |
|
2612 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
2613 |
ditherWidth:4 |
|
2614 |
||
2615 |
"/ ^ self |
|
2616 |
"/ asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
2617 |
"/ ditherWidth:8 |
|
2618 |
||
2619 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2620 |
|i| |
798 | 2621 |
|
2622 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2623 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2624 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2625 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2626 |
|i| |
798 | 2627 |
|
2628 |
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
|
2629 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2630 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2631 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2632 |
|i| |
798 | 2633 |
|
2634 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2635 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2636 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2637 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2638 |
|i| |
798 | 2639 |
|
2640 |
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
|
2641 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2642 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2643 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2644 |
|i| |
798 | 2645 |
|
2646 |
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
|
2647 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2648 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2649 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2650 |
|i| |
798 | 2651 |
|
2652 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2653 |
i asOrderedDitheredMonochromeImage inspect |
798 | 2654 |
" |
2655 |
||
2656 |
"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
|
2657 |
"Modified: 10.6.1996 / 11:15:09 / cg" |
798 | 2658 |
! |
2659 |
||
2660 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
2661 |
"return a dithered monochrome image from the receiver image. |
|
2662 |
Uses the passed ditherMatrix and ditherWidth." |
|
2663 |
||
2664 |
|monoBits| |
|
2665 |
||
2666 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
2667 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
|
2668 |
||
2669 |
"order-4 dither: |
|
2670 |
||
2671 |
|i| |
|
2672 |
||
2673 |
i := Image fromFile:'garfield.gif'. |
|
2674 |
i |
|
2675 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4) |
|
2676 |
ditherWidth:4 |
|
2677 |
" |
|
2678 |
||
2679 |
"order-6 dither: |
|
2680 |
||
2681 |
|i| |
|
2682 |
||
2683 |
i := Image fromFile:'garfield.gif'. |
|
2684 |
i |
|
2685 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8) |
|
2686 |
ditherWidth:8 |
|
2687 |
" |
|
2688 |
||
2689 |
||
2690 |
"thresholding at:0.5 (all above 0.5 becomes white): |
|
2691 |
||
2692 |
|i| |
|
2693 |
||
2694 |
i := Image fromFile:'garfield.gif'. |
|
2695 |
i |
|
2696 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8) |
|
2697 |
ditherWidth:4 |
|
2698 |
" |
|
2699 |
||
2700 |
"thresholding at: 0.25 (all above 0.25 becomes white): |
|
2701 |
||
2702 |
|i| |
|
2703 |
||
2704 |
i := Image fromFile:'garfield.gif'. |
|
2705 |
i |
|
2706 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3) |
|
2707 |
ditherWidth:4 |
|
2708 |
" |
|
2709 |
||
2710 |
"thresholding at: 0.75 (all above 0.75 becomes white): |
|
2711 |
||
2712 |
|i| |
|
2713 |
||
2714 |
i := Image fromFile:'garfield.gif'. |
|
2715 |
i |
|
2716 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11) |
|
2717 |
ditherWidth:4 |
|
2718 |
" |
|
2719 |
||
2720 |
"Modified: 7.6.1996 / 17:23:47 / cg" |
|
2721 |
! |
|
2722 |
||
873 | 2723 |
asPseudoFormQuickOn:aDevice |
2724 |
"return a pseudo-deviceForm from the image. |
|
878 | 2725 |
Fail if any color is not available (i.e. do not dither)." |
873 | 2726 |
|
2727 |
|f d dDev temp temp8 bits anyMissing clr cMap idMap |
|
878 | 2728 |
nClr "{ Class: SmallInteger }" |
2729 |
usedColors | |
|
873 | 2730 |
|
2731 |
d := self depth. |
|
2732 |
(d == 1 |
|
2733 |
or:[d == 2 |
|
2734 |
or:[d == 4 |
|
2735 |
or:[d == 8]]]) ifFalse:[^ nil]. |
|
2736 |
||
2737 |
"/ |
|
2738 |
"/ see if all of the images colors are representable |
|
2739 |
"/ on the device |
|
2740 |
||
2741 |
bits := self bitsPerPixel. |
|
2742 |
nClr := (1 bitShift:bits). |
|
2743 |
cMap := Array new:nClr. |
|
2744 |
idMap := ByteArray new:nClr. |
|
2745 |
||
2746 |
photometric == #palette ifTrue:[ |
|
2747 |
nClr := nClr min:(colorMap size) |
|
2748 |
]. |
|
2749 |
||
878 | 2750 |
d == 8 ifTrue:[ |
2751 |
usedColors := bytes usedValues. "gets us an array filled with used values" |
|
2752 |
1 to:nClr do:[:pixel | |
|
2753 |
(usedColors includes:(pixel - 1)) ifFalse:[ |
|
2754 |
clr := Color black |
|
2755 |
] ifTrue:[ |
|
2756 |
clr := self colorFromValue:pixel-1. |
|
2757 |
clr := clr exactOn:aDevice. |
|
2758 |
clr isNil ifTrue:[^ nil]. |
|
2759 |
]. |
|
2760 |
cMap at:(pixel) put:clr. |
|
2761 |
idMap at:(pixel) put:(clr colorId). |
|
2762 |
]. |
|
2763 |
] ifFalse:[ |
|
2764 |
1 to:nClr do:[:pixel | |
|
2765 |
clr := self colorFromValue:pixel-1. |
|
2766 |
clr := clr exactOn:aDevice. |
|
2767 |
clr isNil ifTrue:[^ nil]. |
|
2768 |
||
2769 |
cMap at:(pixel) put:clr. |
|
2770 |
idMap at:(pixel) put:(clr colorId). |
|
2771 |
]. |
|
873 | 2772 |
]. |
2773 |
||
2774 |
"/ got all colors; good - simply change depth & translate pixels |
|
2775 |
||
2776 |
dDev := aDevice depth. |
|
2777 |
||
2778 |
(d == 8 and:[dDev == 8]) ifTrue:[ |
|
2779 |
"/ only translate |
|
2780 |
temp := ByteArray uninitializedNew:(width * height). |
|
2781 |
bytes expandPixels:8 "xlate only" |
|
2782 |
width:width |
|
2783 |
height:height |
|
2784 |
into:temp |
|
2785 |
mapping:idMap. |
|
2786 |
] ifFalse:[ |
|
2787 |
||
2788 |
"/ stupid: expandPixels can only handle any-to-8 |
|
2789 |
"/ compressPixels can only handle 8-to-any |
|
2790 |
||
2791 |
d ~~ 8 ifTrue:[ |
|
2792 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
2793 |
||
2794 |
bytes expandPixels:d |
|
2795 |
width:width |
|
2796 |
height:height |
|
2797 |
into:temp8 |
|
2798 |
mapping:idMap. |
|
2799 |
idMap := nil. |
|
2800 |
] ifFalse:[ |
|
2801 |
temp8 := bytes. |
|
2802 |
]. |
|
2803 |
||
2804 |
dDev ~~ 8 ifTrue:[ |
|
2805 |
temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height). |
|
2806 |
||
2807 |
temp8 compressPixels:dDev |
|
2808 |
width:width |
|
2809 |
height:height |
|
2810 |
into:temp |
|
2811 |
mapping:idMap. |
|
2812 |
] ifFalse:[ |
|
2813 |
temp := temp8 |
|
2814 |
]. |
|
2815 |
]. |
|
2816 |
||
2817 |
f := Form width:width height:height depth:dDev on:aDevice. |
|
2818 |
f isNil ifTrue:[^ nil]. |
|
2819 |
||
2820 |
f colorMap:cMap. |
|
2821 |
f initGC. |
|
2822 |
||
2823 |
aDevice |
|
2824 |
drawBits:temp |
|
2825 |
depth:dDev |
|
2826 |
width:width |
|
2827 |
height:height |
|
2828 |
x:0 y:0 |
|
2829 |
into:(f id) x:0 y:0 |
|
2830 |
width:width |
|
2831 |
height:height |
|
2832 |
with:(f gcId). |
|
2833 |
||
2834 |
^ f |
|
2835 |
||
2836 |
" |
|
2837 |
( |
|
2838 |
(((Depth4Image |
|
2839 |
width:4 |
|
2840 |
height:4 |
|
2841 |
fromArray:#[ |
|
2842 |
16r01 16r23 |
|
2843 |
16r45 16r67 |
|
2844 |
16r89 16rab |
|
2845 |
16rcd 16ref |
|
2846 |
])) |
|
2847 |
magnifiedBy:30 |
|
2848 |
) |
|
2849 |
asPseudoFormQuickOn:Display |
|
2850 |
) inspect |
|
2851 |
" |
|
2852 |
||
878 | 2853 |
"Modified: 17.6.1996 / 17:31:49 / cg" |
873 | 2854 |
! |
2855 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2856 |
asStevensonArceDitheredMonochromeImage |
837 | 2857 |
"return a stevenson-arce dithered monochrome image from the receiver image. |
2858 |
Depending on the images contents, this may or may not look better than |
|
2859 |
a floyd-steinberg dithered image. |
|
2860 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
2861 |
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
|
2862 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2863 |
|monoBits| |
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 |
monoBits := self stevensonArceDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2866 |
^ (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
|
2867 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2868 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2869 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2870 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2871 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2872 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2873 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2874 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2875 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2876 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2877 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2878 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2879 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2880 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2881 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2882 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2883 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2884 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2885 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2886 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2887 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2888 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2889 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2890 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2891 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2892 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2893 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2894 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2895 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2896 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2897 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2898 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2899 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2900 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2901 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2902 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2903 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2904 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2905 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2906 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2907 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2908 |
"Created: 10.6.1996 / 12:38:29 / cg" |
837 | 2909 |
"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
|
2910 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2911 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2912 |
asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2913 |
"return a thresholded grey form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2914 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2915 |
|depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2916 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2917 |
(depth := aDevice depth) == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2918 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2919 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2920 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2921 |
^ self |
816 | 2922 |
makeDeviceGrayPixmapOn:aDevice |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2923 |
depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2924 |
fromArray:(self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2925 |
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
|
2926 |
ditherWidth:4 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2927 |
depth:depth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2928 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2929 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2930 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2931 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2932 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2933 |
(i asThresholdGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2934 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2935 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2936 |
"Created: 10.6.1996 / 18:38:31 / cg" |
816 | 2937 |
"Modified: 10.6.1996 / 20:10:26 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2938 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2939 |
|
798 | 2940 |
asThresholdGrayImageDepth:depth |
2941 |
"return a thresholded depth-x grey image from the receiver image." |
|
2942 |
||
800 | 2943 |
depth == 1 ifTrue:[ |
2944 |
"/ for monochrome, there is highly specialized |
|
2945 |
"/ monochrome dither code available |
|
2946 |
||
2947 |
^ Depth1Image |
|
2948 |
width:width |
|
2949 |
height:height |
|
2950 |
fromArray:( |
|
2951 |
self |
|
2952 |
orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2953 |
ditherWidth:4) |
|
2954 |
]. |
|
2955 |
||
798 | 2956 |
^ (self class implementorForDepth:depth) |
2957 |
width:width |
|
2958 |
height:height |
|
2959 |
fromArray:( |
|
2960 |
self |
|
2961 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2962 |
ditherWidth:4 |
|
2963 |
depth:depth) |
|
2964 |
||
2965 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2966 |
|i| |
798 | 2967 |
|
2968 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2969 |
(i asThresholdGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2970 |
(i asThresholdGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2971 |
(i asThresholdGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2972 |
(i asThresholdGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2973 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2974 |
(i asOrderedDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2975 |
(i asOrderedDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2976 |
(i asOrderedDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2977 |
(i asOrderedDitheredGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2978 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2979 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2980 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2981 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2982 |
(i asFloydSteinbergDitheredGrayImageDepth:8) inspect. |
798 | 2983 |
" |
2984 |
||
2985 |
"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
|
2986 |
"Modified: 10.6.1996 / 14:20:56 / cg" |
798 | 2987 |
! |
2988 |
||
2989 |
asThresholdMonochromeFormOn:aDevice |
|
2990 |
"return a threshold monochrome form from the image." |
|
2991 |
||
2992 |
^ self |
|
2993 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
2994 |
ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
2995 |
ditherWidth:4 |
|
2996 |
||
2997 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2998 |
|i| |
798 | 2999 |
|
3000 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3001 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3002 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3003 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3004 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3005 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3006 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3007 |
i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3008 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3009 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3010 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3011 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3012 |
|i| |
798 | 3013 |
|
3014 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3015 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3016 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3017 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3018 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3019 |
|i| |
798 | 3020 |
|
3021 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3022 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3023 |
(i asThresholdMonochromeFormOn:Display) inspect |
798 | 3024 |
" |
3025 |
||
3026 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3027 |
"Modified: 10.6.1996 / 17:44:29 / cg" |
798 | 3028 |
! |
3029 |
||
3030 |
asThresholdMonochromeImage |
|
3031 |
"return a threshold monochrome image from the image. |
|
3032 |
Threshold means: brightness < 0.5 -> black / otherwise white" |
|
3033 |
||
3034 |
^ self |
|
3035 |
asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3036 |
ditherWidth:4 |
|
3037 |
||
3038 |
" |
|
3039 |
|i i2| |
|
3040 |
||
3041 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3042 |
i2 := i asThresholdMonochromeImage |
|
3043 |
||
3044 |
||
3045 |
|i i2| |
|
3046 |
||
3047 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
3048 |
i2 := i asThresholdMonochromeImage |
|
3049 |
||
3050 |
||
3051 |
|i i2| |
|
3052 |
||
3053 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
3054 |
i2 := i asThresholdMonochromeImage |
|
3055 |
||
3056 |
||
3057 |
|i i2| |
|
3058 |
||
3059 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
3060 |
i2 := i asThresholdMonochromeImage |
|
3061 |
" |
|
3062 |
||
3063 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3064 |
"Modified: 7.6.1996 / 17:16:10 / cg" |
|
3065 |
! |
|
3066 |
||
808 | 3067 |
asThresholdMonochromeImage:thresholdBrighness |
3068 |
"return a threshold monochrome image from the image. |
|
3069 |
The argument (0..1) gives the threshold value; |
|
3070 |
Threshold means: brightness < threshold -> black / otherwise white" |
|
3071 |
||
3072 |
|value ditherMatrix| |
|
3073 |
||
3074 |
value := thresholdBrighness * 255. |
|
3075 |
ditherMatrix := ByteArray new:256 withAll:(value truncated). |
|
3076 |
||
3077 |
^ self |
|
3078 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix |
|
3079 |
ditherWidth:16 |
|
3080 |
||
3081 |
" |
|
3082 |
|i| |
|
3083 |
||
3084 |
i := Image width:4 height:4 depth:4 |
|
3085 |
fromArray:#[ 16r01 16r23 |
|
3086 |
16r45 16r67 |
|
3087 |
16r89 16rab |
|
3088 |
16rcd 16ref ]. |
|
3089 |
i := i magnifiedBy:30. |
|
3090 |
i inspect. |
|
3091 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3092 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3093 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3094 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3095 |
(i asThresholdMonochromeImage:1) inspect. |
|
3096 |
" |
|
3097 |
||
3098 |
" |
|
3099 |
|i| |
|
3100 |
||
3101 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3102 |
i inspect. |
|
3103 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3104 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3105 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3106 |
(i asThresholdMonochromeImage:0.625) inspect. |
|
3107 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3108 |
" |
|
3109 |
||
3110 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3111 |
"Modified: 8.6.1996 / 14:51:57 / cg" |
|
3112 |
! |
|
3113 |
||
283 | 3114 |
fromForm:aForm |
592 | 3115 |
"setup the receiver from a form" |
283 | 3116 |
|
3117 |
|map c0 c1| |
|
3118 |
||
3119 |
width := aForm width. |
|
3120 |
height := aForm height. |
|
3121 |
bytes := aForm bits. |
|
3122 |
bitsPerSample := self bitsPerSample. |
|
3123 |
samplesPerPixel := self samplesPerPixel. |
|
3124 |
map := aForm colorMap. |
|
3125 |
||
3126 |
aForm depth == 1 ifTrue:[ |
|
592 | 3127 |
map isNil ifTrue:[ |
3128 |
photometric := #whiteIs0 |
|
3129 |
] ifFalse:[ |
|
3130 |
c0 := map at:1. |
|
3131 |
c1 := map at:2. |
|
3132 |
((c0 = Color white) |
|
3133 |
and:[c1 = Color black]) ifTrue:[ |
|
3134 |
photometric := #whiteIs0 |
|
3135 |
] ifFalse:[ |
|
3136 |
((c0 = Color black) |
|
3137 |
and:[c1 = Color white]) ifTrue:[ |
|
3138 |
photometric := #blackIs0 |
|
3139 |
] ifFalse:[ |
|
3140 |
photometric := #palette. |
|
3141 |
colorMap := Array with:c0 with:c1. |
|
3142 |
] |
|
3143 |
] |
|
3144 |
] |
|
283 | 3145 |
] ifFalse:[ |
592 | 3146 |
map notNil ifTrue:[ |
3147 |
photometric := #palette. |
|
3148 |
colorMap := map copy. |
|
3149 |
] ifFalse:[ |
|
3150 |
" |
|
3151 |
photometric stays at default |
|
3152 |
(which is rgb for d24, greyscale for others) |
|
3153 |
" |
|
3154 |
] |
|
283 | 3155 |
]. |
592 | 3156 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3157 |
"Modified: 8.6.1996 / 16:02:03 / cg" |
283 | 3158 |
! |
3159 |
||
89 | 3160 |
fromImage:anImage |
3161 |
"setup the receiver from another image. |
|
3162 |
Color precision may be lost, if conversion is from a higher depth |
|
191 | 3163 |
image. |
3164 |
WARNING: |
|
3165 |
This implementation is a slow fallback (the loop over the |
|
89 | 3166 |
source pixels is very slow). If this method is used heavily, you |
3167 |
may want to redefine it in concrete subclasses for common source images." |
|
3168 |
||
3169 |
width := anImage width. |
|
3170 |
height := anImage height. |
|
3171 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3172 |
bitsPerSample := self bitsPerSample. |
|
3173 |
samplesPerPixel := self samplesPerPixel. |
|
191 | 3174 |
self colormapFromImage:anImage. |
89 | 3175 |
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr | |
798 | 3176 |
self atX:x y:y put:clr |
89 | 3177 |
]. |
3178 |
||
3179 |
" |
|
798 | 3180 |
|i i2 i4 i8 i16 i24| |
89 | 3181 |
|
3182 |
i := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
3183 |
i inspect. |
|
3184 |
i2 := Depth2Image fromImage:i. |
|
3185 |
i2 inspect. |
|
3186 |
i4 := Depth4Image fromImage:i. |
|
3187 |
i4 inspect. |
|
3188 |
i8 := Depth8Image fromImage:i. |
|
3189 |
i8 inspect. |
|
3190 |
i24 := Depth24Image fromImage:i. |
|
3191 |
i24 inspect. |
|
3192 |
" |
|
191 | 3193 |
|
3194 |
"Created: 20.9.1995 / 00:59:03 / claus" |
|
798 | 3195 |
"Modified: 7.6.1996 / 16:23:03 / cg" |
191 | 3196 |
! |
3197 |
||
3198 |
fromSubImage:anImage in:aRectangle |
|
3199 |
"setup the receiver from another image, extracting a rectangular |
|
3200 |
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
|
3201 |
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
|
3202 |
represented. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3203 |
|
191 | 3204 |
WARNING: |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3205 |
This implementation is a slow fallback (the loop over the |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3206 |
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
|
3207 |
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
|
3208 |
of creating a subImage with the same depth & palette." |
191 | 3209 |
|
3210 |
|x0 y0| |
|
3211 |
||
3212 |
width := aRectangle width + 1. |
|
3213 |
height := aRectangle height + 1. |
|
3214 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3215 |
bitsPerSample := self bitsPerSample. |
|
3216 |
samplesPerPixel := self samplesPerPixel. |
|
3217 |
self colormapFromImage:anImage. |
|
3218 |
x0 := aRectangle left. |
|
3219 |
y0 := aRectangle top. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3220 |
|
191 | 3221 |
((photometric == anImage photometric) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3222 |
and:[self bitsPerPixel = anImage bitsPerPixel |
191 | 3223 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3224 |
"/ can do it by value |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3225 |
anImage valuesFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3226 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3227 |
do:[:x :y :pixelValue | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3228 |
self atX:x-x0 y:y-y0 putValue:pixelValue. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3229 |
] |
191 | 3230 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3231 |
"/ must do it by colors |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3232 |
anImage colorsFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3233 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3234 |
do:[:x :y :clr | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3235 |
self atX:x-x0 y:y-y0 put:clr. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3236 |
] |
191 | 3237 |
]. |
3238 |
||
3239 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3240 |
|i i2 i4 i8 i16 i24| |
191 | 3241 |
|
3242 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3243 |
i inspect. |
|
3244 |
i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200). |
|
3245 |
i4 inspect. |
|
3246 |
i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200). |
|
3247 |
i8 inspect. |
|
3248 |
i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200). |
|
3249 |
i24 inspect. |
|
3250 |
" |
|
3251 |
||
3252 |
"Created: 20.9.1995 / 01:06:02 / claus" |
|
3253 |
"Modified: 20.9.1995 / 10:15:37 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3254 |
"Modified: 10.6.1996 / 18:30:17 / cg" |
89 | 3255 |
! |
3256 |
||
283 | 3257 |
monochromeOn:aDevice |
3258 |
"return a monochrome device image of the receiver for aDevice. |
|
3259 |
(monochrome, even if device supports colors)" |
|
3260 |
||
3261 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self]. |
|
3262 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
|
3263 |
"oops, I am already accociated to another device |
|
3264 |
- need a copy ... |
|
3265 |
" |
|
3266 |
^ self copy monochromeOn:aDevice |
|
3267 |
]. |
|
3268 |
monoDeviceForm := self asMonochromeFormOn:aDevice. |
|
3269 |
! |
|
3270 |
||
3271 |
on:aDevice |
|
3272 |
"return an image with the same pixels as the receiver, but |
|
3273 |
associated to aDevice. If the receiver is not yet bound to |
|
3274 |
a device, this will be the receiver. Otherwise, a new image |
|
3275 |
is returned." |
|
3276 |
||
3277 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self]. |
|
852 | 3278 |
|
283 | 3279 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
852 | 3280 |
"oops, I am already accociated to another device |
3281 |
- need a copy ... |
|
3282 |
" |
|
3283 |
^ self copy on:aDevice |
|
283 | 3284 |
]. |
3285 |
deviceForm := self asFormOn:aDevice. |
|
3286 |
device := aDevice |
|
852 | 3287 |
|
3288 |
"Modified: 14.6.1996 / 15:28:30 / cg" |
|
283 | 3289 |
! ! |
3290 |
||
3291 |
!Image methodsFor:'converting greyscale images'! |
|
3292 |
||
3293 |
greyImageAsFormOn:aDevice |
|
3294 |
"return a thresholded grey-deviceForm from the grey image." |
|
3295 |
||
3296 |
|pictureDepth nPlanes f| |
|
3297 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3298 |
|
283 | 3299 |
nPlanes := samplesPerPixel. |
3300 |
(nPlanes == 2) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3301 |
'IMAGE: alpha plane ignored' errorPrintNL. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3302 |
nPlanes := 1 |
283 | 3303 |
]. |
3304 |
||
3305 |
pictureDepth := bitsPerSample at:1. |
|
3306 |
||
3307 |
"monochrome is very easy ..." |
|
3308 |
||
3309 |
(pictureDepth == 1) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3310 |
^ Form width:width height:height fromArray:bytes on:aDevice |
283 | 3311 |
]. |
3312 |
||
3313 |
(aDevice visualType == #TrueColor) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3314 |
^ self greyImageAsTrueColorFormOn:aDevice |
283 | 3315 |
]. |
3316 |
||
858 | 3317 |
"/ (aDevice visualType == #PseudoColor |
3318 |
"/ or:[aDevice visualType == #GrayScale |
|
3319 |
"/ or:[aDevice visualType == #StaticColor]]) ifTrue:[ |
|
3320 |
||
3321 |
"/ PseudoColor conversion also works for StaticColor, |
|
3322 |
"/ GrayScale and DirectColor; although possibly with suboptimal results |
|
3323 |
||
3324 |
^ self greyImageAsPseudoFormOn:aDevice |
|
3325 |
||
3326 |
"Modified: 14.6.1996 / 19:32:01 / cg" |
|
283 | 3327 |
! |
3328 |
||
3329 |
greyImageAsPseudoFormOn:aDevice |
|
3330 |
"return an 8-bit pseudo Form from the grey image" |
|
3331 |
||
3332 |
|wideBits pictureDepth f map |
|
3333 |
colorMap usedColors nUsed aColor |
|
3334 |
nColors "{ Class: SmallInteger }" |
|
3335 |
range id| |
|
3336 |
||
3337 |
pictureDepth := bitsPerSample at:1. |
|
3338 |
||
3339 |
(#(2 4 8) includes:pictureDepth) ifFalse:[ |
|
746 | 3340 |
self error:'currently only depth-2, 4 or 8 supported'. |
3341 |
^ nil |
|
283 | 3342 |
]. |
3343 |
||
3344 |
wideBits := ByteArray uninitializedNew:(width * height). |
|
3345 |
||
3346 |
(pictureDepth == 8) ifTrue:[ |
|
746 | 3347 |
"for 8bits, we scan for used colors first; |
3348 |
to avoid allocating too many colors" |
|
3349 |
||
3350 |
usedColors := bytes usedValues. |
|
3351 |
nUsed := usedColors max + 1. |
|
3352 |
||
3353 |
colorMap := Array new:nUsed. |
|
3354 |
photometric == #blackIs0 ifTrue:[ |
|
3355 |
usedColors do:[:grey | |
|
3356 |
colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey)) |
|
3357 |
] |
|
3358 |
] ifFalse:[ |
|
3359 |
usedColors do:[:grey | |
|
3360 |
colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey))) |
|
3361 |
] |
|
3362 |
] |
|
89 | 3363 |
] ifFalse:[ |
746 | 3364 |
nColors := (1 bitShift:pictureDepth). |
3365 |
colorMap := Array new:nColors. |
|
3366 |
range := 100 / (nColors - 1) asFloat. |
|
3367 |
photometric == #blackIs0 ifTrue:[ |
|
3368 |
1 to:nColors do:[:i | |
|
3369 |
colorMap at:i put:(Color gray:(i - 1) * range). |
|
3370 |
]. |
|
3371 |
] ifFalse:[ |
|
3372 |
1 to:nColors do:[:i | |
|
3373 |
colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range). |
|
3374 |
]. |
|
3375 |
]. |
|
283 | 3376 |
]. |
3377 |
||
3378 |
"XXX should reduce 8->6->4->2 planes, if not all colors could be allocated" |
|
3379 |
||
3380 |
"setup the translation map" |
|
3381 |
map := ByteArray uninitializedNew:256. |
|
3382 |
nColors := colorMap size. |
|
3383 |
1 to:nColors do:[:i | |
|
746 | 3384 |
aColor := colorMap at:i. |
3385 |
aColor notNil ifTrue:[ |
|
3386 |
aColor := aColor on:aDevice. |
|
3387 |
colorMap at:i put:aColor. |
|
3388 |
id := aColor colorId. |
|
3389 |
id notNil ifTrue:[ |
|
3390 |
map at:i put:id |
|
3391 |
] ifFalse:[ |
|
3392 |
map at:i put:0 |
|
3393 |
] |
|
3394 |
] |
|
89 | 3395 |
]. |
283 | 3396 |
|
3397 |
"expand & translate" |
|
3398 |
bytes expandPixels:pictureDepth |
|
746 | 3399 |
width:width |
3400 |
height:height |
|
3401 |
into:wideBits |
|
3402 |
mapping:map. |
|
283 | 3403 |
|
3404 |
f := Form width:width height:height depth:8 on:aDevice. |
|
3405 |
f isNil ifTrue:[^ nil]. |
|
3406 |
f colorMap:colorMap. |
|
3407 |
f initGC. |
|
3408 |
aDevice drawBits:wideBits depth:8 width:width height:height |
|
746 | 3409 |
x:0 y:0 |
3410 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
283 | 3411 |
^ f |
746 | 3412 |
|
3413 |
"Modified: 28.5.1996 / 20:55:57 / cg" |
|
0 | 3414 |
! |
3415 |
||
283 | 3416 |
greyImageAsTrueColorFormOn:aDevice |
3417 |
"return a true-color device-form for the grey-image receiver. |
|
3418 |
TODO: the pixel loops ought to be implemented as inline primitive code ..." |
|
3419 |
||
3420 |
|depth |
|
3421 |
myDepth "{ Class: SmallInteger }" |
|
3422 |
nColors "{ Class: SmallInteger }" |
|
3423 |
colorValues |
|
3424 |
scaleDown scaleRed scaleGreen scaleBlue redShift blueShift greenShift |
|
3425 |
form imageBitsdestIndex |
|
3426 |
bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits destIndex |
|
3427 |
nPixels| |
|
3428 |
||
3429 |
"/ this is a slow fallback method; this ought to be |
|
3430 |
"/ redefined in DepthxImage for more performance. |
|
3431 |
||
3432 |
depth := aDevice depth. |
|
3433 |
myDepth := self depth. |
|
3434 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3435 |
self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3436 |
^ nil |
0 | 3437 |
]. |
3438 |
||
283 | 3439 |
"/ compute scale to map from my pixels into devices range |
3440 |
||
3441 |
scaleDown := 1 bitShift:myDepth. |
|
3442 |
scaleRed := (1 bitShift:aDevice bitsRed). |
|
3443 |
scaleGreen := (1 bitShift:aDevice bitsGreen). |
|
3444 |
scaleBlue := (1 bitShift:aDevice bitsBlue). |
|
3445 |
redShift := aDevice shiftRed. |
|
3446 |
greenShift := aDevice shiftGreen. |
|
3447 |
blueShift := aDevice shiftBlue. |
|
3448 |
||
3449 |
nColors := (1 bitShift:myDepth). |
|
3450 |
colorValues := Array new:nColors. |
|
3451 |
1 to:nColors do:[:i | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3452 |
|v gv bv rv nv| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3453 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3454 |
"/ scale down to 0..1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3455 |
v := (i-1) / scaleDown. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3456 |
rv := (v * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3457 |
gv := (v * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3458 |
bv := (v * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3459 |
nv := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3460 |
nv := nv bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3461 |
nv := nv bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3462 |
colorValues at:i put:nv |
0 | 3463 |
]. |
283 | 3464 |
photometric == #whiteIs0 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3465 |
"/ reverse the order; 0 is brightest |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3466 |
colorValues reverse |
283 | 3467 |
]. |
193 | 3468 |
|
3469 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3470 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3471 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3472 |
|
283 | 3473 |
"/ for now, only support some depths |
3474 |
||
3475 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3476 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3477 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3478 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3479 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3480 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3481 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3482 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3483 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3484 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3485 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3486 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3487 |
imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3488 |
destIndex := destIndex + 2. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3489 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3490 |
] |
283 | 3491 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3492 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3493 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3494 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3495 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3496 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3497 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3498 |
destIndex := 1. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3499 |
0 to:height-1 do:[:y | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3500 |
0 to:width-1 do:[:x | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3501 |
|greyValue| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3502 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3503 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3504 |
imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3505 |
destIndex := destIndex + 4. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3506 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3507 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3508 |
] |
193 | 3509 |
]. |
3510 |
||
283 | 3511 |
imageBits isNil ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3512 |
'IMAGE: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3513 |
^ self asMonochromeFormOn:aDevice |
283 | 3514 |
]. |
3515 |
||
3516 |
form := |
|
193 | 3517 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
283 | 3518 |
form isNil ifTrue:[^ nil]. |
193 | 3519 |
form initGC. |
3520 |
||
3521 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3522 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3523 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3524 |
x:0 y:0 toX:0 y:0. |
193 | 3525 |
|
3526 |
^ form |
|
3527 |
||
283 | 3528 |
"Created: 20.10.1995 / 22:05:10 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3529 |
"Modified: 10.6.1996 / 19:15:13 / cg" |
0 | 3530 |
! ! |
3531 |
||
3532 |
!Image methodsFor:'converting palette images'! |
|
3533 |
||
3534 |
paletteImageAsFormOn:aDevice |
|
72 | 3535 |
"return a device-form for the palette-image receiver" |
3536 |
||
380 | 3537 |
|type ddepth| |
193 | 3538 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3539 |
ddepth := aDevice depth. |
379 | 3540 |
|
193 | 3541 |
((type := aDevice visualType) == #StaticGray) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3542 |
ddepth == 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3543 |
^ self paletteImageAsGray8FormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3544 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3545 |
^ self asGrayFormOn:aDevice |
0 | 3546 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3547 |
|
193 | 3548 |
(type == #TrueColor) ifTrue:[ |
854 | 3549 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
3550 |
ddepth == 8 ifTrue:[ |
|
3551 |
self depth == 8 ifTrue:[ |
|
3552 |
"/ use fixColor dither algorithm |
|
3553 |
^ self asDitheredTrueColor8FormOn:aDevice |
|
3554 |
] |
|
3555 |
] |
|
3556 |
]. |
|
3557 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3558 |
^ self paletteImageAsTrueColorFormOn:aDevice |
193 | 3559 |
]. |
858 | 3560 |
|
3561 |
"/ the PseudoColor conversion also works for |
|
3562 |
"/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results |
|
3563 |
||
3564 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
3565 |
||
3566 |
"Modified: 14.6.1996 / 19:31:01 / cg" |
|
0 | 3567 |
! |
3568 |
||
3569 |
paletteImageAsPseudoFormOn:aDevice |
|
72 | 3570 |
"return a pseudo-deviceForm from the palette image." |
0 | 3571 |
|
89 | 3572 |
|tempImage d temp8| |
3573 |
||
3574 |
d := self depth. |
|
3575 |
(#(1 2 4 8) includes:d) ifTrue:[ |
|
3576 |
" |
|
3577 |
fallback code for some depth's: |
|
3578 |
create a temporary Depth8Image and use its conversion method |
|
3579 |
" |
|
3580 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
3581 |
||
3582 |
bytes expandPixels:d |
|
3583 |
width:width |
|
3584 |
height:height |
|
3585 |
into:temp8 |
|
3586 |
mapping:nil. |
|
3587 |
||
3588 |
tempImage := Image width:width height:height depth:8 fromArray:temp8. |
|
3589 |
tempImage colorMap:colorMap. |
|
3590 |
^ tempImage paletteImageAsPseudoFormOn:aDevice |
|
3591 |
]. |
|
2 | 3592 |
^ self subclassResponsibility |
0 | 3593 |
! |
3594 |
||
193 | 3595 |
paletteImageAsTrueColorFormOn:aDevice |
3596 |
"return a true-color device-form for the palette-image receiver." |
|
3597 |
||
209 | 3598 |
|depth |
3599 |
myDepth "{ Class: SmallInteger }" |
|
3600 |
nColors "{ Class: SmallInteger }" |
|
3601 |
colorValues |
|
193 | 3602 |
scaleRed scaleGreen scaleBlue redShift greenShift blueShift |
194 | 3603 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
854 | 3604 |
destIndex| |
193 | 3605 |
|
3606 |
"/ this is a slow fallback method; this ought to be |
|
3607 |
"/ redefined in DepthxImage for more performance. |
|
3608 |
||
3609 |
depth := aDevice depth. |
|
3610 |
myDepth := self bitsPerPixel. |
|
3611 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3612 |
'IMAGE: depth > 12 not supported' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3613 |
^ nil |
193 | 3614 |
]. |
3615 |
||
3616 |
"/ gather r/g/b values for all colors in the map ... |
|
3617 |
||
3618 |
nColors := colorMap size. |
|
3619 |
||
3620 |
"/ precompute scales to map from 0..100 into devices range |
|
3621 |
"/ (this may be different for the individual components) |
|
3622 |
||
3623 |
scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100. |
|
3624 |
scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100. |
|
3625 |
scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100. |
|
3626 |
redShift := aDevice shiftRed. |
|
3627 |
greenShift := aDevice shiftGreen. |
|
3628 |
blueShift := aDevice shiftBlue. |
|
3629 |
||
3630 |
colorValues := Array uninitializedNew:nColors. |
|
3631 |
||
3632 |
1 to:nColors do:[:index | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3633 |
|clr rv gv bv v "{ Class: SmallInteger }" | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3634 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3635 |
clr := colorMap at:index. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3636 |
clr notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3637 |
rv := (clr red * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3638 |
gv := (clr green * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3639 |
bv := (clr blue * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3640 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3641 |
v := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3642 |
v := v bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3643 |
v := v bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3644 |
colorValues at:index put:v. |
193 | 3645 |
"/ clr print. ' ' print. |
3646 |
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print. |
|
3647 |
"/ ' -> ' print. v printNL. |
|
3648 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3649 |
] |
193 | 3650 |
]. |
3651 |
||
3652 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3653 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3654 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3655 |
|
3656 |
"/ for now, only support some depths |
|
3657 |
||
854 | 3658 |
"/ 16 bits/pixel |
3659 |
||
193 | 3660 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3661 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3662 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3663 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3664 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3665 |
|
854 | 3666 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3667 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3668 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3669 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3670 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3671 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3672 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3673 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3674 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3675 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3676 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3677 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3678 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3679 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3680 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3681 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3682 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3683 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3684 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3685 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3686 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3687 |
v = __intVal(clr); |
193 | 3688 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3689 |
((short *)dstPtr)[0] = v; |
193 | 3690 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3691 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3692 |
dstPtr[1] = (v) & 0xFF; |
193 | 3693 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3694 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3695 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3696 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3697 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3698 |
} |
193 | 3699 |
%}. |
3700 |
] ifFalse:[ |
|
854 | 3701 |
"/ 32 bits/pixel |
3702 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3703 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3704 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3705 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3706 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3707 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3708 |
|
854 | 3709 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3710 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3711 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3712 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3713 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3714 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3715 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3716 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3717 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3718 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3719 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3720 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3721 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3722 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3723 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3724 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3725 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3726 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3727 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3728 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3729 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3730 |
v = __intVal(clr); |
193 | 3731 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3732 |
((long *)dstPtr)[0] = v; |
193 | 3733 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3734 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3735 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3736 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3737 |
dstPtr[3] = (v) & 0xFF; |
193 | 3738 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3739 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3740 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3741 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3742 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3743 |
} |
193 | 3744 |
%}. |
854 | 3745 |
] ifFalse:[ |
3746 |
"/ 8 bits/pixel |
|
3747 |
||
3748 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
3749 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
3750 |
||
3751 |
"/ now, walk over the image and replace |
|
3752 |
"/ colorMap indices by color values in the bits array |
|
3753 |
||
3754 |
%{ |
|
3755 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
3756 |
&& __isArray(colorValues) |
|
3757 |
&& __isByteArray(_INST(bytes)) |
|
3758 |
&& (myDepth == __MKSMALLINT(8)) |
|
3759 |
&& __isByteArray(imageBits)) { |
|
3760 |
int x, y, w, h, nPix; |
|
3761 |
||
3762 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
3763 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
3764 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
|
3765 |
||
3766 |
w = __intVal(_INST(width)); |
|
3767 |
h = __intVal(_INST(height)); |
|
3768 |
nPix = w * h; |
|
3769 |
while (nPix > 0) { |
|
3770 |
unsigned idx, v; |
|
3771 |
OBJ clr; |
|
3772 |
||
3773 |
idx = *srcPtr; |
|
3774 |
clr = ap[idx]; |
|
3775 |
v = __intVal(clr); |
|
3776 |
||
3777 |
dstPtr[0] = v; |
|
3778 |
||
3779 |
dstPtr += 1; |
|
3780 |
srcPtr += 1; |
|
3781 |
nPix--; |
|
3782 |
} |
|
3783 |
} |
|
3784 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3785 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3786 |
] |
193 | 3787 |
]. |
3788 |
||
3789 |
imageBits isNil ifTrue:[ |
|
854 | 3790 |
'IMAGE: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintNL. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3791 |
^ self asMonochromeFormOn:aDevice |
193 | 3792 |
]. |
3793 |
||
3794 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
3795 |
form isNil ifTrue:[^ nil]. |
|
3796 |
form initGC. |
|
3797 |
||
3798 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3799 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3800 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3801 |
x:0 y:0 toX:0 y:0. |
193 | 3802 |
|
3803 |
^ form |
|
3804 |
||
3805 |
"Created: 20.10.1995 / 22:05:10 / cg" |
|
3806 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
|
0 | 3807 |
! ! |
3808 |
||
283 | 3809 |
!Image methodsFor:'converting rgb images'! |
3810 |
||
854 | 3811 |
asDitheredTrueColor8FormOn:aDevice |
3812 |
"convert an rgb image to a dithered depth8-form on aDevice. |
|
3813 |
Return the device-form." |
|
3814 |
||
3815 |
|fixColors pixel |
|
3816 |
dstIdx "{ Class: SmallInteger }" |
|
3817 |
shiftRed "{ Class: SmallInteger }" |
|
3818 |
shiftGreen "{ Class: SmallInteger }" |
|
3819 |
shiftBlue "{ Class: SmallInteger }" |
|
3820 |
nRed "{ Class: SmallInteger }" |
|
3821 |
nGreen "{ Class: SmallInteger }" |
|
3822 |
nBlue "{ Class: SmallInteger }"| |
|
3823 |
||
3824 |
shiftRed := aDevice shiftRed. |
|
3825 |
shiftGreen := aDevice shiftGreen. |
|
3826 |
shiftBlue := aDevice shiftBlue. |
|
3827 |
||
3828 |
nRed := (1 bitShift:aDevice bitsRed). |
|
3829 |
nGreen := (1 bitShift:aDevice bitsGreen). |
|
3830 |
nBlue := (1 bitShift:aDevice bitsBlue). |
|
3831 |
||
3832 |
fixColors := Array new:(nRed * nGreen * nBlue). |
|
3833 |
||
3834 |
dstIdx := 1. |
|
3835 |
0 to:nRed - 1 do:[:sR | |
|
3836 |
0 to:nGreen - 1 do:[:sG | |
|
3837 |
0 to:nBlue - 1 do:[:sB | |
|
3838 |
pixel := (sR bitShift:shiftRed) |
|
3839 |
+ (sG bitShift:shiftGreen) |
|
3840 |
+ (sB bitShift:shiftBlue). |
|
3841 |
fixColors at:dstIdx put:(Color colorId:(pixel)). |
|
3842 |
dstIdx := dstIdx + 1 |
|
3843 |
] |
|
3844 |
] |
|
3845 |
]. |
|
3846 |
||
3847 |
^ self |
|
3848 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
3849 |
colors:fixColors |
|
3850 |
nRed:nRed nGreen:nGreen nBlue:nBlue |
|
3851 |
||
3852 |
"Modified: 14.6.1996 / 17:18:57 / cg" |
|
3853 |
"Created: 14.6.1996 / 17:23:52 / cg" |
|
3854 |
! |
|
3855 |
||
283 | 3856 |
rgbImageAsFormOn:aDevice |
3857 |
"convert am rgb image to a device-form on aDevice. |
|
3858 |
Return the device-form." |
|
3859 |
||
3860 |
|visual| |
|
3861 |
||
3862 |
visual := aDevice visualType. |
|
3863 |
(visual == #StaticGray) ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3864 |
^ self asGrayFormOn:aDevice |
0 | 3865 |
]. |
283 | 3866 |
(visual == #TrueColor) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3867 |
^ self rgbImageAsTrueColorFormOn:aDevice |
0 | 3868 |
]. |
858 | 3869 |
|
3870 |
"/ PseudoColor conversion also works for StaticColor, GrayScale |
|
3871 |
"/ and DirectColor displays; although possibly with suboptimal results |
|
3872 |
||
283 | 3873 |
^ self rgbImageAsPseudoFormOn:aDevice |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3874 |
|
858 | 3875 |
"Modified: 14.6.1996 / 19:30:06 / cg" |
283 | 3876 |
! |
3877 |
||
3878 |
rgbImageAsPseudoFormOn:aDevice |
|
3879 |
"return a pseudocolor form from the rgb-picture" |
|
3880 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3881 |
|n "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3882 |
depth "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3883 |
palette f| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3884 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3885 |
(depth := self depth) <= 8 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3886 |
"/ 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
|
3887 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3888 |
palette := Array new:(1 bitShift:depth). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3889 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3890 |
n := (1 bitShift:depth)-1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3891 |
0 to:n do:[:pixelValue | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3892 |
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
|
3893 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3894 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3895 |
colorMap := palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3896 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3897 |
f := self paletteImageAsPseudoFormOn:aDevice. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3898 |
colorMap := nil. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3899 |
photometric := #rgb. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3900 |
^ f |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3901 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3902 |
|
283 | 3903 |
^ self subclassResponsibility |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3904 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
3905 |
"Modified: 8.6.1996 / 10:58:25 / cg" |
283 | 3906 |
! |
3907 |
||
3908 |
rgbImageAsTrueColorFormOn:aDevice |
|
3909 |
"return a truecolor form from the rgb-picture." |
|
3910 |
||
3911 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
3912 |
form| |
|
193 | 3913 |
|
3914 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3915 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
3916 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 3917 |
|
854 | 3918 |
"/ 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
|
3919 |
usedDeviceBitsPerPixel == 15 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3920 |
usedDeviceBitsPerPixel := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3921 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
3922 |
|
283 | 3923 |
"/ |
3924 |
"/ only the trivial case, where the depths match |
|
3925 |
"/ is handled here; conversions are supposed to |
|
3926 |
"/ be done in concrete subclasses (see D24Image) |
|
3927 |
"/ |
|
3928 |
self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[ |
|
854 | 3929 |
'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
|
3930 |
^ self asMonochromeFormOn:aDevice |
193 | 3931 |
]. |
3932 |
||
283 | 3933 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
3934 |
form isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3935 |
'IMAGE: display bitmap creation failed' errorPrintNL. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3936 |
^ nil |
193 | 3937 |
]. |
3938 |
form initGC. |
|
3939 |
||
3940 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3941 |
copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3942 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3943 |
x:0 y:0 toX:0 y:0. |
193 | 3944 |
|
3945 |
^ form |
|
3946 |
||
854 | 3947 |
"Modified: 14.6.1996 / 16:57:47 / cg" |
283 | 3948 |
! ! |
3949 |
||
3950 |
!Image methodsFor:'copying'! |
|
3951 |
||
3952 |
postCopy |
|
592 | 3953 |
"redefined to also copy the pixels and the colorMap |
3954 |
and clear out any device handles in the copy." |
|
3955 |
||
283 | 3956 |
bytes := bytes copy. |
3957 |
colorMap := colorMap deepCopy. |
|
3958 |
device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil |
|
592 | 3959 |
|
3960 |
"Modified: 23.4.1996 / 11:12:03 / cg" |
|
283 | 3961 |
! ! |
3962 |
||
3963 |
!Image methodsFor:'displaying'! |
|
3964 |
||
758 | 3965 |
displayFilledOn:aGC |
759 | 3966 |
"display the receiver as an opaque image. |
758 | 3967 |
This allows Images to be wrapped by a FillingWrapper" |
3968 |
||
3969 |
aGC displayOpaqueForm:self x:0 y:0. |
|
3970 |
||
3971 |
"Created: 29.5.1996 / 10:34:18 / cg" |
|
759 | 3972 |
"Modified: 29.5.1996 / 10:52:36 / cg" |
758 | 3973 |
! |
3974 |
||
283 | 3975 |
displayOn:aGC at:aPoint |
592 | 3976 |
"draw the receiver in the graphicsContext, aGC. |
283 | 3977 |
Smalltalk-80 compatibility" |
3978 |
||
672 | 3979 |
self displayOn:aGC x:aPoint x y:aPoint y. |
3980 |
||
3981 |
"Modified: 12.5.1996 / 20:16:38 / cg" |
|
3982 |
! |
|
3983 |
||
3984 |
displayOn:aGC x:x y:y |
|
3985 |
"draw the receiver in the graphicsContext, aGC. |
|
3986 |
Smalltalk-80 compatibility" |
|
3987 |
||
3988 |
aGC displayForm:self x:x y:y. |
|
592 | 3989 |
|
3990 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
|
672 | 3991 |
"Created: 12.5.1996 / 20:14:31 / cg" |
758 | 3992 |
! |
3993 |
||
3994 |
displayStrokedOn:aGC |
|
759 | 3995 |
"display the receiver as an non opaque image. |
758 | 3996 |
This allows Images to be wrapped by a StrokingWrapper" |
3997 |
||
3998 |
aGC displayForm:self x:0 y:0. |
|
3999 |
||
759 | 4000 |
"Created: 29.5.1996 / 10:34:18 / cg" |
4001 |
"Modified: 29.5.1996 / 10:52:30 / cg" |
|
283 | 4002 |
! ! |
4003 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4004 |
!Image methodsFor:'dither helpers'! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4005 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4006 |
burkesDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4007 |
"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
|
4008 |
Works for any source depths / photometric" |
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 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4011 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4012 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4013 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4014 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4015 |
errorArray1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4016 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4017 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4018 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4019 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4020 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4021 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4022 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4023 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4024 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4025 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4026 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4027 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4028 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4029 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4030 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4031 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4032 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4033 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4034 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4035 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4036 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4037 |
errorArray := Array new:(w+4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4038 |
errorArray1 := Array new:(w+4) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4039 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4040 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4041 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4042 |
"/ 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
|
4043 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4044 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4045 |
greyValues := self greyMapForRange:(255*1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4046 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4047 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4048 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4049 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4050 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4051 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4052 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4053 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4054 |
errorArray1 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4055 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4056 |
errorArray1 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4057 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4058 |
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
|
4059 |
|eP "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4060 |
eD |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4061 |
eI "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4062 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4063 |
xN "{Class: SmallInteger }" | |
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 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4066 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4067 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4068 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4069 |
xE := x + 2 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4070 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4071 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4072 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4073 |
grey > (127*1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4074 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4075 |
e := grey - (255*1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4076 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4077 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4078 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4079 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4080 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4081 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4082 |
"/ XX 8 4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4083 |
"/ 2 4 8 4 2 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4084 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4085 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4086 |
eI := e // 32. |
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 |
eP := eI * 8. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4089 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4090 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4091 |
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
|
4092 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4093 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4094 |
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
|
4095 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4096 |
eP := eI * 4. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4097 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4098 |
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
|
4099 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4100 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4101 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4102 |
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
|
4103 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4104 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4105 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4106 |
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
|
4107 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4108 |
eP := eI * 2. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4109 |
xN := xE - 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4110 |
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
|
4111 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4112 |
eD := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4113 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4114 |
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
|
4115 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4116 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4117 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4118 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4119 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4120 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4121 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4122 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4123 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4124 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4125 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4126 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4127 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4128 |
monoBits at:dstIndex put:byte. |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4131 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4132 |
]. |
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 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4135 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4136 |
"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
|
4137 |
"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
|
4138 |
! |
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 |
floydSteinbergDitheredBitsDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4141 |
"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
|
4142 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4143 |
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
|
4144 |
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
|
4145 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4146 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4147 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4148 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4149 |
outBits greyValues greyErrors greyPixels greyLevels |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4150 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4151 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4152 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4153 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4154 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4155 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4156 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4157 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4158 |
eR eRB eB eLB | |
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 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4161 |
self error:'unimplemented conversion'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4162 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4163 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4164 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4165 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4166 |
h := height. |
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 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4169 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4170 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4171 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4172 |
]. |
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 |
greyLevels := (1 bitShift:depth) - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4175 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4176 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4177 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4178 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4179 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4180 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4181 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4182 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4183 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4184 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4185 |
"/ 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
|
4186 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4187 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4188 |
greyValues := self greyMapForRange:(greyLevels). |
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 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4191 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4192 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4193 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4194 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4195 |
greyPixels := ByteArray withAll:greyPixels. |
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 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4198 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4199 |
] ifFalse:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4200 |
((v - v truncated) * 1024) truncated |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4201 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4202 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4203 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4204 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4205 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4206 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4207 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4208 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4209 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4210 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4211 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4212 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4213 |
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
|
4214 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4215 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4216 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4217 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4218 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4219 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4220 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4221 |
pixel := greyPixels at:(value + 1). |
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 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4224 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4225 |
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
|
4226 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4227 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4228 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4229 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4230 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4231 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4232 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4233 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4234 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4235 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4236 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4237 |
e16 := e // 16. |
809
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 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4240 |
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
|
4241 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4242 |
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
|
4243 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4244 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4245 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4246 |
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
|
4247 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4248 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4249 |
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
|
4250 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4251 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4252 |
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
|
4253 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4254 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4255 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4256 |
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
|
4257 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4258 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4259 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4260 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4261 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4262 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4263 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4264 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4265 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4266 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4267 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4268 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4269 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4270 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4271 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4272 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4273 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4274 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4275 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4276 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4277 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4278 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4279 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4280 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4281 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4282 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4283 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4284 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4285 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4286 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4287 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4288 |
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
|
4289 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4290 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4291 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4292 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4293 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4294 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4295 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4296 |
grey := (clr brightness * greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4297 |
pixel := grey truncated. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4298 |
error := ((grey - pixel) * 1024) truncated. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4299 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4300 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4301 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4302 |
error := error + (errorArray at:xE). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4303 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4304 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4305 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4306 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4307 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4308 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4309 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4310 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4311 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4312 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4313 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4314 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4315 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4316 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4317 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4318 |
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
|
4319 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4320 |
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
|
4321 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4322 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4323 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4324 |
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
|
4325 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4326 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4327 |
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
|
4328 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4329 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4330 |
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
|
4331 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4332 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4333 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4334 |
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
|
4335 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4336 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4337 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4338 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4339 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4340 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4341 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4342 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4343 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4344 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4345 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4346 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4347 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4348 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4349 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4350 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4351 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4352 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4353 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4354 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4355 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4356 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4357 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4358 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4359 |
"Created: 10.6.1996 / 13:28:22 / cg" |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4360 |
"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
|
4361 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4362 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4363 |
floydSteinbergDitheredDepth8BitsColors:colors |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4364 |
"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
|
4365 |
which must be a depth-8 image. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4366 |
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
|
4367 |
(which need not be a colorCubes colors)." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4368 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4369 |
|pseudoBits |
882 | 4370 |
rgbBytes |
4371 |
ditherRGBBytes ditherColors |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4372 |
w "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4373 |
h "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4374 |
index "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4375 |
fixR "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4376 |
fixG "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4377 |
fixB "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4378 |
ditherIds failed map lastColor |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4379 |
error clr| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4380 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4381 |
self depth ~~ 8 ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4382 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4383 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4384 |
"/ 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
|
4385 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4386 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4387 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4388 |
photometric == #palette ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4389 |
lastColor := colorMap size - 1 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4390 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4391 |
lastColor := 255. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4392 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4393 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4394 |
0 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4395 |
clr := self colorFromValue:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4396 |
rgbBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4397 |
rgbBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4398 |
rgbBytes at:index+2 put:(clr blueByte). |
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 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4401 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4402 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4403 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4404 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4405 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4406 |
ditherColors := colors select:[:clr | clr notNil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4407 |
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
|
4408 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4409 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4410 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4411 |
lastColor := ditherColors size. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4412 |
ditherIds := ByteArray uninitializedNew:lastColor. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4413 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4414 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4415 |
1 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4416 |
clr := ditherColors at:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4417 |
ditherRGBBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4418 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4419 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4420 |
ditherIds at:pix put:clr colorId. |
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 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4423 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4424 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4425 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4426 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4427 |
w := width + 2. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4428 |
error := ByteArray uninitializedNew:w*(3*2). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4429 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4430 |
w := width. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4431 |
h := height. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4432 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4433 |
failed := true. |
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 |
%{ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4436 |
int __x, __y; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4437 |
int __eR, __eG, __eB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4438 |
unsigned char *srcP, *dstP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4439 |
unsigned char *rgbP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4440 |
unsigned char *idP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4441 |
unsigned char *dp; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4442 |
short *errP, *eP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4443 |
int __fR, __fG, __fB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4444 |
int iR, iG, iB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4445 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4446 |
int __w = __intVal(w); |
882 | 4447 |
int __h = __intVal(h); |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4448 |
int __nColors = __intVal(lastColor); |
882 | 4449 |
int __wR = -1, __wG, __wB; |
4450 |
int nSame = 0; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4451 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4452 |
if (__isByteArray(__INST(bytes)) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4453 |
&& __isByteArray(pseudoBits) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4454 |
&& __isByteArray(rgbBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4455 |
&& __isByteArray(ditherRGBBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4456 |
&& __isByteArray(ditherIds) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4457 |
&& __isByteArray(error)) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4458 |
failed = false; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4459 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4460 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4461 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4462 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4463 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4464 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4465 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4466 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4467 |
* clear error accumulator |
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 |
eP = errP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4470 |
bzero(eP, (__w+2) * 2 * 3); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4471 |
|
882 | 4472 |
for (__y=__h; __y>0; __y--) { |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4473 |
__eR = __eG = __eB = 0; |
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 |
eP = &(errP[3]); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4476 |
__eR = eP[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4477 |
__eG = eP[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4478 |
__eB = eP[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4479 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4480 |
for (__x=__w; __x>0; __x--) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4481 |
int __want; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4482 |
int pix; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4483 |
int __wantR, __wantG, __wantB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4484 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4485 |
int tR, tG, tB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4486 |
int nR, nG, nB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4487 |
int dR, dG, dB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4488 |
int minDelta, bestIdx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4489 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4490 |
pix = *srcP++; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4491 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4492 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4493 |
* 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
|
4494 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4495 |
idx = pix+pix+pix; /* pix * 3 */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4496 |
|
882 | 4497 |
__wantR = rgbP[idx] + __eR; |
4498 |
__wantG = rgbP[idx+1] + __eG; |
|
4499 |
__wantB = rgbP[idx+2] + __eB; |
|
4500 |
||
4501 |
if ((__wantR == __wR) |
|
4502 |
&& (__wantG == __wG) |
|
4503 |
&& (__wantB == __wB)) { |
|
4504 |
/* |
|
4505 |
* same color again - reuse last bestMatch |
|
4506 |
*/ |
|
4507 |
nSame++; |
|
4508 |
} else { |
|
4509 |
__wR = __wantR; |
|
4510 |
__wG = __wantG; |
|
4511 |
__wB = __wantB; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4512 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4513 |
/* |
882 | 4514 |
if(__wR > 255) __wR = 255; |
4515 |
else if (__wR < 0) __wR = 0; |
|
4516 |
if(__wG > 255) __wG = 255; |
|
4517 |
else if (__wG < 0) __wG = 0; |
|
4518 |
if(__wB > 255) __wB = 255; |
|
4519 |
else if (__wB < 0) __wB = 0; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4520 |
*/ |
882 | 4521 |
/* find the best matching color */ |
4522 |
||
4523 |
minDelta = 99999; |
|
4524 |
bestIdx = -1; |
|
4525 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
4526 |
for (idx = 0; idx<__nColors; idx++) { |
|
4527 |
int d, delta; |
|
4528 |
||
4529 |
d = dp[0]; |
|
4530 |
delta = __wR - d; |
|
4531 |
if (delta < 0) delta = -delta; |
|
878 | 4532 |
if (delta < minDelta) { |
882 | 4533 |
d = dp[1]; |
4534 |
if (__wG > d) |
|
4535 |
delta += (__wG - d); |
|
878 | 4536 |
else |
882 | 4537 |
delta += (d - __wG); |
878 | 4538 |
if (delta < minDelta) { |
882 | 4539 |
d = dp[2]; |
4540 |
if (__wB > d) |
|
4541 |
delta += (__wB - d); |
|
4542 |
else |
|
4543 |
delta += (d - __wB); |
|
4544 |
||
4545 |
if (delta < minDelta) { |
|
4546 |
bestIdx = idx; |
|
4547 |
if (delta == 0) { |
|
4548 |
/* |
|
4549 |
if (delta < 3) { |
|
4550 |
*/ |
|
4551 |
break; |
|
4552 |
} |
|
4553 |
minDelta = delta; |
|
878 | 4554 |
} |
4555 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4556 |
} |
882 | 4557 |
dp += 3; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4558 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4559 |
} |
882 | 4560 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4561 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4562 |
dp += bestIdx * 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4563 |
dR = dp[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4564 |
dG = dp[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4565 |
dB = dp[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4566 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4567 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4568 |
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
|
4569 |
__wantR, __wantG, __wantB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4570 |
__wR, __wG, __wB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4571 |
dR, dG, dB); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4572 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4573 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4574 |
* store the corresponding dither colors colorId |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4575 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4576 |
*dstP++ = idP[bestIdx]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4577 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4578 |
/* |
882 | 4579 |
* the new error & distribute the error |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4580 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4581 |
__eR = __wantR - dR; |
882 | 4582 |
if (__eR) { |
4583 |
tR = __eR >> 4; /* 16th of error */ |
|
4584 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
4585 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
4586 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
4587 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
4588 |
__eR = nR; |
|
4589 |
} else { |
|
4590 |
__eR = eP[3]; |
|
4591 |
eP[0] = eP[-3] = eP[3] = 0; |
|
4592 |
} |
|
4593 |
||
4594 |
__eG = __wantG - dG; |
|
4595 |
if (__eG) { |
|
4596 |
tG = __eG >> 4; |
|
4597 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
4598 |
eP[1] = tG*5; |
|
4599 |
eP[-2] = tG*3; |
|
4600 |
eP[4] = __eG - (tG*15); |
|
4601 |
__eG = nG; |
|
4602 |
} else { |
|
4603 |
__eG = eP[4]; |
|
4604 |
eP[1] = eP[-2] = eP[4] = 0; |
|
4605 |
} |
|
4606 |
||
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4607 |
__eB = __wantB - dB; |
882 | 4608 |
if (__eB) { |
4609 |
tB = __eB >> 4; |
|
4610 |
nB = eP[5] + (tB * 7); |
|
4611 |
eP[2] = tB*5; |
|
4612 |
eP[-1] = tB*3; |
|
4613 |
eP[5] = __eB - (tB*15); |
|
4614 |
__eB = nB; |
|
4615 |
} else { |
|
4616 |
__eB = eP[5]; |
|
4617 |
eP[2] = eP[-1] = eP[5] = 0; |
|
4618 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4619 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4620 |
eP += 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4621 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4622 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4623 |
} |
882 | 4624 |
printf("pixels: %d same: %d\n", __w*__h, nSame); |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4625 |
%}. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4626 |
failed ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4627 |
self primitiveFailed. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4628 |
^ nil |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4629 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4630 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4631 |
^ pseudoBits |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4632 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4633 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4634 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
4635 |
|
854 | 4636 |
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
858 | 4637 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
4638 |
which must be a depth-8 image. |
|
4639 |
This is a special-cased dither method for 8-bit palette images being displayed on |
|
4640 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
|
854 | 4641 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
4642 |
colors assigned to aDevice, such as the preallocated colors of the |
|
4643 |
Color class. |
|
4644 |
By passing the ditherColors as extra array, this method can |
|
4645 |
also be used to dither an 8bit image into a smaller number of colors, |
|
4646 |
for example to create dithered Depth4Images from Depth8Images." |
|
4647 |
||
858 | 4648 |
|pseudoBits |
854 | 4649 |
rgbBytes |
4650 |
w "{Class: SmallInteger }" |
|
4651 |
h "{Class: SmallInteger }" |
|
4652 |
index "{Class: SmallInteger }" |
|
4653 |
fixR "{Class: SmallInteger }" |
|
4654 |
fixG "{Class: SmallInteger }" |
|
4655 |
fixB "{Class: SmallInteger }" |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4656 |
fixGfixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4657 |
fixIds failed map lastColor |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4658 |
rgbIDX "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4659 |
idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes |
854 | 4660 |
error clr| |
4661 |
||
858 | 4662 |
self depth ~~ 8 ifTrue:[^ nil]. |
4663 |
||
854 | 4664 |
fixR := nRed. |
4665 |
fixR == 0 ifTrue:[ ^ nil]. |
|
4666 |
fixG := nGreen. |
|
4667 |
fixG == 0 ifTrue:[ ^ nil]. |
|
4668 |
fixB := nBlue. |
|
4669 |
fixB == 0 ifTrue:[ ^ nil]. |
|
4670 |
||
4671 |
"/ simple check |
|
4672 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
4673 |
self error:'invalid color array passed'. |
|
4674 |
^ nil |
|
4675 |
]. |
|
4676 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
4677 |
||
4678 |
"/ |
|
4679 |
"/ collect color components as integer values (for integer arithmetic) |
|
4680 |
"/ |
|
4681 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
|
4682 |
||
4683 |
index := 1. |
|
4684 |
||
4685 |
photometric == #palette ifTrue:[ |
|
4686 |
lastColor := colorMap size - 1 |
|
4687 |
] ifFalse:[ |
|
4688 |
lastColor := 255. |
|
4689 |
]. |
|
4690 |
0 to:lastColor do:[:pix | |
|
4691 |
clr := self colorFromValue:pix. |
|
4692 |
rgbBytes at:index put:(clr redByte). |
|
4693 |
rgbBytes at:index+1 put:(clr greenByte). |
|
4694 |
rgbBytes at:index+2 put:(clr blueByte). |
|
4695 |
||
4696 |
index := index + 3. |
|
4697 |
]. |
|
4698 |
||
4699 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
4700 |
||
4701 |
w := width + 2. |
|
4702 |
error := ByteArray uninitializedNew:w*(3*2). |
|
4703 |
||
4704 |
w := width. |
|
4705 |
h := height. |
|
4706 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4707 |
idxAndErrRBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4708 |
idxAndErrGBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4709 |
idxAndErrBBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4710 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4711 |
fixGfixB := fixG * fixB. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4712 |
index := 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4713 |
0 to:255 do:[:i | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4714 |
rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4715 |
idxAndErrRBytes at:index put:(rgbIDX * fixGfixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4716 |
idxAndErrRBytes at:index+1 put:i - (rgbIDX * 255 // (fixR-1)) + 128. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4717 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4718 |
rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4719 |
idxAndErrGBytes at:index put:(rgbIDX * fixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4720 |
idxAndErrGBytes at:index+1 put:i - (rgbIDX * 255 // (fixG-1)) + 128. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4721 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4722 |
rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4723 |
idxAndErrBBytes at:index put:(rgbIDX ). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4724 |
idxAndErrBBytes at:index+1 put:i - (rgbIDX * 255 // (fixB-1)) + 128. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4725 |
index := index + 2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4726 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4727 |
|
854 | 4728 |
failed := true. |
4729 |
||
4730 |
%{ |
|
4731 |
int __x, __y; |
|
4732 |
int __eR, __eG, __eB; |
|
4733 |
unsigned char *srcP, *dstP; |
|
4734 |
unsigned char *rgbP; |
|
4735 |
unsigned char *idP; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4736 |
unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes; |
854 | 4737 |
short *errP, *eP; |
4738 |
int idx; |
|
4739 |
int __w = __intVal(w); |
|
4740 |
||
4741 |
if (__isByteArray(__INST(bytes)) |
|
4742 |
&& __isByteArray(pseudoBits) |
|
4743 |
&& __isByteArray(rgbBytes) |
|
4744 |
&& __isByteArray(fixIds) |
|
4745 |
&& __isByteArray(error) |
|
4746 |
&& __bothSmallInteger(fixR, fixG) |
|
4747 |
&& __isSmallInteger(fixB)) { |
|
4748 |
failed = false; |
|
4749 |
||
4750 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
4751 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
4752 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
|
4753 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4754 |
__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4755 |
__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4756 |
__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element; |
854 | 4757 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
4758 |
||
4759 |
/* |
|
4760 |
* clear error accumulator |
|
4761 |
*/ |
|
4762 |
eP = errP; |
|
4763 |
bzero(eP, (__w+2) * 2 * 3); |
|
4764 |
||
4765 |
for (__y=__intVal(h); __y>0; __y--) { |
|
4766 |
__eR = __eG = __eB = 0; |
|
4767 |
||
4768 |
eP = &(errP[3]); |
|
4769 |
__eR = eP[0]; |
|
4770 |
__eG = eP[1]; |
|
4771 |
__eB = eP[2]; |
|
4772 |
||
4773 |
for (__x=__w; __x>0; __x--) { |
|
4774 |
int __want; |
|
4775 |
int pix; |
|
4776 |
int idx; |
|
4777 |
int tR, tG, tB; |
|
4778 |
int nR, nG, nB; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4779 |
int iRGB; |
854 | 4780 |
|
4781 |
pix = *srcP++; |
|
4782 |
||
4783 |
/* |
|
4784 |
* wR, wG and wB is the wanted r/g/b value; |
|
4785 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4786 |
pix = pix+pix+pix; /* pix * 3 */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4787 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4788 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4789 |
* compute indexR/G/B and the new error: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4790 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4791 |
__want = rgbP[pix] + __eR; |
854 | 4792 |
if (__want > 255) __want = 255; |
4793 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4794 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4795 |
idx = __idxAndErrRBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4796 |
__eR = __idxAndErrRBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4797 |
__eR -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4798 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4799 |
__want = rgbP[pix+1] + __eG; |
854 | 4800 |
if (__want > 255) __want = 255; |
4801 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4802 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4803 |
idx += __idxAndErrGBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4804 |
__eG = __idxAndErrGBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4805 |
__eG -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4806 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4807 |
__want = rgbP[pix+2] + __eB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4808 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4809 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4810 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4811 |
idx += __idxAndErrBBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4812 |
__eB = __idxAndErrBBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4813 |
__eB -= 128; |
854 | 4814 |
|
4815 |
/* |
|
4816 |
* store the corresponding dither colors colorId |
|
4817 |
*/ |
|
4818 |
*dstP++ = idP[idx]; |
|
4819 |
||
4820 |
/* |
|
4821 |
* distribute the error |
|
4822 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4823 |
if (__eR) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4824 |
tR = __eR >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4825 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4826 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4827 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4828 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4829 |
__eR = nR; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4830 |
} else { |
882 | 4831 |
__eR = eP[3]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4832 |
eP[0] = eP[-3] = eP[3] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4833 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4834 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4835 |
if (__eG) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4836 |
tG = __eG >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4837 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4838 |
eP[1] = tG*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4839 |
eP[-2] = tG*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4840 |
eP[4] = __eG - (tG*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4841 |
__eG = nG; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4842 |
} else { |
882 | 4843 |
__eG = eP[4]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4844 |
eP[1] = eP[-2] = eP[4] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4845 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4846 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4847 |
if (__eB) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4848 |
tB = __eB >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4849 |
nB = eP[5] + (tB * 7); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4850 |
eP[2] = tB*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4851 |
eP[-1] = tB*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4852 |
eP[5] = __eB - (tB*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4853 |
__eB = nB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4854 |
} else { |
882 | 4855 |
__eB = eP[5]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4856 |
eP[2] = eP[-1] = eP[5] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
4857 |
} |
854 | 4858 |
|
4859 |
eP += 3; |
|
4860 |
} |
|
4861 |
} |
|
4862 |
} |
|
4863 |
%}. |
|
4864 |
failed ifTrue:[ |
|
4865 |
self primitiveFailed. |
|
4866 |
^ nil |
|
4867 |
]. |
|
4868 |
||
4869 |
^ pseudoBits |
|
4870 |
||
4871 |
||
4872 |
! |
|
4873 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4874 |
floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4875 |
"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
|
4876 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4877 |
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
|
4878 |
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
|
4879 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4880 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4881 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4882 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4883 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4884 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4885 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4886 |
e eD t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4887 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4888 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4889 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4890 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4891 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4892 |
eR eRB eB eLB | |
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 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4895 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4896 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4897 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4898 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4899 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4900 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4901 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4902 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4903 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4904 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4905 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4906 |
nextErrorArray atAllPut:0. |
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 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4909 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4910 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4911 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4912 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4913 |
"/ 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
|
4914 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4915 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4916 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4917 |
greyValues := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4918 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4919 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4920 |
v rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4921 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4922 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4923 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4924 |
nextDst := dstIndex + bytesPerMonoRow. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4927 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4928 |
nextErrorArray := t. |
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 |
nextErrorArray atAllPut:0. |
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 |
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
|
4933 |
%{ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4934 |
int __grey, __e; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4935 |
int __byte = __intVal(byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4936 |
OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4937 |
OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4938 |
int __x = __intVal(x); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4939 |
int __eR, __eB, __eRB, __eLB, __eI; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4940 |
int __bitCnt = __intVal(bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4941 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4942 |
__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4943 |
__grey += __intVal(__errorArray[__x+1]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4944 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4945 |
__byte <<= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4946 |
if (__grey > 127*1024) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4947 |
__e = __grey - (255*1024); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4948 |
__byte |= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4949 |
} else { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4950 |
__e = __grey; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4951 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4952 |
if (__e) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4953 |
__eI = __e >> 4; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4954 |
__eR = __eI * 7; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4955 |
__eRB = __eI * 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4956 |
__eB = __eI * 5; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4957 |
__eLB = __e - __eR - __eRB - __eB; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4958 |
__errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4959 |
__nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4960 |
__nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4961 |
__nextErrorArray[__x ] = __MKSMALLINT(__intVal(__nextErrorArray[__x ]) + __eLB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4962 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4963 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4964 |
__bitCnt--; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4965 |
if (__bitCnt == 0) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4966 |
int __dstIndex = __intVal(dstIndex); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4967 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4968 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4969 |
dstIndex = __MKSMALLINT(__dstIndex + 1); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4970 |
__byte = 0; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4971 |
__bitCnt = 8; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4972 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4973 |
byte = __MKSMALLINT(__byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4974 |
bitCnt = __MKSMALLINT(__bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4975 |
%}. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4976 |
|
829 | 4977 |
"/ |eI "{ Class: SmallInteger }" |
4978 |
"/ xE "{ Class: SmallInteger }" |
|
4979 |
"/ xN "{ Class: SmallInteger }" | |
|
4980 |
"/ |
|
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4981 |
"/ "/ get the colors grey value [0 .. 1] |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4982 |
"/ grey := greyValues at:(pixel + 1). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4983 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4984 |
"/ "/ adjust error |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4985 |
"/ xE := x + 2. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4986 |
"/ grey := (grey + (errorArray at:xE)). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4987 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4988 |
"/ byte := byte bitShift:1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4989 |
"/ grey > (127*1024) ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4990 |
"/ byte := byte bitOr:1. "/ white |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4991 |
"/ e := grey - (255*1024) |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4992 |
"/ ] ifFalse:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4993 |
"/ e := grey "/ black |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4994 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4995 |
"/ e ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4996 |
"/ eD := e. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4997 |
"/ eI := e // 16. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4998 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4999 |
"/ eR := eI * 7. "/ 7/16 to right |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5000 |
"/ eRB := eI * 1. "/ 1/16 to right below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5001 |
"/ eB := eI * 5. "/ 5/16 to below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5002 |
"/ eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5003 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5004 |
"/ xN := xE + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5005 |
"/ eR ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5006 |
"/ errorArray at:xN put:(errorArray at:xN) + eR. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5007 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5008 |
"/ eRB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5009 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5010 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5011 |
"/ eB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5012 |
"/ nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5013 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5014 |
"/ eLB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5015 |
"/ xN := xE - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5016 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5017 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5018 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5019 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5020 |
"/ bitCnt := bitCnt - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5021 |
"/ bitCnt == 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5022 |
"/ monoBits at:dstIndex put:byte. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5023 |
"/ dstIndex := dstIndex + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5024 |
"/ byte := 0. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5025 |
"/ bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5026 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5027 |
0 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5028 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5029 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5030 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5031 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5032 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5033 |
byte := 0. |
809
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5036 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5037 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5038 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5039 |
'IMAGE: slow floydSteinberg dither ..' infoPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5040 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5041 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5042 |
nextDst := dstIndex + bytesPerMonoRow. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5045 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5046 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5047 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5048 |
nextErrorArray atAllPut:0. |
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 |
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
|
5051 |
|eI "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5052 |
xE "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5053 |
xN "{ Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5054 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5055 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5056 |
grey := (clr brightness * 255). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5057 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5058 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5059 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5060 |
grey := (grey + (errorArray at:xE)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5061 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5062 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5063 |
grey > 127 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5064 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5065 |
e := grey - 255 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5066 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5067 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5068 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5069 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5070 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5071 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5072 |
eI := e // 16. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5073 |
eR := eI * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5074 |
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
|
5075 |
eB := eI * 5. "/ 5/16 to below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5076 |
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
|
5077 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5078 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5079 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5080 |
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
|
5081 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5082 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5083 |
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
|
5084 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5085 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5086 |
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
|
5087 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5088 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5089 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5090 |
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
|
5091 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5092 |
]. |
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 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5095 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5096 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5097 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5098 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5099 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5100 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5101 |
|
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 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5104 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5105 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5106 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5107 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5108 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5109 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5110 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5111 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5112 |
]. |
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 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5115 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5116 |
"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
|
5117 |
"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
|
5118 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5119 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5120 |
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5121 |
"return a nearest paint bitmap from the receiver picture, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5122 |
which must be a depth-8 image. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5123 |
This is a special-cased dither method for 8-bit palette images being displayed on |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5124 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5125 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5126 |
colors assigned to aDevice, such as the preallocated colors of the |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5127 |
Color class. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5128 |
By passing the ditherColors as extra array, this method can |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5129 |
also be used to dither an 8bit image into a smaller number of colors, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5130 |
for example to create dithered Depth4Images from Depth8Images." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5131 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5132 |
|pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5133 |
rgbBytes |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5134 |
w "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5135 |
h "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5136 |
index "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5137 |
fixR "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5138 |
fixG "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5139 |
fixB "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5140 |
fixGfixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5141 |
fixIds failed map lastColor |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5142 |
idxRBytes idxGBytes idxBBytes |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5143 |
clr| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5144 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5145 |
self depth ~~ 8 ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5146 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5147 |
fixR := nRed. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5148 |
fixR == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5149 |
fixG := nGreen. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5150 |
fixG == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5151 |
fixB := nBlue. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5152 |
fixB == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5153 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5154 |
"/ simple check |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5155 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5156 |
self error:'invalid color array passed'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5157 |
^ nil |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5158 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5159 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5160 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5161 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5162 |
"/ collect color components as integer values (for integer arithmetic) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5163 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5164 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5165 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5166 |
index := 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5167 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5168 |
photometric == #palette ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5169 |
lastColor := colorMap size - 1 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5170 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5171 |
lastColor := 255. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5172 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5173 |
0 to:lastColor do:[:pix | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5174 |
clr := self colorFromValue:pix. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5175 |
rgbBytes at:index put:(clr redByte). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5176 |
rgbBytes at:index+1 put:(clr greenByte). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5177 |
rgbBytes at:index+2 put:(clr blueByte). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5178 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5179 |
index := index + 3. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5180 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5181 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5182 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5183 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5184 |
w := width. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5185 |
h := height. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5186 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5187 |
idxRBytes := ByteArray uninitializedNew:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5188 |
idxGBytes := ByteArray uninitializedNew:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5189 |
idxBBytes := ByteArray uninitializedNew:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5190 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5191 |
fixGfixB := fixG * fixB. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5192 |
index := 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5193 |
0 to:255 do:[:i | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5194 |
idxRBytes at:index put:((i * (fixR-1) + 128) // 255) * fixGfixB. "red index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5195 |
idxGBytes at:index put:((i * (fixG-1) + 128) // 255) * fixB. "green index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5196 |
idxBBytes at:index put:((i * (fixB-1) + 128) // 255). "blue index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5197 |
index := index + 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5198 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5199 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5200 |
failed := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5201 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5202 |
%{ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5203 |
int __x, __y; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5204 |
unsigned char *srcP, *dstP; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5205 |
unsigned char *rgbP; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5206 |
unsigned char *idP; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5207 |
unsigned char *__idxRBytes, *__idxGBytes, *__idxBBytes; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5208 |
int __w = __intVal(w); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5209 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5210 |
if (__isByteArray(__INST(bytes)) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5211 |
&& __isByteArray(pseudoBits) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5212 |
&& __isByteArray(rgbBytes) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5213 |
&& __isByteArray(fixIds)) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5214 |
failed = false; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5215 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5216 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5217 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5218 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5219 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5220 |
__idxRBytes = __ByteArrayInstPtr(idxRBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5221 |
__idxGBytes = __ByteArrayInstPtr(idxGBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5222 |
__idxBBytes = __ByteArrayInstPtr(idxBBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5223 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5224 |
for (__y=__intVal(h); __y>0; __y--) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5225 |
for (__x=__w; __x>0; __x--) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5226 |
int __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5227 |
int pix; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5228 |
int idx; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5229 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5230 |
pix = *srcP++; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5231 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5232 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5233 |
* wR, wG and wB is the wanted r/g/b value; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5234 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5235 |
pix = pix+pix+pix; /* pix * 3 */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5236 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5237 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5238 |
* compute indexR/G/B |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5239 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5240 |
__want = rgbP[pix]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5241 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5242 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5243 |
idx = __idxRBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5244 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5245 |
__want = rgbP[pix+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5246 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5247 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5248 |
idx += __idxGBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5249 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5250 |
__want = rgbP[pix+2]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5251 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5252 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5253 |
idx += __idxBBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5254 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5255 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5256 |
* store the corresponding nearest colors colorId |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5257 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5258 |
*dstP++ = idP[idx]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5259 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5260 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5261 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5262 |
%}. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5263 |
failed ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5264 |
self primitiveFailed. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5265 |
^ nil |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5266 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5267 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5268 |
^ pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5269 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5270 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5271 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5272 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5273 |
orderedDitheredBitsDepth:depth |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5274 |
"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
|
5275 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5276 |
^ self |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5277 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5278 |
ditherWidth:8 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5279 |
depth:depth. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5280 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5281 |
"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
|
5282 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5283 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5284 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5285 |
"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
|
5286 |
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
|
5287 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5288 |
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
|
5289 |
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
|
5290 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5291 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5292 |
greyLevels greyValues greyPixels greyErrors |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5293 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5294 |
nextDst |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5295 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5296 |
pixelsPerByte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5297 |
outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5298 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5299 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5300 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5301 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5302 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5303 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5304 |
'IMAGE: unimplemented orderedDither conversion' errorPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5305 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5306 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5307 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5308 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5309 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5310 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5311 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5312 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5313 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5314 |
greyLevels := 1 bitShift:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5315 |
pixelsPerByte := 8 / depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5316 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5317 |
bytesPerOutRow := (w * depth + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5318 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5319 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5320 |
^ nil |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5323 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5324 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5325 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5326 |
"/ 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
|
5327 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5328 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5329 |
greyValues := self greyMapForRange:(greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5330 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5331 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5332 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5333 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5334 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5335 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5336 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5337 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5338 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5339 |
((v - v truncated) * nDither) rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5340 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5341 |
greyErrors := ByteArray withAll:greyErrors. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5342 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5343 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5344 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5345 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5346 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5347 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5348 |
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
|
5349 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5350 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5351 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5352 |
int __value = __intVal(value); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5353 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5354 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5355 |
int __pixel, __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5356 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5357 |
unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5358 |
unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5359 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5360 |
__pixel = __greyPixels[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5361 |
__grey = __greyErrors[__value]; |
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 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5364 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5365 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5366 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5367 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5368 |
__pixel++; |
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 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5371 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5372 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5373 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5374 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5375 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5376 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5377 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5378 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5379 |
__bitCnt = 8; |
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 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5382 |
bitCnt = __MKSMALLINT(__bitCnt); |
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 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5385 |
|
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 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5388 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5389 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5390 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5391 |
dstIndex := nextDst. |
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 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5394 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
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 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5397 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5398 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5399 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5400 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5401 |
"/ this is the representaion independent (but slow) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5402 |
"/ 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
|
5403 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5404 |
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
|
5405 |
|dstClr grey dT pixel| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5406 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5407 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5408 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5409 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5410 |
"/ remap into [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5411 |
grey := grey * (greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5412 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5413 |
"/ get threshold pixel [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5414 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5415 |
pixel := grey truncated. |
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 |
"/ compute the error [0..1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5418 |
grey := grey - pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5419 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5420 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5421 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5422 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5423 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5424 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5425 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5426 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5427 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5428 |
int __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5429 |
int __bitCnt = __intVal(bitCnt); |
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 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5432 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5433 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
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 |
__pixel = __intVal(pixel); |
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 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5438 |
__pixel++; |
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 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5441 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5442 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5443 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5444 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5445 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5446 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5447 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5448 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5449 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5450 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5451 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5452 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5453 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5454 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5455 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5456 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5457 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5458 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5459 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5460 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5461 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5462 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5463 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5464 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5465 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5466 |
|
831 | 5467 |
orderedDitheredMonochromeBits |
5468 |
"return the bitmap for a dithered monochrome bitmap from the image; |
|
5469 |
using a default ditherMatrix." |
|
5470 |
||
5471 |
^ self |
|
5472 |
orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
5473 |
ditherWidth:8 |
|
5474 |
||
5475 |
"Created: 11.6.1996 / 16:48:57 / cg" |
|
5476 |
! |
|
5477 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5478 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5479 |
"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
|
5480 |
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
|
5481 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5482 |
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
|
5483 |
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
|
5484 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5485 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5486 |
greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5487 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5488 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5489 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5490 |
monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5491 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5492 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5493 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5494 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5495 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5496 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5497 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5498 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5499 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5500 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5501 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5502 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5503 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5504 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5505 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5506 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5507 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5508 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5509 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5510 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5511 |
"/ 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
|
5512 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5513 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5514 |
greyValues := self greyByteMapForRange:nDither. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5515 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5516 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5517 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5518 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5519 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5520 |
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
|
5521 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5522 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5523 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5524 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5525 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5526 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5527 |
int __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5528 |
unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5529 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5530 |
__grey = __greyValues[__intVal(value)]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5531 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5532 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5533 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5534 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5535 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5536 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5537 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5538 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5539 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5540 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5541 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5542 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5543 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5544 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5545 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5546 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5547 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5548 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5549 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5550 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5551 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5552 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5553 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5554 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5555 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5556 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5557 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5558 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5559 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5560 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5561 |
Transcript showCR:'slow ordered dither ..'. Transcript endEntry. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5562 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5563 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5564 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5565 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5566 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5567 |
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
|
5568 |
|dstClr grey dT| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5569 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5570 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5571 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5572 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5573 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5574 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5575 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5576 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5577 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5578 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5579 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5580 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5581 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5582 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5583 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5584 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5585 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5586 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5587 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5588 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5589 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5590 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5591 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5592 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5593 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5594 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5595 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5596 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5597 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5598 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5599 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5600 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5601 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5602 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5603 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5604 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5605 |
"/ 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
|
5606 |
"/ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5607 |
"/ byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5608 |
"/ grey < dT ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5609 |
"/ byte := byte bitOr:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5610 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5611 |
"/ bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5612 |
"/ bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5613 |
"/ monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5614 |
"/ dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5615 |
"/ byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5616 |
"/ bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5617 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5618 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5619 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5620 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5621 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5622 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5623 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5624 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5625 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5626 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5627 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5628 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5629 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5630 |
stevensonArceDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5631 |
"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
|
5632 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5633 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5634 |
|f last |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5635 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5636 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5637 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5638 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5639 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5640 |
errorArray1 errorArray2 errorArray3 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5641 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5642 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5643 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5644 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5645 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5646 |
direction "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5647 |
dstClr grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5648 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5649 |
xN "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5650 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5651 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5652 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5653 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5654 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5655 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5656 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5657 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5658 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5659 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5660 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5661 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5662 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5663 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5664 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5665 |
errorArray := Array new:(w+6). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5666 |
errorArray1 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5667 |
errorArray2 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5668 |
errorArray3 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5669 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5670 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5671 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5672 |
"/ 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
|
5673 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5674 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5675 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5676 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5677 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5678 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5679 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5680 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5681 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5682 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5683 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5684 |
errorArray1 := errorArray2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5685 |
errorArray2 := errorArray3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5686 |
errorArray3 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5687 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5688 |
errorArray3 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5689 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5690 |
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
|
5691 |
|eP eD| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5692 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5693 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5694 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5695 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5696 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5697 |
xE := x + 3 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5698 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5699 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5700 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5701 |
grey > (127 * 1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5702 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5703 |
e := grey - (255 * 1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5704 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5705 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5706 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5707 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5708 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5709 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5710 |
"/ XX 32 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5711 |
"/ 12 26 30 16 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5712 |
"/ 12 26 12 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5713 |
"/ 5 12 12 5 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5714 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5715 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5716 |
e := e // 200. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5717 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5718 |
eP := e * 32. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5719 |
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
|
5720 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5721 |
eP := e * 30. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5722 |
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
|
5723 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5724 |
eP := e * 16. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5725 |
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
|
5726 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5727 |
eP := e * 26. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5728 |
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
|
5729 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5730 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5731 |
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
|
5732 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5733 |
eP := e * 12. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5734 |
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
|
5735 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5736 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5737 |
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
|
5738 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5739 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5740 |
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
|
5741 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5742 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5743 |
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
|
5744 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5745 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5746 |
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
|
5747 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5748 |
eP := e * 5. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5749 |
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
|
5750 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5751 |
eP := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5752 |
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
|
5753 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5754 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5755 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5756 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5757 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5758 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5759 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5760 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5761 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5762 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5763 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5764 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5765 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5766 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5767 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5768 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5769 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5770 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5771 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5772 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5773 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5774 |
"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
|
5775 |
"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
|
5776 |
! ! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5777 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5778 |
!Image methodsFor:'drawing'! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5779 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5780 |
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
|
5781 |
|pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5782 |
xI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5783 |
yI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5784 |
wI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5785 |
hI "{ Class: SmallInteger }"| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5786 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5787 |
pixel := self valueFromColor:aColor. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5788 |
xI := x. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5789 |
yI := y. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5790 |
wI := w. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5791 |
hI := h. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5792 |
yI to:yI+hI-1 do:[:yRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5793 |
xI to:xI+wI-1 do:[:xRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5794 |
self atX:xRun y:yRun putValue:pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5795 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5796 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5797 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5798 |
"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
|
5799 |
"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
|
5800 |
! ! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
5801 |
|
283 | 5802 |
!Image methodsFor:'enumerating'! |
5803 |
||
5804 |
atY:y from:x1 to:x2 do:aBlock |
|
5805 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5806 |
The block is passed the color at each pixel. |
|
5807 |
The code here provides a generic and slow implementation, and |
|
5808 |
should be redefined in concrete subclasses, to avoid some processing |
|
5809 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5810 |
and also the color allocation)." |
|
5811 |
||
798 | 5812 |
self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'. |
5813 |
self colorsAtY:y from:x1 to:x2 do:aBlock |
|
5814 |
||
5815 |
"Modified: 7.6.1996 / 19:13:30 / cg" |
|
5816 |
! |
|
5817 |
||
5818 |
colorsAtY:y from:x1 to:x2 do:aBlock |
|
5819 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
5820 |
The block is passed the color at each pixel. |
|
5821 |
The code here provides a generic and slow implementation, and |
|
5822 |
should be redefined in concrete subclasses, to avoid some processing |
|
5823 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
5824 |
and also the color allocation)." |
|
5825 |
||
283 | 5826 |
|xStart "{Class: SmallInteger }" |
5827 |
xEnd "{Class: SmallInteger }"| |
|
5828 |
||
5829 |
xStart := x1. |
|
5830 |
xEnd := x2. |
|
5831 |
xStart to:xEnd do:[:xRun | |
|
798 | 5832 |
aBlock value:xRun value:(self atX:xRun y:y) |
283 | 5833 |
] |
798 | 5834 |
|
5835 |
"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
|
5836 |
"Modified: 10.6.1996 / 10:27:29 / cg" |
283 | 5837 |
! |
5838 |
||
5839 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5840 |
"perform aBlock for each color in a rectangular area of the image. |
|
5841 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5842 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5843 |
The code here provides a generic and slow implementation, and |
|
5844 |
should be redefined in concrete subclasses, to avoid some processing |
|
5845 |
when going from pixel to pixel (i.e. the byte-index and mask computations, |
|
5846 |
and especially, the color allocations)." |
|
5847 |
||
5848 |
|xS "{Class: SmallInteger }" |
|
5849 |
xE "{Class: SmallInteger }"| |
|
5850 |
||
5851 |
xS := xStart. |
|
5852 |
xE := xEnd. |
|
5853 |
yStart to:yEnd do:[:yRun | |
|
798 | 5854 |
self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color | |
5855 |
aBlock value:xRun value:yRun value:color |
|
5856 |
] |
|
283 | 5857 |
] |
798 | 5858 |
|
5859 |
"Modified: 7.6.1996 / 19:11:39 / cg" |
|
283 | 5860 |
! |
5861 |
||
5862 |
valueAtY:y from:x1 to:x2 do:aBlock |
|
5863 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
798 | 5864 |
Obsolete - remains for backward compatibility." |
5865 |
||
5866 |
self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'. |
|
5867 |
self valuesAtY:y from:x1 to:x2 do:aBlock |
|
5868 |
||
5869 |
"Modified: 7.6.1996 / 19:11:06 / cg" |
|
5870 |
! |
|
5871 |
||
5872 |
valuesAtY:y from:x1 to:x2 do:aBlock |
|
5873 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
283 | 5874 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
5875 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
5876 |
(see also Image>>atY:from:to:do:). |
|
5877 |
The code here provides a generic and slow implementation, and |
|
5878 |
should be redefined in concrete subclasses, to avoid some processing |
|
5879 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
5880 |
||
5881 |
|xStart "{Class: SmallInteger }" |
|
5882 |
xEnd "{Class: SmallInteger }"| |
|
5883 |
||
5884 |
xStart := x1. |
|
5885 |
xEnd := x2. |
|
5886 |
xStart to:xEnd do:[:xRun | |
|
692 | 5887 |
aBlock value:xRun value:(self valueAtX:xRun y:y) |
283 | 5888 |
] |
692 | 5889 |
|
5890 |
"Modified: 17.5.1996 / 12:03:59 / cg" |
|
798 | 5891 |
"Created: 7.6.1996 / 19:09:51 / cg" |
283 | 5892 |
! |
5893 |
||
5894 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
5895 |
"perform aBlock for each pixelValue in a rectangular area of the image. |
|
5896 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
5897 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
5898 |
The code here provides a generic and slow implementation, and |
|
5899 |
should be redefined in concrete subclasses, to avoid some processing |
|
5900 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
5901 |
||
5902 |
|xS "{Class: SmallInteger }" |
|
5903 |
xE "{Class: SmallInteger }"| |
|
5904 |
||
5905 |
xS := xStart. |
|
5906 |
xE := xEnd. |
|
5907 |
yStart to:yEnd do:[:yRun | |
|
798 | 5908 |
self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel | |
5909 |
aBlock value:xRun value:yRun value:pixel |
|
5910 |
] |
|
283 | 5911 |
] |
798 | 5912 |
|
5913 |
"Modified: 7.6.1996 / 19:09:29 / cg" |
|
0 | 5914 |
! ! |
5915 |
||
5916 |
!Image methodsFor:'image manipulations'! |
|
5917 |
||
283 | 5918 |
colorMapProcessing:aBlock |
5919 |
"a helper for all kinds of colormap manipulations. |
|
592 | 5920 |
The argument, aBlock is called for every colormap entry, |
5921 |
and the returned value will replace the original entry in the map. |
|
283 | 5922 |
This will fail for non-palette images. |
592 | 5923 |
See examples in Image>>copyWithColorMapProcessing:" |
283 | 5924 |
|
5925 |
|nColors "{ Class: SmallInteger }"| |
|
5926 |
||
5927 |
colorMap isNil ifTrue:[ |
|
592 | 5928 |
^ self error:'image has no colormap' |
283 | 5929 |
]. |
5930 |
||
5931 |
nColors := colorMap size. |
|
5932 |
1 to:nColors do:[:index | |
|
592 | 5933 |
|clr| |
5934 |
||
5935 |
clr := colorMap at:index. |
|
5936 |
clr notNil ifTrue:[ |
|
5937 |
colorMap at:index put:(aBlock value:clr) |
|
5938 |
] |
|
283 | 5939 |
] |
592 | 5940 |
|
5941 |
"Modified: 23.4.1996 / 11:13:55 / cg" |
|
283 | 5942 |
! |
5943 |
||
89 | 5944 |
copyWithColorMapProcessing:aBlock |
81 | 5945 |
"a helper to create & return new images based on the receiver with |
89 | 5946 |
some colorMap processing. The receiver is copied, and the copied images |
5947 |
colormap is modified by replacing entries with the result of the processing block, |
|
5948 |
which is called with the original color values. The block is supposed to return |
|
5949 |
a color." |
|
81 | 5950 |
|
5951 |
|newImage| |
|
5952 |
||
5953 |
newImage := self copy. |
|
5954 |
newImage colorMap isNil ifTrue:[ |
|
5955 |
self error:'no colormap in image'. |
|
5956 |
^ nil |
|
5957 |
]. |
|
5958 |
||
5959 |
" |
|
5960 |
the code below manipulates the colormap. |
|
5961 |
For non-palette images, special code is required |
|
5962 |
" |
|
89 | 5963 |
newImage colorMapProcessing:aBlock. |
81 | 5964 |
^ newImage |
5965 |
||
5966 |
" |
|
5967 |
leave red component only: |
|
5968 |
||
5969 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5970 |
copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] |
81 | 5971 |
" |
89 | 5972 |
|
81 | 5973 |
" |
5974 |
make it reddish: |
|
5975 |
||
5976 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5977 |
copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] |
81 | 5978 |
" |
89 | 5979 |
|
81 | 5980 |
" |
5981 |
invert: |
|
5982 |
||
5983 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5984 |
copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] |
81 | 5985 |
" |
89 | 5986 |
|
81 | 5987 |
" |
5988 |
lighter: |
|
5989 |
||
5990 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 5991 |
copyWithColorMapProcessing:[:clr | |r g b| |
5992 |
r := clr red. g := clr green. b := clr blue. |
|
5993 |
Color red:(r + (100-r//2)) |
|
5994 |
green:(g + (100-g//2)) |
|
5995 |
blue:(b + (100-b//2))] |
|
81 | 5996 |
" |
89 | 5997 |
|
81 | 5998 |
" |
5999 |
darker: |
|
6000 |
||
6001 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 6002 |
copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] |
81 | 6003 |
" |
6004 |
! |
|
6005 |
||
283 | 6006 |
darkened |
6007 |
"return a new image which is slightly darker than the receiver. |
|
6008 |
The receiver must be a palette image (currently). |
|
592 | 6009 |
CAVEAT: Need an argument, which specifies by how much it should be darker." |
283 | 6010 |
|
6011 |
^ self |
|
592 | 6012 |
copyWithColorMapProcessing:[:clr | |
6013 |
Color red:(clr red // 2) |
|
6014 |
green:(clr green // 2) |
|
6015 |
blue:(clr blue // 2)] |
|
283 | 6016 |
|
6017 |
" |
|
6018 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
6019 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
6020 |
" |
|
592 | 6021 |
|
6022 |
"Modified: 23.4.1996 / 11:14:34 / cg" |
|
283 | 6023 |
! |
6024 |
||
6025 |
flipHorizontal |
|
6026 |
"inplace horizontal flip" |
|
6027 |
||
6028 |
|w "{Class: SmallInteger }" |
|
6029 |
h "{Class: SmallInteger }" |
|
6030 |
c2 "{Class: SmallInteger }" |
|
6031 |
value | |
|
6032 |
||
6033 |
w := width - 1. |
|
6034 |
h := height - 1. |
|
6035 |
||
6036 |
0 to:h do:[:row | |
|
6037 |
c2 := w. |
|
6038 |
0 to:(w // 2) do:[:col | |
|
6039 |
value := self valueAtX:col y:row. |
|
6040 |
self atX:col y:row putValue:(self valueAtX:c2 y:row). |
|
6041 |
self atX:c2 y:row putValue:value. |
|
6042 |
c2 := c2 - 1. |
|
6043 |
] |
|
81 | 6044 |
]. |
283 | 6045 |
"flush device info" |
6046 |
self restored |
|
6047 |
! |
|
6048 |
||
6049 |
flipVertical |
|
6050 |
"inplace vertical flip" |
|
6051 |
||
6052 |
|h "{Class: SmallInteger }" |
|
6053 |
bytesPerRow "{Class: SmallInteger }" |
|
6054 |
buffer |
|
6055 |
indexLow "{Class: SmallInteger }" |
|
6056 |
indexHi "{Class: SmallInteger }"| |
|
6057 |
||
6058 |
bytesPerRow := self bytesPerRow. |
|
6059 |
buffer := ByteArray new:bytesPerRow. |
|
6060 |
||
6061 |
h := height - 1. |
|
6062 |
||
6063 |
indexLow := 1. |
|
6064 |
indexHi := bytesPerRow * h + 1. |
|
6065 |
||
6066 |
0 to:(h // 2) do:[:row | |
|
6067 |
buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow. |
|
6068 |
bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi. |
|
6069 |
bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1. |
|
6070 |
indexLow := indexLow + bytesPerRow. |
|
6071 |
indexHi := indexHi - bytesPerRow. |
|
6072 |
]. |
|
6073 |
"flush device info" |
|
6074 |
self restored |
|
6075 |
! |
|
6076 |
||
6077 |
hardMagnifiedBy:scalePoint |
|
6078 |
"return a new image magnified by scalePoint, aPoint. |
|
6079 |
This is the general magnification method, handling non-integral values. |
|
6080 |
It is slower than the integral magnification method." |
|
6081 |
||
6082 |
|mX |
|
6083 |
mY |
|
6084 |
newWidth "{ Class: SmallInteger }" |
|
6085 |
newHeight "{ Class: SmallInteger }" |
|
6086 |
w "{ Class: SmallInteger }" |
|
6087 |
h "{ Class: SmallInteger }" |
|
6088 |
newImage newBits bitsPerPixel newBytesPerRow |
|
6089 |
value srcRow| |
|
6090 |
||
6091 |
mX := scalePoint x. |
|
6092 |
mY := scalePoint y. |
|
6093 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
6094 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
6095 |
||
6096 |
newWidth := (width * mX) truncated. |
|
6097 |
newHeight := (height * mY) truncated. |
|
6098 |
||
6099 |
bitsPerPixel := self depth. |
|
6100 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
6101 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
6102 |
||
6103 |
newImage := self species new. |
|
6104 |
newImage bits:newBits. |
|
6105 |
newImage width:newWidth. |
|
6106 |
newImage height:newHeight. |
|
6107 |
newImage photometric:photometric. |
|
6108 |
newImage samplesPerPixel:samplesPerPixel. |
|
6109 |
newImage bitsPerSample:bitsPerSample. |
|
6110 |
newImage colorMap:colorMap copy. |
|
6111 |
||
6112 |
"walk over destination image fetching pixels from source image" |
|
6113 |
||
6114 |
w := newWidth - 1. |
|
6115 |
h := newHeight - 1. |
|
6116 |
||
6117 |
0 to:h do:[:row | |
|
6118 |
srcRow := (row // mY). |
|
6119 |
0 to:w do:[:col | |
|
6120 |
value := self valueAtX:(col // mX) y:srcRow. |
|
6121 |
newImage atX:col y:row putValue:value. |
|
89 | 6122 |
] |
283 | 6123 |
]. |
6124 |
||
6125 |
^ newImage |
|
6126 |
||
6127 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
|
6128 |
! |
|
6129 |
||
6130 |
hardRotated:degrees |
|
592 | 6131 |
"raise an error - rotation by arbitrary angles is not yet implemented" |
6132 |
||
283 | 6133 |
self error:'not yet implemented' |
592 | 6134 |
|
6135 |
"Modified: 23.4.1996 / 11:15:33 / cg" |
|
81 | 6136 |
! |
6137 |
||
54 | 6138 |
lightened |
89 | 6139 |
"return a new image which is slightly brighter than the receiver. |
6140 |
The receiver must be a palette image (currently). |
|
592 | 6141 |
CAVEAT: Need an argument, which specifies by how much it should be lighter." |
54 | 6142 |
|
81 | 6143 |
^ self |
592 | 6144 |
copyWithColorMapProcessing:[:clr | |r g b| |
6145 |
r := clr red. |
|
6146 |
g := clr green. |
|
6147 |
b := clr blue. |
|
6148 |
Color red:(r + (100-r//2)) |
|
6149 |
green:(g + (100-g//2)) |
|
6150 |
blue:(b + (100-b//2))] |
|
81 | 6151 |
|
6152 |
" |
|
6153 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
6154 |
(Image fromFile:'bitmaps/claus.gif') lightened inspect |
|
6155 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
6156 |
(Image fromFile:'bitmaps/claus.gif') darkened darkened inspect |
|
6157 |
" |
|
592 | 6158 |
|
6159 |
"Modified: 23.4.1996 / 11:14:41 / cg" |
|
54 | 6160 |
! |
6161 |
||
134 | 6162 |
magnifiedBy:scale |
81 | 6163 |
"return a new image magnified by scalePoint, aPoint. |
72 | 6164 |
If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:' |
6165 |
while simple (integral) magnifications are handled here." |
|
0 | 6166 |
|
81 | 6167 |
|scalePoint mX mY |
46 | 6168 |
magX "{ Class: SmallInteger }" "new version of stc can find this out itself..." |
6169 |
magY "{ Class: SmallInteger }" |
|
6170 |
srcOffset "{ Class: SmallInteger }" |
|
6171 |
dstOffset "{ Class: SmallInteger }" |
|
6172 |
w "{ Class: SmallInteger }" |
|
6173 |
h "{ Class: SmallInteger }" |
|
6174 |
first |
|
81 | 6175 |
newWidth newHeight newImage newBits |
6176 |
bitsPerPixel newBytesPerRow oldBytesPerRow| |
|
0 | 6177 |
|
81 | 6178 |
scalePoint := scale asPoint. |
6179 |
mX := scalePoint asPoint x. |
|
6180 |
mY := scalePoint asPoint y. |
|
46 | 6181 |
((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil]. |
0 | 6182 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
6183 |
||
12 | 6184 |
((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[ |
134 | 6185 |
^ self hardMagnifiedBy:scalePoint |
0 | 6186 |
]. |
6187 |
||
2 | 6188 |
bitsPerPixel := self depth. |
0 | 6189 |
oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8. |
6190 |
||
46 | 6191 |
w := width. |
6192 |
h := height. |
|
6193 |
magX := mX. |
|
6194 |
magY := mY. |
|
6195 |
||
6196 |
newWidth := w * mX. |
|
6197 |
newHeight := h * mY. |
|
0 | 6198 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
6199 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
6200 |
||
6201 |
newImage := self species new. |
|
2 | 6202 |
newImage bits:newBits. |
0 | 6203 |
newImage width:newWidth. |
6204 |
newImage height:newHeight. |
|
6205 |
newImage photometric:photometric. |
|
6206 |
newImage samplesPerPixel:samplesPerPixel. |
|
6207 |
newImage bitsPerSample:bitsPerSample. |
|
6208 |
newImage colorMap:colorMap copy. |
|
6209 |
||
6210 |
mX = 1 ifTrue:[ |
|
72 | 6211 |
"expand rows only" |
6212 |
srcOffset := 1. |
|
6213 |
dstOffset := 1. |
|
0 | 6214 |
|
72 | 6215 |
1 to:h do:[:row | |
6216 |
1 to:mY do:[:i | |
|
6217 |
newBits replaceFrom:dstOffset |
|
6218 |
to:(dstOffset + oldBytesPerRow - 1) |
|
6219 |
with:bytes |
|
6220 |
startingAt:srcOffset. |
|
6221 |
dstOffset := dstOffset + newBytesPerRow |
|
6222 |
]. |
|
6223 |
srcOffset := srcOffset + oldBytesPerRow. |
|
6224 |
]. |
|
0 | 6225 |
] ifFalse:[ |
72 | 6226 |
"expand cols" |
6227 |
(mX > 1) ifTrue:[ |
|
6228 |
dstOffset := 1. |
|
6229 |
srcOffset := 1. |
|
6230 |
1 to:h do:[:row | |
|
6231 |
self magnifyRowFrom:bytes |
|
6232 |
offset:srcOffset |
|
6233 |
into:newBits |
|
6234 |
offset:dstOffset |
|
6235 |
factor:mX. |
|
0 | 6236 |
|
72 | 6237 |
first := dstOffset. |
6238 |
dstOffset := dstOffset + newBytesPerRow. |
|
6239 |
" and copy for row expansion " |
|
6240 |
2 to:mY do:[:i | |
|
6241 |
newBits replaceFrom:dstOffset |
|
6242 |
to:(dstOffset + newBytesPerRow - 1) |
|
6243 |
with:newBits |
|
6244 |
startingAt:first. |
|
6245 |
dstOffset := dstOffset + newBytesPerRow |
|
6246 |
]. |
|
6247 |
srcOffset := srcOffset + oldBytesPerRow. |
|
6248 |
]. |
|
6249 |
] |
|
0 | 6250 |
]. |
6251 |
^ newImage |
|
6252 |
||
134 | 6253 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)" |
2 | 6254 |
! |
6255 |
||
154 | 6256 |
magnifiedPreservingRatioTo:anExtent |
6257 |
"return a new image magnified to fit into anExtent, |
|
6258 |
preserving the receivers width/height ratio. |
|
6259 |
(i.e. not distorting the image). |
|
6260 |
See also #magnifiedTo: and #magnifiedBy:" |
|
6261 |
||
6262 |
|rX rY| |
|
6263 |
||
6264 |
rX := anExtent x / self width. |
|
6265 |
rY := anExtent y / self height. |
|
6266 |
^ self magnifiedBy:(rX min:rY) |
|
6267 |
||
6268 |
" |
|
6269 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
6270 |
||
6271 |
in contrast to: |
|
6272 |
||
6273 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
|
6274 |
" |
|
6275 |
! |
|
6276 |
||
134 | 6277 |
magnifiedTo:anExtent |
154 | 6278 |
"return a new image magnified to have the size specified by extent. |
6279 |
This may distort the image if the arguments ratio is not the images ratio. |
|
6280 |
See also #magnifiedPreservingRatioTo: and #magnifiedBy:" |
|
89 | 6281 |
|
134 | 6282 |
^ self magnifiedBy:(anExtent / self extent) |
89 | 6283 |
|
6284 |
" |
|
134 | 6285 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
154 | 6286 |
|
6287 |
in contrast to: |
|
6288 |
||
6289 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
89 | 6290 |
" |
6291 |
! |
|
6292 |
||
12 | 6293 |
rotated:degrees |
6294 |
"return a new image from the old one, by rotating the image |
|
46 | 6295 |
degrees clockwise. |
592 | 6296 |
CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented." |
12 | 6297 |
|
46 | 6298 |
|w "{Class: SmallInteger }" |
6299 |
h "{Class: SmallInteger }" |
|
12 | 6300 |
c2 "{Class: SmallInteger }" |
692 | 6301 |
r2 "{Class: SmallInteger }" |
6302 |
nW "{Class: SmallInteger }" |
|
6303 |
nH "{Class: SmallInteger }" |
|
24 | 6304 |
newImage newBits newBytesPerRow d| |
12 | 6305 |
|
6306 |
d := degrees. |
|
6307 |
[d < 0] whileTrue:[d := d + 360]. |
|
6308 |
d >= 360 ifTrue:[d := d \\ 360]. |
|
46 | 6309 |
d := d truncated. |
6310 |
d == 0 ifTrue:[^ self]. |
|
6311 |
((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[ |
|
592 | 6312 |
^ self hardRotated:d |
12 | 6313 |
]. |
6314 |
||
692 | 6315 |
d == 180 ifTrue:[ |
6316 |
nW := width. |
|
6317 |
nH := height. |
|
6318 |
] ifFalse:[ |
|
6319 |
nW := height. |
|
6320 |
nH := width. |
|
6321 |
]. |
|
6322 |
||
6323 |
newBytesPerRow := ((nW * self depth) + 7) // 8. |
|
6324 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * nH). |
|
12 | 6325 |
|
6326 |
newImage := self species new. |
|
6327 |
newImage bits:newBits. |
|
692 | 6328 |
newImage width:nW. |
6329 |
newImage height:nH. |
|
12 | 6330 |
newImage photometric:photometric. |
6331 |
newImage samplesPerPixel:samplesPerPixel. |
|
6332 |
newImage bitsPerSample:bitsPerSample. |
|
6333 |
newImage colorMap:colorMap copy. |
|
6334 |
||
6335 |
w := width - 1. |
|
6336 |
h := height - 1. |
|
6337 |
||
6338 |
d == 90 ifTrue:[ |
|
592 | 6339 |
0 to:h do:[:row | |
6340 |
c2 := h-row. |
|
798 | 6341 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6342 |
newImage atX:c2 y:col putValue:pixel. |
592 | 6343 |
] |
692 | 6344 |
"/ 0 to:w do:[:col | |
6345 |
"/ newImage atX:c2 y:col putValue:(self valueAtX:col y:row). |
|
6346 |
"/ ] |
|
592 | 6347 |
] |
12 | 6348 |
]. |
46 | 6349 |
d == 180 ifTrue:[ |
592 | 6350 |
0 to:h do:[:row | |
692 | 6351 |
r2 := h - row. |
798 | 6352 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6353 |
newImage atX:(w-col) y:r2 putValue:pixel. |
592 | 6354 |
] |
692 | 6355 |
"/ 0 to:w do:[:col | |
6356 |
"/ newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row). |
|
6357 |
"/ ] |
|
592 | 6358 |
] |
46 | 6359 |
]. |
12 | 6360 |
d == 270 ifTrue:[ |
592 | 6361 |
0 to:h do:[:row | |
798 | 6362 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 6363 |
newImage atX:row y:(w-col) putValue:pixel. |
592 | 6364 |
] |
692 | 6365 |
"/ 0 to:w do:[:col | |
6366 |
"/ newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row). |
|
6367 |
"/ ] |
|
592 | 6368 |
] |
12 | 6369 |
]. |
6370 |
^ newImage |
|
592 | 6371 |
|
692 | 6372 |
" |
6373 |
|i| |
|
6374 |
||
6375 |
i := Image fromFile:'claus.gif'. |
|
6376 |
i inspect. |
|
6377 |
(i rotated:90) inspect. |
|
6378 |
(i rotated:180) inspect. |
|
6379 |
(i rotated:270) inspect. |
|
6380 |
" |
|
6381 |
||
798 | 6382 |
"Modified: 7.6.1996 / 19:09:22 / cg" |
692 | 6383 |
! |
6384 |
||
6385 |
withPixelFunctionApplied:pixelFunctionBlock |
|
6386 |
"return a new image from the old one, by applying a pixel processor |
|
6387 |
(read `Behond photography, by Gerard J. Holzmann; |
|
6388 |
ISBM 0-13-074410-7) |
|
6389 |
See blurred / oilPointed as examples ...)" |
|
6390 |
||
6391 |
|w "{Class: SmallInteger }" |
|
6392 |
h "{Class: SmallInteger }" |
|
6393 |
newImage newBits newBytesPerRow d| |
|
6394 |
||
6395 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
6396 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
6397 |
||
6398 |
newImage := self species new. |
|
6399 |
newImage bits:newBits. |
|
6400 |
newImage width:width. |
|
6401 |
newImage height:height. |
|
6402 |
newImage photometric:photometric. |
|
6403 |
newImage samplesPerPixel:samplesPerPixel. |
|
6404 |
newImage bitsPerSample:bitsPerSample. |
|
6405 |
newImage colorMap:colorMap copy. |
|
6406 |
||
6407 |
w := width - 1. |
|
6408 |
h := height - 1. |
|
6409 |
||
6410 |
0 to:h do:[:y | |
|
6411 |
0 to:w do:[:x | |
|
6412 |
newImage atX:x y:y put:(pixelFunctionBlock |
|
6413 |
value:self |
|
6414 |
value:x |
|
6415 |
value:y) |
|
6416 |
] |
|
6417 |
]. |
|
6418 |
^ newImage |
|
6419 |
||
6420 |
" |
|
6421 |
|i| |
|
6422 |
||
6423 |
i := Image fromFile:'claus.gif'. |
|
6424 |
i inspect. |
|
6425 |
(i withPixelFunctionApplied:[:oldImage :x :y | |
|
6426 |
((x between:100 and:200) |
|
6427 |
and:[y between:100 and:200]) ifTrue:[ |
|
6428 |
oldImage atX:x y:y |
|
6429 |
] ifFalse:[ |
|
6430 |
Color black. |
|
6431 |
] |
|
6432 |
]) inspect. |
|
6433 |
" |
|
6434 |
||
6435 |
"Modified: 17.5.1996 / 12:31:44 / cg" |
|
283 | 6436 |
! ! |
6437 |
||
6438 |
!Image methodsFor:'inspecting'! |
|
6439 |
||
6440 |
inspectorClass |
|
6441 |
"redefined to launch an ImageInspector |
|
6442 |
(instead of the default InspectorView)." |
|
6443 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6444 |
(width notNil and:[height notNil]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6445 |
^ ImageInspectorView |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6446 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6447 |
^ super inspectorClass |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6448 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6449 |
"Modified: 10.6.1996 / 18:23:55 / cg" |
283 | 6450 |
! ! |
6451 |
||
6452 |
!Image methodsFor:'instance release'! |
|
6453 |
||
6454 |
disposed |
|
6455 |
"some Image has been collected - nothing to do" |
|
12 | 6456 |
! |
6457 |
||
283 | 6458 |
release |
6459 |
"release device resources" |
|
6460 |
||
6461 |
device := nil. |
|
6462 |
deviceForm := nil. |
|
6463 |
monoDeviceForm := nil. |
|
6464 |
fullColorDeviceForm := nil. |
|
6465 |
Lobby unregister:self |
|
46 | 6466 |
! |
6467 |
||
283 | 6468 |
restored |
6469 |
"flush device specifics after a snapin or binary restore" |
|
6470 |
||
6471 |
self release |
|
6472 |
! ! |
|
6473 |
||
592 | 6474 |
!Image methodsFor:'obsolete'! |
6475 |
||
6476 |
magnifyBy:scale |
|
6477 |
"obsolete: has been renamed to magnifiedBy: for ST-80 compatibility |
|
6478 |
and name consistency ..." |
|
6479 |
||
6480 |
self obsoleteMethodWarning. |
|
6481 |
^ self magnifiedBy:scale |
|
6482 |
! ! |
|
6483 |
||
283 | 6484 |
!Image methodsFor:'pixel copying'! |
6485 |
||
6486 |
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
6487 |
"replace a rectangulat area by pixels from another image. |
|
6488 |
WARNING: |
|
6489 |
This implementation is a slow fallback (the loop over the |
|
6490 |
source pixels is very slow). If this method is used heavily, you |
|
6491 |
may want to redefine it in concrete subclasses for the common case of |
|
6492 |
of copying from an Image with the same depth & palette." |
|
6493 |
||
6494 |
|dX dY| |
|
6495 |
||
6496 |
dX := srcX-dstX. |
|
6497 |
dY := srcY-dstY. |
|
6498 |
((photometric == anImage photometric) |
|
6499 |
and:[self bitsPerPixel == anImage bitsPerPixel |
|
6500 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
|
6501 |
"/ can loop over values |
|
6502 |
anImage valuesFromX:srcX y:srcY |
|
6503 |
toX:srcX+w-1 y:srcY+h-1 |
|
6504 |
do:[:x :y :pixelValue | |
|
6505 |
self atX:x-dX y:y-dY putValue:pixelValue. |
|
6506 |
] |
|
6507 |
] ifFalse:[ |
|
6508 |
"/ must loop over colors |
|
6509 |
anImage colorsFromX:srcX y:srcY |
|
6510 |
toX:srcX+w-1 y:srcY+h-1 |
|
6511 |
do:[:x :y :clr | |
|
6512 |
self atX:x-dX y:y-dY put:clr. |
|
6513 |
] |
|
6514 |
] |
|
6515 |
||
6516 |
" |
|
6517 |
|i1 i8 i4| |
|
6518 |
||
6519 |
i8 := Image fromFile:'bitmaps/garfield.gif'. |
|
6520 |
i8 inspect. |
|
6521 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
6522 |
i1 inspect. |
|
6523 |
||
6524 |
i4 := Depth4Image fromImage:i8. |
|
6525 |
i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30. |
|
6526 |
i4 inspect. |
|
6527 |
" |
|
6528 |
||
6529 |
"Created: 20.9.1995 / 10:14:01 / claus" |
|
6530 |
"Modified: 20.9.1995 / 10:25:31 / claus" |
|
6531 |
! |
|
6532 |
||
6533 |
subImageIn:aRectangle |
|
6534 |
"create and return a new image consisting of a subArea of myself" |
|
6535 |
||
6536 |
^ self class fromSubImage:self in:aRectangle |
|
6537 |
||
6538 |
" |
|
6539 |
|i| |
|
6540 |
||
6541 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
6542 |
i inspect. |
|
6543 |
(i subImageIn:(300@160 corner:340@200)) inspect |
|
6544 |
" |
|
6545 |
||
6546 |
"Created: 20.9.1995 / 01:24:20 / claus" |
|
6547 |
! ! |
|
6548 |
||
6549 |
!Image methodsFor:'printing & storing'! |
|
6550 |
||
6551 |
storeOn:aStream |
|
592 | 6552 |
"append a printed representation of the receiver to aStream, |
6553 |
from which a copy of it can be reconstructed." |
|
6554 |
||
283 | 6555 |
aStream nextPutAll:'(' , self class name , ' new)'. |
6556 |
aStream nextPutAll:' width: '. width storeOn:aStream. |
|
6557 |
aStream nextPutAll:'; height: '. height storeOn:aStream. |
|
6558 |
aStream nextPutAll:'; photometric:('. photometric storeOn:aStream. |
|
6559 |
aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream. |
|
6560 |
aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. |
|
6561 |
aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '. |
|
6562 |
colorMap notNil ifTrue:[ |
|
592 | 6563 |
aStream nextPutAll:'; colorMap:('. |
6564 |
colorMap storeOn:aStream. |
|
6565 |
aStream nextPutAll:')'. |
|
283 | 6566 |
]. |
6567 |
aStream nextPutAll:'; yourself' |
|
592 | 6568 |
|
6569 |
"Modified: 23.4.1996 / 11:18:05 / cg" |
|
0 | 6570 |
! ! |
6571 |
||
6572 |
!Image methodsFor:'private'! |
|
6573 |
||
193 | 6574 |
bestSupportedImageFormatFor:aDevice |
6575 |
"scan through the image formats as supported by aDevice, |
|
6576 |
and return the best to use when the receiver is to be represented |
|
6577 |
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
|
6578 |
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
|
6579 |
|
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6580 |
|bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel | |
193 | 6581 |
|
6582 |
myDepth := self bitsPerPixel. |
|
6583 |
maxBitsPerPixel := 0. |
|
6584 |
||
6585 |
aDevice supportedImageFormats do:[:entry | |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6586 |
|deviceImageDepth deviceImageBitsPerPixel| |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6587 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6588 |
deviceImageDepth := entry at:#depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6589 |
deviceImageBitsPerPixel := entry at:#bitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6590 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6591 |
deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6592 |
maxInfo := entry. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6593 |
"/ maxBitsPerPixel := deviceImageBitsPerPixel. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6594 |
"/ maxDepth := deviceImageDepth. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6595 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6596 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6597 |
deviceImageDepth >= myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6598 |
deviceImageDepth == myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6599 |
"/ take the better one ... |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6600 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6601 |
or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth) |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6602 |
and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6603 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6604 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6605 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6606 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6607 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6608 |
"/ take the next-larger depth |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6609 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6610 |
or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6611 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6612 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6613 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6614 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6615 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6616 |
]. |
193 | 6617 |
]. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6618 |
|
193 | 6619 |
bestDeviceDepth isNil ifTrue:[ |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6620 |
maxBitsPerPixel == 0 ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6621 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6622 |
"/ oops - nothing appropriate |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6623 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6624 |
maxInfo notNil ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6625 |
^ maxInfo |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6626 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6627 |
bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6628 |
bestInfo := IdentityDictionary new. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6629 |
bestInfo at:#depth put:bestDeviceDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6630 |
bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6631 |
bestInfo at:#padding put:32. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6632 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6633 |
bestInfo := maxInfo. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6634 |
] |
193 | 6635 |
]. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6636 |
^ bestInfo |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
6637 |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
6638 |
"Modified: 14.6.1996 / 14:46:40 / cg" |
283 | 6639 |
! |
6640 |
||
6641 |
colormapFromImage:anImage |
|
6642 |
"setup the receivers colormap from another image. |
|
6643 |
Color precision may be lost, if conversion is from a higher depth |
|
6644 |
image. This does not convert any pixel values; it is non-public helper |
|
6645 |
for fromImage:/fromSubImake:" |
|
6646 |
||
6647 |
samplesPerPixel == 3 ifTrue:[ |
|
6648 |
photometric := #rgb |
|
6649 |
] ifFalse:[ |
|
6650 |
photometric := anImage photometric. |
|
6651 |
photometric == #palette ifTrue:[ |
|
6652 |
colorMap := anImage colorMap copy. |
|
6653 |
" |
|
6654 |
must compress the colormap, if source image has higher depth |
|
6655 |
than myself. |
|
6656 |
" |
|
6657 |
anImage bitsPerPixel > self bitsPerPixel ifTrue:[ |
|
6658 |
" |
|
6659 |
get used colors are extracted into our colorMap |
|
6660 |
(the at-put below will set the pixelValue according the |
|
6661 |
new colorIndex |
|
6662 |
" |
|
6663 |
colorMap := anImage usedColors asArray. |
|
6664 |
colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[ |
|
6665 |
'IMAGE: possibly too many colors in image' errorPrintNL |
|
6666 |
] |
|
6667 |
] |
|
6668 |
] |
|
6669 |
]. |
|
6670 |
||
6671 |
"Created: 20.9.1995 / 00:58:42 / claus" |
|
6672 |
! |
|
6673 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6674 |
greyByteMapForRange:range |
798 | 6675 |
"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
|
6676 |
in the range 0..range. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6677 |
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
|
6678 |
The values are rounded towards the nearest pixel." |
798 | 6679 |
|
808 | 6680 |
|d n greyMap r| |
6681 |
||
6682 |
r := range. |
|
6683 |
r == 256 ifTrue:[ |
|
6684 |
r := 255 |
|
798 | 6685 |
]. |
6686 |
||
6687 |
photometric == #palette ifTrue:[ |
|
808 | 6688 |
n := colorMap size. |
6689 |
greyMap := ByteArray new:n. |
|
6690 |
||
6691 |
1 to:n do:[:i | |
|
6692 |
greyMap at:i put:(r * (colorMap at:i) brightness) rounded |
|
798 | 6693 |
]. |
6694 |
] ifFalse:[ |
|
808 | 6695 |
d := self bitsPerPixel. |
6696 |
n := 1 bitShift:d. |
|
6697 |
n >= 4096 ifTrue:[ |
|
6698 |
self error:'size not supported - too large'. |
|
6699 |
^ nil |
|
6700 |
]. |
|
6701 |
greyMap := ByteArray new:n. |
|
6702 |
||
6703 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6704 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6705 |
1 to:n do:[:i | |
808 | 6706 |
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
|
6707 |
]. |
798 | 6708 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6709 |
1 to:n do:[:i | |
808 | 6710 |
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
|
6711 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6712 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6713 |
"/ we are done |
798 | 6714 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6715 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6716 |
greyMap reverse |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6717 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6718 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6719 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6720 |
] |
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 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6723 |
]. |
808 | 6724 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6725 |
^ greyMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6726 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6727 |
" |
808 | 6728 |
Depth8Image new greyByteMapForRange:256 |
6729 |
||
6730 |
Depth8Image new greyByteMapForRange:64 |
|
6731 |
Depth4Image new greyByteMapForRange:64 |
|
6732 |
||
6733 |
Depth4Image new greyByteMapForRange:1 |
|
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 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6736 |
"Created: 8.6.1996 / 08:34:14 / cg" |
808 | 6737 |
"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
|
6738 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6739 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6740 |
greyMapForRange:range |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6741 |
"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
|
6742 |
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
|
6743 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6744 |
|d r |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6745 |
n "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6746 |
greyArray| |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6747 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6748 |
d := self bitsPerPixel. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6749 |
n := 1 bitShift:d. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6750 |
n >= 4096 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6751 |
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
|
6752 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6753 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6754 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6755 |
greyArray := Array new:n. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6756 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6757 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6758 |
1 to:(colorMap size) do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6759 |
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
|
6760 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6761 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6762 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6763 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6764 |
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
|
6765 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6766 |
] ifFalse:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6767 |
r := range asFloat. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6768 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6769 |
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
|
6770 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6771 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6772 |
"/ we are done |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6773 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6774 |
photometric == #whiteIs0 ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6775 |
greyArray reverse |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6776 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6777 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6778 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6779 |
] |
798 | 6780 |
] |
6781 |
] |
|
6782 |
]. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6783 |
^ greyArray |
798 | 6784 |
|
6785 |
" |
|
6786 |
Depth8Image new greyMapForRange:64 |
|
6787 |
Depth4Image new greyMapForRange:64 |
|
6788 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6789 |
Depth16Image new greyMapForRange:1 |
798 | 6790 |
Depth4Image new greyMapForRange:1 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6791 |
Depth2Image new greyMapForRange:1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6792 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6793 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6794 |
"Modified: 10.6.1996 / 10:37:40 / cg" |
798 | 6795 |
! |
6796 |
||
283 | 6797 |
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels |
6798 |
into:dstBytes offset:dstStart factor:mX |
|
6799 |
||
6800 |
"magnify a single pixel row - can only magnify by integer factors, |
|
6801 |
can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast." |
|
6802 |
||
6803 |
^ self subclassResponsibility |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6804 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6805 |
|
816 | 6806 |
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
6807 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6808 |
pixels interpreted as greyValues, 0 is black, |
|
6809 |
create a device form for it" |
|
6810 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6811 |
|f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6812 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6813 |
f := Form width:width height:height depth:depth on:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6814 |
f isNil ifTrue:[^ nil]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6815 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6816 |
f bits:bits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6817 |
f initGC. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6818 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6819 |
(aDevice blackpixel ~~ 0) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6820 |
"/ have to invert bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6821 |
f function:#copyInverted |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6822 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6823 |
aDevice drawBits:bits depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6824 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6825 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6826 |
into:(f id) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6827 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6828 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6829 |
with:(f gcId). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6830 |
^ f |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6831 |
|
816 | 6832 |
"Created: 10.6.1996 / 20:10:31 / cg" |
6833 |
! |
|
6834 |
||
6835 |
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
6836 |
"given the bits of a monochrome bitmap, 8-bit padded and |
|
6837 |
0-bits as black, create a device form for it" |
|
6838 |
||
6839 |
monoBits invert. |
|
6840 |
^ (Form width:width height:height fromArray:monoBits on:aDevice) |
|
6841 |
colorMap:(Array with:Color black with:Color white). |
|
6842 |
||
6843 |
"Created: 10.6.1996 / 20:18:09 / cg" |
|
6844 |
"Modified: 10.6.1996 / 20:31:24 / cg" |
|
6845 |
! |
|
6846 |
||
6847 |
makeDevicePixmapOn:aDevice depth:depth fromArray:bits |
|
6848 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
6849 |
pixels interpreted as in the devices colormap, |
|
6850 |
create a device form for it" |
|
6851 |
||
6852 |
|f| |
|
6853 |
||
6854 |
f := Form width:width height:height depth:depth on:aDevice. |
|
6855 |
f isNil ifTrue:[^ nil]. |
|
6856 |
||
6857 |
f bits:bits. |
|
6858 |
f initGC. |
|
6859 |
||
6860 |
aDevice drawBits:bits depth:depth |
|
6861 |
width:width height:height |
|
6862 |
x:0 y:0 |
|
6863 |
into:(f id) |
|
6864 |
x:0 y:0 |
|
6865 |
width:width height:height |
|
6866 |
with:(f gcId). |
|
6867 |
^ f |
|
6868 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
6869 |
"Created: 10.6.1996 / 17:56:08 / cg" |
816 | 6870 |
"Modified: 10.6.1996 / 20:11:27 / cg" |
2 | 6871 |
! ! |
0 | 6872 |
|
283 | 6873 |
!Image methodsFor:'queries'! |
6874 |
||
6875 |
averageColor |
|
6876 |
"return the average color of the image. |
|
6877 |
This usually only makes sense for textures and patterns |
|
6878 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
6879 |
Notice, that for the above purpose, it is usually ok to process |
|
6880 |
a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle" |
|
6881 |
||
6882 |
^ self averageColorIn:(0@0 corner:(width-1)@(height-1)) |
|
6883 |
! |
|
6884 |
||
6885 |
averageColorIn:aRectangle |
|
6886 |
"return the images average color in an area. |
|
6887 |
The implementation below is slow - so you may want to |
|
6888 |
create tuned versions for DepthXImage if you plan to do |
|
6889 |
heavy image processing ... |
|
6890 |
(also, creating tuned versions of the enumeration messages helps a lot)" |
|
6891 |
||
6892 |
|x0 "{ Class:SmallInteger }" |
|
6893 |
y0 "{ Class:SmallInteger }" |
|
6894 |
x1 "{ Class:SmallInteger }" |
|
6895 |
y1 "{ Class:SmallInteger }" |
|
6896 |
sumRed sumGreen sumBlue n| |
|
6897 |
||
6898 |
sumRed := sumGreen := sumBlue := 0. |
|
6899 |
y0 := aRectangle top. |
|
6900 |
y1 := aRectangle bottom. |
|
6901 |
x0 := aRectangle left. |
|
6902 |
x1 := aRectangle right. |
|
6903 |
||
6904 |
self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY | |
|
6905 |
sumRed := sumRed + colorAtXY red. |
|
6906 |
sumGreen := sumGreen + colorAtXY green. |
|
6907 |
sumBlue := sumBlue + colorAtXY blue. |
|
6908 |
]. |
|
6909 |
n := (x1 - x0 + 1) * (y1 - y0 + 1). |
|
6910 |
^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n) |
|
6911 |
! |
|
6912 |
||
6913 |
bitsPerPixel |
|
6914 |
"return the number of bits per pixel" |
|
6915 |
||
6916 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
|
6917 |
! |
|
6918 |
||
6919 |
bitsPerRow |
|
6920 |
"return the number of bits in one scanline of the image" |
|
6921 |
||
6922 |
^ width * (self bitsPerPixel). |
|
6923 |
! |
|
6924 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6925 |
blueBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6926 |
"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
|
6927 |
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
|
6928 |
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
|
6929 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6930 |
|blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6931 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6932 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6933 |
"/ 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
|
6934 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6935 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6936 |
blueBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6937 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6938 |
^ pixel bitAnd:(1 bitShift:blueBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6939 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6940 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6941 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6942 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6943 |
"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
|
6944 |
"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
|
6945 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6946 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6947 |
blueComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6948 |
"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
|
6949 |
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
|
6950 |
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
|
6951 |
|
854 | 6952 |
|blueBits "{ Class: SmallInteger }" |
6953 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6954 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6955 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6956 |
"/ 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
|
6957 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6958 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6959 |
blueBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6960 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6961 |
s := (1 bitShift:blueBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6962 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6963 |
^ 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
|
6964 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6965 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6966 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6967 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6968 |
"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
|
6969 |
"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
|
6970 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6971 |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6972 |
bounds |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6973 |
"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
|
6974 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6975 |
^ 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
|
6976 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6977 |
"Created: 13.5.1996 / 10:27:06 / cg" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6978 |
! |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
6979 |
|
283 | 6980 |
brightness |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6981 |
"return the (average) brightness of the image. |
283 | 6982 |
This usually only makes sense for textures and patterns |
6983 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
6984 |
Notice, that for the above purpose, only a subimage is inspected here" |
|
6985 |
||
6986 |
^ (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
|
6987 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
6988 |
"Modified: 8.6.1996 / 08:46:46 / cg" |
283 | 6989 |
! |
6990 |
||
6991 |
bytesPerRow |
|
6992 |
"return the number of bytes in one scanline of the image" |
|
6993 |
||
6994 |
|bitsPerRow bytesPerRow| |
|
6995 |
||
6996 |
bitsPerRow := width * (self bitsPerPixel). |
|
6997 |
bytesPerRow := bitsPerRow // 8. |
|
6998 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
6999 |
bytesPerRow := bytesPerRow + 1 |
|
7000 |
]. |
|
7001 |
^ bytesPerRow |
|
7002 |
! |
|
7003 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7004 |
colorFromValue:pixelValue |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7005 |
"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
|
7006 |
Pixel values start with 0." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7007 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7008 |
|maxPixel r g b| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7009 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7010 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7011 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7012 |
^ Color gray:(pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7013 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7014 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7015 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7016 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7017 |
^ Color gray:100 - (pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7018 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7019 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7020 |
photometric == #palette ifTrue:[ |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7021 |
pixelValue >= colorMap size ifTrue:[ |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7022 |
^ Color black |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7023 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7024 |
^ colorMap at:(pixelValue + 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7025 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7026 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7027 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7028 |
r := self redComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7029 |
g := self greenComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7030 |
b := self blueComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7031 |
^ 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
|
7032 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7033 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7034 |
self error:'invalid photometric' |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7035 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7036 |
"Created: 8.6.1996 / 08:46:18 / cg" |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
7037 |
"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
|
7038 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7039 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7040 |
greenBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7041 |
"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
|
7042 |
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
|
7043 |
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
|
7044 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7045 |
|blueBits greenBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7046 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7047 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7048 |
"/ 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
|
7049 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7050 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7051 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7052 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7053 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7054 |
^ (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
|
7055 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7056 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7057 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7058 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7059 |
"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
|
7060 |
"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
|
7061 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7062 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7063 |
greenComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7064 |
"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
|
7065 |
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
|
7066 |
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
|
7067 |
|
854 | 7068 |
|greenBits "{ Class: SmallInteger }" |
7069 |
blueBits "{ Class: SmallInteger }" |
|
7070 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7071 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7072 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7073 |
"/ 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
|
7074 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7075 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7076 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7077 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7078 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7079 |
s := (1 bitShift:greenBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7080 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7081 |
^ 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
|
7082 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7083 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7084 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7085 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7086 |
"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
|
7087 |
"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
|
7088 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7089 |
|
674 | 7090 |
heightOn:aGC |
7091 |
"return my height, if displayed on aGC; |
|
7092 |
since my height is independent of the device (the number of pixels), |
|
7093 |
return the pixel-height" |
|
7094 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7095 |
^ height |
674 | 7096 |
|
7097 |
"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
|
7098 |
"Modified: 13.5.1996 / 10:26:36 / cg" |
674 | 7099 |
! |
7100 |
||
283 | 7101 |
isImage |
7102 |
"return true, if the receiver is some kind of image; |
|
7103 |
true is returned here - the method is redefined from Object." |
|
7104 |
||
7105 |
^ true |
|
7106 |
! |
|
7107 |
||
7108 |
isImageOrForm |
|
7109 |
"return true, if the receiver is some kind of image or form; |
|
7110 |
true is returned here - the method is redefined from Object." |
|
7111 |
||
7112 |
^ true |
|
7113 |
! |
|
7114 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7115 |
redBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7116 |
"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
|
7117 |
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
|
7118 |
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
|
7119 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7120 |
|redBits greenBits blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7121 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7122 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7123 |
"/ 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
|
7124 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7125 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7126 |
redBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7127 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7128 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7129 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7130 |
^ (pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7131 |
bitAnd:(1 bitShift:redBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7132 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7133 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7134 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7135 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7136 |
"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
|
7137 |
"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
|
7138 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7139 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7140 |
redComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7141 |
"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
|
7142 |
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
|
7143 |
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
|
7144 |
|
854 | 7145 |
|redBits "{ Class: SmallInteger }" |
7146 |
greenBits "{ Class: SmallInteger }" |
|
7147 |
blueBits "{ Class: SmallInteger }" |
|
7148 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7149 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7150 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7151 |
"/ 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
|
7152 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7153 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7154 |
redBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7155 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7156 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7157 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7158 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7159 |
s := (1 bitShift:redBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7160 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7161 |
^ 100.0 / s * |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7162 |
((pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7163 |
bitAnd:(1 bitShift:redBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7164 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7165 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7166 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7167 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7168 |
"Created: 8.6.1996 / 08:45:30 / cg" |
854 | 7169 |
"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
|
7170 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7171 |
|
283 | 7172 |
usedColors |
7173 |
"return a collection of colors used in the receiver." |
|
7174 |
||
7175 |
|usedValues max| |
|
7176 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7177 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7178 |
"/ 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
|
7179 |
"/ 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
|
7180 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7181 |
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
|
7182 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7183 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7184 |
|
283 | 7185 |
usedValues := self usedValues asArray. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7186 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7187 |
^ usedValues collect:[:val | (colorMap at:val+1)] |
283 | 7188 |
]. |
7189 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7190 |
"/ (photometric == #blackIs0 or:[photometric == #whiteIs0]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7191 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7192 |
max := (1 bitShift:self depth) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7193 |
^ usedValues collect:[:val | (Color gray:(100 * val / max ))] |
283 | 7194 |
|
7195 |
" |
|
7196 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
7197 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
7198 |
(Image fromFile:'ttt.tiff') usedColors |
|
7199 |
" |
|
746 | 7200 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
7201 |
"Modified: 8.6.1996 / 09:04:56 / cg" |
283 | 7202 |
! |
7203 |
||
7204 |
usedValues |
|
7205 |
"return a collection of color values used in the receiver. |
|
7206 |
Notice, that the interpretation of the pixels depends on the photometric |
|
7207 |
of the image. |
|
7208 |
This is a general and therefore slow implementation; subclasses |
|
7209 |
may want to redefine this method for more performance." |
|
7210 |
||
7211 |
|set| |
|
7212 |
||
7213 |
set := IdentitySet new. |
|
7214 |
self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel | |
|
7215 |
set add:pixel |
|
7216 |
]. |
|
7217 |
^ set |
|
7218 |
||
7219 |
" |
|
7220 |
(Image fromFile:'bitmaps/garfield.gif') usedValues |
|
7221 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedValues |
|
7222 |
(Image fromFile:'ttt.tiff') usedValues |
|
7223 |
" |
|
674 | 7224 |
! |
7225 |
||
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7226 |
valueFromColor:color |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7227 |
"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
|
7228 |
Non-representable colors return nil." |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7229 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7230 |
|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
|
7231 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7232 |
photometric == #whiteIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7233 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7234 |
^ maxPixel - (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7235 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7236 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7237 |
photometric == #blackIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7238 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7239 |
^ (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7240 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7241 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7242 |
photometric == #palette ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7243 |
pixel := colorMap indexOf:color. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7244 |
pixel == 0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7245 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7246 |
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
|
7247 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7248 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7249 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7250 |
^ pixel - 1 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7251 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7252 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7253 |
photometric == #rgb ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7254 |
samplesPerPixel >= 3 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7255 |
redBits := bitsPerSample at:1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7256 |
greenBits := bitsPerSample at:2. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7257 |
blueBits := bitsPerSample at:3. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7258 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7259 |
"/ map r/g/b to 0..255 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7260 |
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
|
7261 |
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
|
7262 |
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
|
7263 |
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
|
7264 |
^ pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7265 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7266 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7267 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7268 |
self error:'format not supported'. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7269 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7270 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7271 |
"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
|
7272 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7273 |
|
674 | 7274 |
widthOn:aGC |
7275 |
"return my width, if displayed on aGC; |
|
7276 |
since my width is independent of the device (the number of pixels), |
|
7277 |
return the pixel-width" |
|
7278 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
7279 |
^ width |
674 | 7280 |
|
7281 |
"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
|
7282 |
"Modified: 13.5.1996 / 10:26:42 / cg" |
283 | 7283 |
! ! |
7284 |
||
7285 |
!Image methodsFor:'saving on file'! |
|
7286 |
||
7287 |
saveOn:aFileName |
|
7288 |
"save the image in a aFileName. The suffix of the filename |
|
7289 |
controls the format. Currently, not all formats may be supported |
|
7290 |
(see ImageReader subclasses implementing save:onFile:)" |
|
7291 |
||
7292 |
" |
|
7293 |
from the extension, get the imageReader class |
|
7294 |
(which should know how to write images as well) |
|
7295 |
" |
|
7296 |
FileFormats associationsDo:[:a | |
|
7297 |
(aFileName endsWith:(a key)) ifTrue:[ |
|
7298 |
^ (a value) save:self onFile:aFileName |
|
7299 |
] |
|
7300 |
]. |
|
7301 |
||
7302 |
" |
|
7303 |
no known extension - could ask user for the format here. |
|
7304 |
currently default to tiff format. |
|
7305 |
" |
|
7306 |
'IMAGE: unknown extension - cannot figure out format - using tiff' errorPrintNL. |
|
7307 |
^ self saveOn:aFileName using:TIFFReader |
|
89 | 7308 |
! |
7309 |
||
283 | 7310 |
saveOn:aFileName using:readerClass |
7311 |
"save the receiver using the representation class" |
|
7312 |
||
7313 |
readerClass save:self onFile:aFileName |
|
7314 |
||
7315 |
" |
|
7316 |
anImage saveOn:'myImage' using:TIFFReader |
|
7317 |
anImage saveOn:'myImage' using:XBMReader |
|
7318 |
" |
|
0 | 7319 |
! ! |
283 | 7320 |
|
7321 |
!Image methodsFor:'screen capture'! |
|
7322 |
||
7323 |
fromScreen:aRectangle |
|
7324 |
"read an image from the display screen" |
|
7325 |
||
7326 |
^ self fromScreen:aRectangle on:Screen current |
|
7327 |
! |
|
7328 |
||
7329 |
fromScreen:aRectangle on:aDevice |
|
7330 |
"read an image from aDevices display screen. |
|
7331 |
Since I have no other displays, only the MonoChrome, StaticGrey |
|
7332 |
and PseudoColor cases have been tested ... |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7333 |
(especially True- and DirectColor may be wrong). |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7334 |
Late note: 24bit rgb now also works." |
283 | 7335 |
|
7336 |
|depth visType |
|
7337 |
x "{ Class: SmallInteger }" |
|
7338 |
y "{ Class: SmallInteger }" |
|
7339 |
w "{ Class: SmallInteger }" |
|
7340 |
h "{ Class: SmallInteger }" |
|
7341 |
dstIndex "{ Class: SmallInteger }" |
|
7342 |
srcIndex "{ Class: SmallInteger }" |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7343 |
srcRow "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7344 |
dstRow "{ Class: SmallInteger }" |
283 | 7345 |
inData tmpData usedPixels mapSize |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7346 |
map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7347 |
info bitsPerPixelIn bytesPerLineIn curs cid rootView |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7348 |
maskR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7349 |
maskG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7350 |
maskB "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7351 |
shR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7352 |
shG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7353 |
shB "{ Class: SmallInteger }" |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7354 |
shR2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7355 |
shG2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7356 |
shB2 "{ Class: SmallInteger }" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7357 |
r "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7358 |
g "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7359 |
b "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7360 |
word| |
283 | 7361 |
|
7362 |
curs := Cursor sourceForm:(Form fromFile:'Camera.xbm') |
|
518 | 7363 |
maskForm:(Form fromFile:'Camera_m.xbm') |
7364 |
hotSpot:16@16. |
|
283 | 7365 |
curs notNil ifTrue:[ |
518 | 7366 |
cid := (curs on:aDevice) id |
283 | 7367 |
]. |
7368 |
||
7369 |
" |
|
7370 |
get some attributes of the display device |
|
7371 |
" |
|
7372 |
visType := aDevice visualType. |
|
7373 |
depth := aDevice depth. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7374 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7375 |
"/ kludge for 15bit XFree server |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7376 |
depth == 15 ifTrue:[ |
518 | 7377 |
depth := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7378 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7379 |
|
283 | 7380 |
(visType == #StaticGray) ifTrue:[ |
518 | 7381 |
(aDevice blackpixel == 0) ifTrue:[ |
7382 |
photometric := #blackIs0 |
|
7383 |
] ifFalse:[ |
|
7384 |
photometric := #whiteIs0 |
|
7385 |
]. |
|
7386 |
samplesPerPixel := 1. |
|
7387 |
bitsPerPixel := depth. |
|
7388 |
bitsPerSample := Array with:bitsPerPixel. |
|
283 | 7389 |
] ifFalse:[ |
518 | 7390 |
((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[ |
7391 |
photometric := #palette. |
|
7392 |
samplesPerPixel := 1. |
|
7393 |
bitsPerPixel := depth. |
|
7394 |
bitsPerSample := Array with:bitsPerPixel. |
|
7395 |
] ifFalse:[ |
|
7396 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
7397 |
photometric := #rgb. |
|
7398 |
samplesPerPixel := 3. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7399 |
"/ bitsPerPixel := depth. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7400 |
"/ 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
|
7401 |
"/ with:aDevice bitsGreen |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7402 |
"/ with:aDevice bitsBlue |
518 | 7403 |
bitsPerPixel := 24. |
7404 |
bitsPerSample := #(8 8 8). |
|
7405 |
] ifFalse:[ |
|
7406 |
self error:'screen visual not supported'. |
|
7407 |
^ nil |
|
7408 |
] |
|
7409 |
] |
|
283 | 7410 |
]. |
7411 |
||
7412 |
" |
|
7413 |
dont know yet, how the display pads; assume worst case, |
|
7414 |
offering enough space for 32 bit padding |
|
7415 |
" |
|
7416 |
w := width := aRectangle width. |
|
7417 |
h := height := aRectangle height. |
|
7418 |
x := aRectangle left. |
|
7419 |
y := aRectangle top. |
|
7420 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7421 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7422 |
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
|
7423 |
(its too late when info is present ...) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7424 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7425 |
spaceBitsPerPixel := bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7426 |
(bitsPerPixel > 8) ifTrue:[ |
518 | 7427 |
spaceBitsPerPixel := 16. |
7428 |
(bitsPerPixel > 16) ifTrue:[ |
|
7429 |
spaceBitsPerPixel := 32. |
|
7430 |
(bitsPerPixel > 32) ifTrue:[ |
|
7431 |
spaceBitsPerPixel := bitsPerPixel. |
|
7432 |
] |
|
7433 |
] |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7434 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7435 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7436 |
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4. |
283 | 7437 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
7438 |
||
7439 |
" |
|
7440 |
actually have to grabServer ... but thats not yet available |
|
7441 |
" |
|
728 | 7442 |
rootView := aDevice rootView. |
283 | 7443 |
aDevice setActivePointerGrab:rootView. |
7444 |
aDevice grabPointerIn:rootView id |
|
518 | 7445 |
withCursor:cid pointerMode:#async keyboardMode:#sync confineTo:nil. |
283 | 7446 |
|
7447 |
" |
|
7448 |
get the pixels |
|
7449 |
" |
|
7450 |
info := aDevice getBitsFrom:rootView id x:x y:y width:w height:h into:inData. |
|
7451 |
||
7452 |
" |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7453 |
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
|
7454 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7455 |
byteOrder := info at:#byteOrder. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7456 |
bitsPerPixelIn := info at:#bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7457 |
byteOrder ~~ #msbFirst ifTrue:[ |
518 | 7458 |
bitsPerPixelIn == 16 ifTrue:[ |
7459 |
"/ must swap bytes |
|
7460 |
inData swapBytes |
|
7461 |
] ifFalse:[ |
|
7462 |
bitsPerPixelIn == 32 ifTrue:[ |
|
7463 |
"/ must swap longs |
|
7464 |
inData swapLongs |
|
7465 |
] |
|
7466 |
] |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7467 |
]. |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7468 |
|
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
7469 |
" |
283 | 7470 |
check, if the devices padding is different .. |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7471 |
or if the bitsPerPixels are different |
283 | 7472 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7473 |
bytesPerLineIn := (info at:#bytesPerLine). "what I got" |
283 | 7474 |
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
|
7475 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7476 |
((bytesPerLine ~~ bytesPerLineIn) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7477 |
or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[ |
518 | 7478 |
tmpData := inData. |
7479 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
7480 |
||
7481 |
srcRow := 1. |
|
7482 |
dstRow := 1. |
|
7483 |
||
7484 |
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[ |
|
7485 |
"/ for now, only 32 -> 24 is supported |
|
7486 |
||
7487 |
maskR := (1 bitShift:aDevice bitsRed) - 1. |
|
7488 |
maskG := (1 bitShift:aDevice bitsGreen) - 1. |
|
7489 |
maskB := (1 bitShift:aDevice bitsBlue) - 1. |
|
7490 |
shR := aDevice shiftRed negated. |
|
7491 |
shG := aDevice shiftGreen negated. |
|
7492 |
shB := aDevice shiftBlue negated. |
|
7493 |
shR2 := (8 - aDevice bitsRed). |
|
7494 |
shG2 := (8 - aDevice bitsGreen). |
|
7495 |
shB2 := (8 - aDevice bitsBlue). |
|
7496 |
||
7497 |
((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[ |
|
7498 |
"/ 'reformatting 32->24...' printNL. |
|
7499 |
1 to:h do:[:hi | |
|
7500 |
srcIndex := srcRow. |
|
7501 |
dstIndex := dstRow. |
|
7502 |
||
7503 |
1 to:w do:[:wi | |
|
7504 |
word := tmpData doubleWordAt:srcIndex MSB:true. |
|
7505 |
r := (word bitShift:shR) bitAnd:maskR. |
|
7506 |
g := (word bitShift:shG) bitAnd:maskG. |
|
7507 |
b := (word bitShift:shB) bitAnd:maskB. |
|
7508 |
||
7509 |
inData at:dstIndex put:r. |
|
7510 |
inData at:dstIndex+1 put:g. |
|
7511 |
inData at:dstIndex+2 put:b. |
|
7512 |
srcIndex := srcIndex + 4. |
|
7513 |
dstIndex := dstIndex + 3. |
|
7514 |
]. |
|
7515 |
dstRow := dstRow + bytesPerLine. |
|
7516 |
srcRow := srcRow + bytesPerLineIn |
|
7517 |
] |
|
7518 |
] ifFalse:[ |
|
7519 |
((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[ |
|
7520 |
"/ 'reformatting 16->24...' printNL. |
|
7521 |
1 to:h do:[:hi | |
|
7522 |
srcIndex := srcRow. |
|
7523 |
dstIndex := dstRow. |
|
7524 |
||
7525 |
1 to:w do:[:wi | |
|
7526 |
word := tmpData wordAt:srcIndex MSB:true. |
|
7527 |
r := (word bitShift:shR) bitAnd:maskR. |
|
7528 |
g := (word bitShift:shG) bitAnd:maskG. |
|
7529 |
b := (word bitShift:shB) bitAnd:maskB. |
|
7530 |
||
7531 |
inData at:dstIndex put:(r bitShift:shR2). |
|
7532 |
inData at:dstIndex+1 put:(g bitShift:shG2). |
|
7533 |
inData at:dstIndex+2 put:(b bitShift:shB2). |
|
7534 |
srcIndex := srcIndex + 2. |
|
7535 |
dstIndex := dstIndex + 3. |
|
7536 |
]. |
|
7537 |
dstRow := dstRow + bytesPerLine. |
|
7538 |
srcRow := srcRow + bytesPerLineIn |
|
7539 |
] |
|
7540 |
] ifFalse:[ |
|
7541 |
('IMAGE: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' , |
|
7542 |
bitsPerPixel printString) errorPrintNL. |
|
7543 |
^ nil |
|
7544 |
] |
|
7545 |
]. |
|
7546 |
] ifFalse:[ |
|
7547 |
" |
|
7548 |
repad in the buffer |
|
7549 |
" |
|
7550 |
1 to:h do:[:hi | |
|
7551 |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1) |
|
7552 |
with:tmpData startingAt:srcRow. |
|
7553 |
dstRow := dstRow + bytesPerLine. |
|
7554 |
srcRow := srcRow + bytesPerLineIn |
|
7555 |
] |
|
7556 |
] |
|
283 | 7557 |
] ifFalse:[ |
518 | 7558 |
(bytesPerLine * height) ~~ inData size ifTrue:[ |
7559 |
tmpData := inData. |
|
7560 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
7561 |
inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1 |
|
7562 |
] |
|
283 | 7563 |
]. |
7564 |
bytes := inData. |
|
7565 |
||
7566 |
"info printNL." |
|
7567 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7568 |
((visType == #StaticGray) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7569 |
or:[visType == #TrueColor |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
7570 |
or:[visType == #DirectColor]]) ifTrue:[ |
518 | 7571 |
" |
7572 |
were done, the pixel values are the rgb/grey values |
|
7573 |
" |
|
283 | 7574 |
] ifFalse:[ |
518 | 7575 |
" |
7576 |
what we have now are the color numbers - still need the r/g/b values. |
|
7577 |
find out, which colors are in the picture |
|
7578 |
" |
|
7579 |
usedPixels := inData usedValues. |
|
7580 |
mapSize := usedPixels max + 1. |
|
7581 |
||
7582 |
"get the palette" |
|
7583 |
map := Array new:mapSize. |
|
7584 |
usedPixels do:[:colorIndex | |
|
7585 |
|i| |
|
7586 |
||
7587 |
i := colorIndex + 1. |
|
7588 |
aDevice getRGBFrom:colorIndex into:[:r :g :b | |
|
7589 |
map at:i put:(Color red:r green:g blue:b) |
|
7590 |
] |
|
7591 |
]. |
|
7592 |
colorMap := map. |
|
283 | 7593 |
]. |
7594 |
||
7595 |
aDevice ungrabPointer. |
|
7596 |
||
7597 |
" |
|
7598 |
(Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display |
|
7599 |
(Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display |
|
7600 |
" |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
7601 |
|
518 | 7602 |
"Modified: 7.3.1996 / 19:17:33 / cg" |
283 | 7603 |
! ! |
7604 |
||
7605 |
!Image class methodsFor:'documentation'! |
|
7606 |
||
7607 |
version |
|
882 | 7608 |
^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.104 1996-06-17 18:28:45 cg Exp $' |
650 | 7609 |
! ! |
283 | 7610 |
Image initialize! |