author | Claus Gittinger <cg@exept.de> |
Thu, 10 Apr 1997 17:45:37 +0200 | |
changeset 1573 | 61046386f41f |
parent 1572 | 029910ee5c9e |
child 1575 | d93e15f64146 |
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 |
|
1289 | 14 |
instanceVariableNames:'bytes width height bitsPerPixel depth colorMap maxPixelValue |
15 |
rowByteSize bitsPerSample samplesPerPixel photometric device |
|
16 |
deviceForm monoDeviceForm fullColorDeviceForm mask' |
|
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
17 |
classVariableNames:'Lobby DitherAlgorithm NumberOfDitherColors |
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
18 |
CollectGarbageWhenRunningOutOfColors FileFormats |
1385
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
19 |
ImageNotFoundQuerySignal BadImageFormatQuerySignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
20 |
ImageSaveErrorSignal FileCreationErrorSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
21 |
CannotRepresentImageSignal InformationLostQuerySignal' |
306
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
22 |
poolDictionaries:'' |
5070ca5adcb1
more for StaticColor visuals (OS/2 display)
Claus Gittinger <cg@exept.de>
parents:
305
diff
changeset
|
23 |
category:'Graphics-Images' |
0 | 24 |
! |
25 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
26 |
!Image class methodsFor:'documentation'! |
0 | 27 |
|
46 | 28 |
copyright |
29 |
" |
|
30 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
72 | 31 |
All Rights Reserved |
46 | 32 |
|
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
0 | 42 |
documentation |
43 |
" |
|
46 | 44 |
this class provides (some time in the future) representation |
45 |
for all kinds of images (monochrome, greyscale and color) |
|
592 | 46 |
and will finally replace Form. |
622 | 47 |
For now (only ;-) depths of 1, 2, 4, 8, 16 and 24 are supported. |
592 | 48 |
|
49 |
An Image keeps all of its information in a device independent way, |
|
50 |
but may be associated to a device. |
|
51 |
The data held keeps all information which was originally present, |
|
52 |
even if the display-device has lower resolution. |
|
46 | 53 |
Therefore, it is possible to process and manipulate images without loosing |
54 |
color information - even on low color resolution displays. |
|
55 |
||
56 |
Usually, you get a device specific representation of the image by |
|
592 | 57 |
sending the |
58 |
'on:aDevice' |
|
59 |
message to it, which will create a (possibly dithered) device-form, |
|
60 |
representing the image using the currently available colors. |
|
46 | 61 |
|
286 | 62 |
In rare cases, an explicit monochrome representation of the image is needed |
46 | 63 |
(X servers take monochrome icons only), this can be created by sending |
592 | 64 |
it the message |
65 |
'monochromeOn:aDevice'. |
|
0 | 66 |
|
46 | 67 |
Also, it is planned to generate another hi-color resolution version, |
286 | 68 |
which uses its own colormap and allows the use of all 256 colors on an 8bit display |
69 |
(this is not currently implemented). |
|
70 |
||
71 |
An images pixel interpretation is controlled by the photometric instance variable |
|
72 |
and (if that is #palette) a colorMap. |
|
73 |
This is in contrast to the ST-80 way, where all of this info is in the colorMap |
|
74 |
(and using specialized colorMaps for b&w / greyScale images). |
|
75 |
This may change in future versions for more application compatibility. |
|
76 |
||
77 |
To convert pictures from/to external file-formats, image readers are used |
|
592 | 78 |
which have the file-format knowledge built in. |
79 |
There are readers for most common formats available |
|
286 | 80 |
(see ImageReader and especially subclasses such as TIFFReader, GIFReader etc.). |
81 |
||
82 |
File formats are handled by subclasses of ImageReader, which understand |
|
83 |
a specific format. You can add more readers, by adding an association |
|
84 |
such as ('.jpg' -> JPEGReader) to the class variable 'FileFormats' |
|
85 |
(see the classes #initialize method, which dsets up some default, and the |
|
86 |
patches/display.rc files, which add more). |
|
87 |
||
88 |
Some algorithms used here (especially dithering & color allocation) are |
|
46 | 89 |
experimental and far from being perfect (some are very slow). |
592 | 90 |
For now, the most common cases have been optimized and perform reasonably |
91 |
fast - however, with uncommon depth/visualType combinations, you may |
|
92 |
run into slower fallback methods ... |
|
93 |
||
94 |
Much more work is needed if you plan to do heavy image processing and will |
|
95 |
(may) be done in the future if there is a demand for it ... |
|
96 |
Dithering can be controlled by the DitherAlgorithm classVariable: |
|
2 | 97 |
|
46 | 98 |
DitherAlgorithm: |
0 | 99 |
|
46 | 100 |
nil a simple threshold algorithm |
592 | 101 |
(i.e. for mono, p<0.5 -> black, p>=0.5 -> white) |
0 | 102 |
|
46 | 103 |
#pattern patterned dither |
592 | 104 |
(for p, take dithered color to fill pixel; |
105 |
uses dithering in color-class) |
|
0 | 106 |
|
46 | 107 |
#error error diffusion dither (Floyd-Steinberg) |
592 | 108 |
planned - not yet implemented. |
109 |
||
110 |
||
111 |
||
112 |
[instance variables:] |
|
113 |
||
114 |
width <Integer> the width in pixels |
|
115 |
height <Integer> the height in pixels |
|
116 |
bytes <ByteArray> the full image information |
|
117 |
photometric <Symbol> #rgb, #palette, #blackIs0 or #whiteIs0 |
|
118 |
samplesPerPixel <Integer> the number of planes |
|
119 |
bitsPerSample <Array> the number of bits per plane |
|
120 |
||
121 |
colorMap <Array> only if photometric is #pseudocolor; |
|
122 |
maps pixel values to r/g/b values. |
|
123 |
||
124 |
device <Workstation> the device on which deviceForm, |
|
125 |
monoDeviceForm and lowResDeviceForm are |
|
126 |
||
127 |
deviceForm <Form> the device form which gives the best |
|
128 |
possible aproximation of the image on |
|
129 |
device using standard colors. |
|
130 |
||
131 |
monoDeviceForm <Form> the device form which gives a monochrome |
|
132 |
aproximation of the image on device. |
|
133 |
||
134 |
fullColorDeviceForm <Form> the device form which gives the best |
|
135 |
possible aproximation of the image on |
|
136 |
device using private colors. |
|
137 |
||
1288
9af08a658acc
added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents:
1279
diff
changeset
|
138 |
bitsPerPixel not used in ST/X |
9af08a658acc
added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents:
1279
diff
changeset
|
139 |
depth these have been added in instVar-slots |
9af08a658acc
added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents:
1279
diff
changeset
|
140 |
maxPixelValue according to the ST-80's image class. |
9af08a658acc
added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents:
1279
diff
changeset
|
141 |
rowByteSize to allow loading of st-80 images |
9af08a658acc
added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents:
1279
diff
changeset
|
142 |
(which are stored as instVarAt:put: expressions) |
9af08a658acc
added ST-80 dummy instVars - allows ST-80 images stored via #storeOn:
Claus Gittinger <cg@exept.de>
parents:
1279
diff
changeset
|
143 |
|
592 | 144 |
[class variables:] |
145 |
||
146 |
Lobby <Registry> keeps track of known images |
|
147 |
(for resource freeing with garbage collector) |
|
148 |
||
149 |
DitherAlgorithm <Symbol> defines how to dither |
|
150 |
||
151 |
NumberOfDitherColors <Integer> defines, how many dither colors to use |
|
152 |
||
153 |
FileFormats <Dictionary> associates filename extensions to |
|
154 |
image reader classes (now set-up in startup-file) |
|
155 |
||
156 |
CollectGarbageWhenRunningOutOfColors |
|
157 |
<Boolean> if true, and we run out of available |
|
158 |
device colors during creation of a |
|
159 |
device image, collect garbage for |
|
160 |
possible image reclamation. |
|
161 |
If false, proceed immediately. |
|
162 |
Default is true. |
|
158 | 163 |
|
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
164 |
ImageNotFoundNotificationSignal |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
165 |
<QuerySignal> raised, if an image could not be loaded |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
166 |
from a file. The parameter is the images |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
167 |
fileName. May return a replacement |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
168 |
image or proceed with nil. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
169 |
If unhandled, a nil is returned from the |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
170 |
image creation. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
171 |
|
46 | 172 |
todo: |
592 | 173 |
there is currently no mask stored/available in the image itself; currently masks |
174 |
have to be stored as separate bitmaps. |
|
175 |
(which is bad for image-file formats, which provide a mask) |
|
176 |
Thus, currently, all images are completely opaque. |
|
177 |
||
178 |
[See also:] |
|
179 |
Form Icon ImageReader |
|
611 | 180 |
|
181 |
[author:] |
|
182 |
Claus Gittinger |
|
0 | 183 |
" |
649 | 184 |
! |
185 |
||
186 |
examples |
|
187 |
" |
|
188 |
reading from a file (many formats are supported): |
|
189 |
[exBegin] |
|
190 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
191 |
[exEnd] |
|
192 |
[exBegin] |
|
193 |
(Image fromFile:'bitmaps/SmalltalkX.xbm') inspect |
|
194 |
[exEnd] |
|
195 |
[exBegin] |
|
196 |
(Image fromFile:'bitmaps/okSmily_up.bmp') inspect |
|
197 |
[exEnd] |
|
198 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
199 |
inline image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
200 |
default: depth=1 & #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
201 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
202 |
(Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
203 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
204 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
205 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
206 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
207 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
208 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
209 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
210 |
2r11111111 )) inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
211 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
212 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
213 |
with #whiteIs0 photometric |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
214 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
215 |
((Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
216 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
217 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
218 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
219 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
220 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
221 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
222 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
223 |
2r11111111 )) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
224 |
photometric:#whiteIs0) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
225 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
226 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
227 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
228 |
with a colorMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
229 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
230 |
((Image width:8 height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
231 |
fromArray:#( 2r11111111 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
232 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
233 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
234 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
235 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
236 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
237 |
2r10000001 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
238 |
2r11111111 )) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
239 |
colorMap:(Array with:(Color red) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
240 |
with:(Color yellow))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
241 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
242 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
243 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
244 |
a depth4 greyScale image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
245 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
246 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
247 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
248 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
249 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
250 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
251 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
252 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
253 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
254 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
255 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
256 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
257 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
258 |
the following has the same effect: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
259 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
260 |
((Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
261 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
262 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
263 |
depth:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
264 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
265 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
266 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
267 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
268 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
269 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
270 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
271 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
272 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
273 |
with reverse grey-interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
274 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
275 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
276 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
277 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
278 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
279 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
280 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
281 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
282 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
283 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
284 |
photometric:#whiteIs0; |
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-bit-per-pixel 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 1 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 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
307 |
with 1/2/1 rgb interpretation: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
308 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
309 |
((Depth4Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
310 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
311 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
312 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
313 |
16r01 16r23 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
314 |
16r45 16r67 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
315 |
16r89 16rab |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
316 |
16rcd 16ref |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
317 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
318 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
319 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
320 |
bitsPerSample:#(1 2 1); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
321 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
322 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
323 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
324 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
325 |
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
|
326 |
[exBegin] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
327 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
328 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
329 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
330 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
331 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
332 |
fromArray:#[ 16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
333 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
334 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
335 |
16rcd 16ref ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
336 |
i photometric:#rgb. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
337 |
i samplesPerPixel:3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
338 |
i bitsPerSample:#(2 2 0). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
339 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
340 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
341 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
342 |
[exEnd] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
343 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
344 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
345 |
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
|
346 |
[exBegin] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
347 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
348 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
349 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
350 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
351 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
352 |
fromArray:#[ 16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
353 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
354 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
355 |
16rcd 16ref ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
356 |
i photometric:#rgb. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
357 |
i samplesPerPixel:3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
358 |
i bitsPerSample:#(0 0 4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
359 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
360 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
361 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
362 |
[exEnd] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
363 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
364 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
365 |
a 2plane greyscale image: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
366 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
367 |
((Depth2Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
368 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
369 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
370 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
371 |
4r0123 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
372 |
4r1230 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
373 |
4r2301 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
374 |
4r3012 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
375 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
376 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
377 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
378 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
379 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
380 |
with colors: |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
381 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
382 |
((Depth2Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
383 |
width:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
384 |
height:4 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
385 |
fromArray:#[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
386 |
4r0123 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
387 |
4r1230 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
388 |
4r2301 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
389 |
4r3012 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
390 |
]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
391 |
colorMap:(Array with:(Color black) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
392 |
with:(Color red) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
393 |
with:(Color green) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
394 |
with:(Color blue)); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
395 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
396 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
397 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
398 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
399 |
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
|
400 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
401 |
((Depth8Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
402 |
width:16 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
403 |
height:16 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
404 |
fromArray:(ByteArray withAll:(0 to:16rFF))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
405 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
406 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
407 |
bitsPerSample:#(3 3 2); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
408 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
409 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
410 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
411 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
412 |
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
|
413 |
[exBegin] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
414 |
((Depth8Image |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
415 |
width:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
416 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
417 |
fromArray:(ByteArray withAll:(0 to:16r3F))) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
418 |
photometric:#rgb; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
419 |
samplesPerPixel:3; |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
420 |
bitsPerSample:#(2 2 2); |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
421 |
magnifiedBy:30) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
422 |
inspect |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
423 |
[exEnd] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
424 |
|
649 | 425 |
storing (only a few formats are currently supported): |
426 |
[exBegin] |
|
427 |
|img| |
|
428 |
||
429 |
img := Image fromFile:'bitmaps/okSmily_up.bmp'. |
|
430 |
img saveOn:'myImage.tiff'. |
|
431 |
(Image fromFile:'myImage.tiff') inspect |
|
432 |
[exEnd] |
|
433 |
magnifying (any factor): |
|
434 |
[exBegin] |
|
435 |
((Image fromFile:'bitmaps/claus.gif') |
|
436 |
magnifiedTo:(48@48)) |
|
437 |
inspect |
|
438 |
[exEnd] |
|
439 |
[exBegin] |
|
440 |
((Image fromFile:'bitmaps/claus.gif') |
|
441 |
magnifiedBy:0.7) |
|
442 |
inspect |
|
443 |
[exEnd] |
|
444 |
rotating (currently, only multiples of 90 degrees are supported): |
|
445 |
[exBegin] |
|
446 |
((Image fromFile:'bitmaps/claus.gif') |
|
447 |
rotated:90) |
|
448 |
inspect |
|
449 |
[exEnd] |
|
450 |
[exBegin] |
|
451 |
(((Image fromFile:'bitmaps/claus.gif') |
|
452 |
magnifiedBy:0.3@0.7) rotated:270) |
|
453 |
inspect |
|
454 |
[exEnd] |
|
455 |
" |
|
0 | 456 |
! ! |
457 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
458 |
!Image class methodsFor:'initialization'! |
283 | 459 |
|
1307 | 460 |
addReader:aReaderClass suffix:aSuffix |
461 |
"register an additional image reader. |
|
462 |
This is provided for subclasses, to regster themself when |
|
463 |
loaded (or from the startup scripts)" |
|
464 |
||
1309 | 465 |
FileFormats isNil ifTrue:[ |
466 |
self initializeFileFormatTable |
|
467 |
]. |
|
1307 | 468 |
FileFormats at:(aSuffix asLowercase) put:aReaderClass. |
469 |
||
470 |
" |
|
471 |
Image addReader:GIFReader suffix:'gif' |
|
472 |
" |
|
473 |
||
474 |
"Modified: 1.2.1997 / 14:42:54 / cg" |
|
475 |
! |
|
476 |
||
283 | 477 |
fileFormats |
478 |
"return the collection of supported file formats. |
|
479 |
The returned dictionary maps file-extensions to image reader classes." |
|
480 |
||
481 |
FileFormats isNil ifTrue:[ |
|
482 |
self initializeFileFormatTable |
|
483 |
]. |
|
484 |
^ FileFormats |
|
485 |
||
486 |
" |
|
487 |
Image fileFormats |
|
488 |
" |
|
100 | 489 |
! |
490 |
||
283 | 491 |
flushDeviceImages |
869 | 492 |
"simply release all deviceForms" |
283 | 493 |
|
494 |
Lobby do:[:anImage | |
|
869 | 495 |
anImage restored |
283 | 496 |
] |
869 | 497 |
|
498 |
"Modified: 15.6.1996 / 15:45:02 / cg" |
|
0 | 499 |
! |
500 |
||
501 |
initialize |
|
2 | 502 |
"initialize class constants" |
503 |
||
0 | 504 |
"setup tracker of known pictures" |
24 | 505 |
Lobby isNil ifTrue:[ |
748 | 506 |
Lobby := Registry new. |
507 |
ObjectMemory addDependent:self. |
|
508 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
509 |
"/ define the algorithm to use for dithering - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
510 |
"/ supported values are: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
511 |
"/ #threshold |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
512 |
"/ #ordered |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
513 |
"/ #floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
514 |
"/ #burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
515 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
516 |
DitherAlgorithm := #floydSteinberg. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
517 |
|
748 | 518 |
(Display notNil and:[Display hasGrayscales]) ifFalse:[ |
519 |
NumberOfDitherColors := 64 |
|
520 |
] ifTrue:[ |
|
521 |
"as far as I remember, this is about the number of grey values, the eye can distinguish" |
|
522 |
NumberOfDitherColors := 100 |
|
523 |
]. |
|
524 |
||
525 |
"define reader classes" |
|
526 |
FileFormats isNil ifTrue:[ |
|
527 |
self initializeFileFormatTable |
|
528 |
]. |
|
529 |
||
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
530 |
CollectGarbageWhenRunningOutOfColors := false. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
531 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
532 |
ImageNotFoundQuerySignal := QuerySignal new. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
533 |
ImageNotFoundQuerySignal nameClass:self message:#imageNotFoundQuerySignal. |
1307 | 534 |
|
1385
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
535 |
ImageSaveErrorSignal := ErrorSignal newSignalMayProceed:true. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
536 |
ImageSaveErrorSignal nameClass:self message:#imageSaveErrorSignal. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
537 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
538 |
FileCreationErrorSignal := ImageSaveErrorSignal newSignalMayProceed:true. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
539 |
FileCreationErrorSignal nameClass:self message:#fileCreationErrorSignal. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
540 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
541 |
CannotRepresentImageSignal := ImageSaveErrorSignal newSignalMayProceed:true. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
542 |
CannotRepresentImageSignal nameClass:self message:#cannotRepresentImageSignal. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
543 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
544 |
InformationLostQuerySignal := QuerySignal new. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
545 |
InformationLostQuerySignal nameClass:self message:#informationLostQuerySignal. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
546 |
|
1307 | 547 |
BadImageFormatQuerySignal := QuerySignal new. |
548 |
BadImageFormatQuerySignal nameClass:self message:#badImageFormatQuerySignal. |
|
386 | 549 |
] |
748 | 550 |
|
1385
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
551 |
"Modified: 27.2.1997 / 12:42:13 / cg" |
12 | 552 |
! |
553 |
||
24 | 554 |
initializeFileFormatTable |
46 | 555 |
"initialize a default table to map from file extension to reader class. |
556 |
The mapping here is a default needed for proper operation of ST/X; |
|
557 |
see the 'smalltalk.rc' startup file for a real (full) map." |
|
24 | 558 |
|
559 |
FileFormats := Dictionary new. |
|
1307 | 560 |
|
561 |
FileFormats at:'xbm' put:XBMReader. |
|
562 |
FileFormats at:'tiff' put:TIFFReader. |
|
563 |
FileFormats at:'gif' put:GIFReader. |
|
564 |
"/ FileFormats at:'img' put:IMGReader. |
|
565 |
"/ FileFormats at:'icon' put:SunRasterReader. |
|
24 | 566 |
|
72 | 567 |
" |
568 |
Image initializeFileFormatTable |
|
569 |
" |
|
1307 | 570 |
|
571 |
"Modified: 1.2.1997 / 14:41:11 / cg" |
|
24 | 572 |
! |
573 |
||
901 | 574 |
update:something with:aParameter from:changedObject |
0 | 575 |
"flush all device specific stuff when restarted from a snapshot" |
576 |
||
577 |
(something == #restarted) ifTrue:[ |
|
901 | 578 |
self flushDeviceImages |
0 | 579 |
] |
901 | 580 |
|
581 |
"Created: 21.6.1996 / 19:47:43 / cg" |
|
0 | 582 |
! ! |
583 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
584 |
!Image class methodsFor:'instance creation'! |
283 | 585 |
|
586 |
extent:ext depth:d bits:bits |
|
587 |
"ST-80 compatibility; assume 32-bit padding" |
|
588 |
||
589 |
^ self extent:ext depth:d bits:bits pad:32 |
|
24 | 590 |
! |
591 |
||
283 | 592 |
extent:ext depth:d bits:bits pad:padding |
593 |
"ST-80 compatibility" |
|
594 |
||
595 |
^ self width:ext x height:ext y depth:d fromArray:bits pad:padding |
|
24 | 596 |
! |
597 |
||
1276 | 598 |
extent:ext depth:d bitsPerPixel:bpp palette:aColormap usingBits:bits |
599 |
"ST-80 compatibility" |
|
600 |
||
601 |
|img| |
|
602 |
||
603 |
img := self width:ext x height:ext y depth:bpp fromArray:bits pad:32. |
|
604 |
img colorMap:aColormap. |
|
605 |
^ img |
|
606 |
||
607 |
"Created: 25.1.1997 / 03:50:22 / cg" |
|
608 |
"Modified: 25.1.1997 / 12:27:35 / cg" |
|
609 |
! |
|
610 |
||
1433 | 611 |
extent:ext depth:d palette:aColormap |
612 |
"create & return a blank image of the given size. |
|
613 |
ST-80 compatibility" |
|
614 |
||
615 |
|newImage emptyBits| |
|
616 |
||
617 |
newImage := (self implementorForDepth:d) new. |
|
618 |
newImage width:ext x height:ext y depth:d palette:aColormap. |
|
619 |
emptyBits := ByteArray new:(newImage bytesPerRow * ext y). |
|
620 |
newImage bits:emptyBits. |
|
621 |
^ newImage |
|
622 |
||
623 |
" |
|
624 |
Image extent:16@16 depth:8 palette:nil |
|
625 |
Image extent:16@16 depth:4 palette:nil |
|
626 |
Image extent:16@16 depth:2 palette:nil |
|
627 |
" |
|
628 |
||
629 |
"Created: 6.3.1997 / 15:24:01 / cg" |
|
630 |
! |
|
631 |
||
1070 | 632 |
extent:ext depth:d palette:aColormap bits:bits |
633 |
"ST-80 compatibility" |
|
634 |
||
635 |
^ self extent:ext depth:d palette:aColormap bits:bits pad:16 |
|
636 |
||
637 |
"Modified: 7.10.1996 / 11:32:16 / cg" |
|
638 |
! |
|
639 |
||
283 | 640 |
extent:ext depth:d palette:aColormap bits:bits pad:padding |
641 |
"ST-80 compatibility" |
|
642 |
||
1070 | 643 |
|img| |
644 |
||
645 |
img := self width:ext x height:ext y depth:d fromArray:bits pad:padding. |
|
646 |
img colorMap:aColormap. |
|
647 |
^ img |
|
648 |
||
649 |
"Modified: 7.10.1996 / 11:32:00 / cg" |
|
283 | 650 |
! |
651 |
||
652 |
extent:ext fromArray:bits offset:offset |
|
653 |
"ST-80 compatibility" |
|
654 |
||
655 |
^ self width:ext x height:ext y fromArray:bits |
|
89 | 656 |
! |
657 |
||
658 |
fromForm:aForm |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
659 |
"create & return an Image given a aForm" |
89 | 660 |
|
936 | 661 |
|depth device vis img| |
662 |
||
663 |
depth := aForm depth. |
|
664 |
device := aForm device. |
|
665 |
||
666 |
(device notNil and:[depth == device depth]) ifTrue:[ |
|
667 |
"/ |
|
668 |
"/ for truecolor displays, return a Depth24Image |
|
669 |
"/ (must do this for depth15 & depth16 displays, since |
|
670 |
"/ Depth16Image has no way to specify r/g/b masks ...) |
|
671 |
"/ |
|
672 |
vis := device visualType. |
|
673 |
(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[ |
|
674 |
depth > 8 ifTrue:[ |
|
675 |
depth := 24. |
|
676 |
] |
|
677 |
]. |
|
678 |
]. |
|
679 |
img := (self implementorForDepth:depth) new. |
|
680 |
device isNil ifTrue:[ |
|
681 |
^ img fromForm:aForm. |
|
682 |
]. |
|
683 |
^ img from:aForm in:(0@0 extent:(aForm extent)) |
|
89 | 684 |
|
685 |
" |
|
686 |
|f| |
|
687 |
||
688 |
f := Form width:16 height:16. |
|
689 |
f clear. |
|
690 |
f displayLineFromX:0 y:0 toX:15 y:15. |
|
691 |
f inspect. |
|
692 |
(Image fromForm:f) inspect |
|
693 |
" |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
694 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
695 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
696 |
|f| |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
697 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
698 |
f := Form width:16 height:16 depth:(Display depth) on:Display. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
699 |
f clear. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
700 |
f paint:(Color red). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
701 |
f displayLineFromX:0 y:0 toX:15 y:15. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
702 |
f paint:(Color green). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
703 |
f displayLineFromX:15 y:0 toX:0 y:15. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
704 |
f inspect. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
705 |
(Image fromForm:f) inspect |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
706 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
707 |
|
936 | 708 |
"Modified: 11.7.1996 / 11:21:42 / cg" |
89 | 709 |
! |
710 |
||
711 |
fromImage:anImage |
|
712 |
"create & return an Image given another image. This can be used to |
|
713 |
convert an image to another depth." |
|
714 |
||
715 |
(self == Image or:[anImage class == self]) ifTrue:[^ anImage]. |
|
716 |
^ self new fromImage:anImage. |
|
717 |
||
718 |
" |
|
719 |
|i1 i8| |
|
720 |
||
721 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
722 |
i8 := Depth8Image fromImage:i1. |
|
723 |
i8 inspect |
|
724 |
" |
|
725 |
! |
|
726 |
||
191 | 727 |
fromSubImage:anImage in:aRectangle |
728 |
"create & return an Image from a rectangular area in another image. |
|
729 |
This can also be used to get a subimage in another depth." |
|
730 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
731 |
|newImage| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
732 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
733 |
self == Image ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
734 |
newImage := self implementorForDepth:anImage depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
735 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
736 |
newImage := self new. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
737 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
738 |
^ newImage fromSubImage:anImage in:aRectangle. |
191 | 739 |
|
740 |
" |
|
741 |
|i1 i8| |
|
742 |
||
743 |
i1 := Image fromFile:'bitmaps/garfield.gif'. |
|
744 |
i8 := Depth8Image fromSubImage:i1 in:(0@0 corner:20@20). |
|
745 |
i8 inspect |
|
746 |
" |
|
650 | 747 |
" |
748 |
|i1 i8| |
|
749 |
||
750 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
|
751 |
i8 := Depth8Image fromSubImage:i1 in:(70@50 extent:50@50). |
|
752 |
i8 inspect |
|
753 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
754 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
755 |
|i1 i8| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
756 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
757 |
i1 := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
758 |
i8 := Image fromSubImage:i1 in:(70@50 extent:50@50). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
759 |
i8 inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
760 |
" |
191 | 761 |
|
762 |
"Created: 20.9.1995 / 01:05:43 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
763 |
"Modified: 10.6.1996 / 18:11:08 / cg" |
191 | 764 |
! |
765 |
||
283 | 766 |
new |
767 |
"create a new image. Redefined to set the photometric to |
|
768 |
greyScale with black being 0 as default." |
|
769 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
770 |
^ super new photometric:(self defaultPhotometric) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
771 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
772 |
"Modified: 10.6.1996 / 18:08:37 / cg" |
283 | 773 |
! |
774 |
||
89 | 775 |
width:w height:h |
776 |
"create a new image, given width, height. Assume a depth of 1." |
|
777 |
||
778 |
|cls| |
|
779 |
||
780 |
cls := self. |
|
781 |
cls == Image ifTrue:[ |
|
782 |
cls := self implementorForDepth:1 |
|
783 |
]. |
|
784 |
^ cls new width:w height:h depth:1 |
|
785 |
! |
|
786 |
||
82 | 787 |
width:w height:h depth:d |
89 | 788 |
"create a new image, given width, height and depth" |
789 |
||
191 | 790 |
^ (self implementorForDepth:d) new |
791 |
width:w height:h depth:d |
|
82 | 792 |
! |
793 |
||
794 |
width:w height:h depth:d fromArray:pixelData |
|
89 | 795 |
"create a new image, given width, height, depth and data. |
796 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
134 | 797 |
depth (8-bit padded)." |
82 | 798 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
799 |
^ (self implementorForDepth:d) new |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
800 |
width:w height:h depth:d fromArray:pixelData |
82 | 801 |
|
802 |
" |
|
803 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
804 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
805 |
depth:1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
806 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
807 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
808 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
809 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
810 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
811 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
812 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
813 |
2r00110011]. |
82 | 814 |
" |
815 |
||
816 |
" |
|
817 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
818 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
819 |
depth:2 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
820 |
fromArray:#[4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
821 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
822 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
823 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
824 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
825 |
4r0011 4r0011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
826 |
4r1100 4r1100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
827 |
4r0011 4r0011]. |
89 | 828 |
" |
829 |
||
830 |
" |
|
831 |
Image width:8 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
832 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
833 |
depth:4 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
834 |
fromArray:#[16r00 16r01 16rf0 16rf1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
835 |
16r02 16r03 16rf2 16rf3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
836 |
16r04 16r05 16rf4 16rf5 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
837 |
16r06 16r07 16rf6 16rf7 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
838 |
16r08 16r09 16rf8 16rf9 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
839 |
16r0a 16r0b 16rfa 16rfb |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
840 |
16r0c 16r0d 16rfc 16rfd |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
841 |
16r0e 16r0f 16rfe 16rff]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
842 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
843 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
844 |
"Modified: 10.6.1996 / 18:18:10 / cg" |
132 | 845 |
! |
846 |
||
134 | 847 |
width:w height:h depth:d fromArray:pixelData pad:padding |
848 |
"create a new image, given width, height, depth and data. |
|
849 |
Data must be a ByteArray containing correctly aligned bits for the specified |
|
850 |
depth." |
|
851 |
||
852 |
|img newBits srcRowBytes dstRowBytes srcIndex dstIndex| |
|
853 |
||
854 |
img := (self implementorForDepth:d) new width:w height:h depth:d . |
|
855 |
||
856 |
padding ~~ 8 ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
857 |
"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
|
858 |
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
|
859 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
860 |
dstRowBytes := img bytesPerRow. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
861 |
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
|
862 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
863 |
newBits := ByteArray new:(dstRowBytes * h). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
864 |
srcIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
865 |
dstIndex := 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
866 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
867 |
1 to:h do:[:row | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
868 |
newBits replaceFrom:dstIndex |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
869 |
to:(dstIndex + dstRowBytes - 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
870 |
with:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
871 |
startingAt:srcIndex. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
872 |
srcIndex := srcIndex + srcRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
873 |
dstIndex := dstIndex + dstRowBytes. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
874 |
]. |
134 | 875 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
876 |
pixelData class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
877 |
newBits := ByteArray withAll:pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
878 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
879 |
newBits := pixelData |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
880 |
] |
134 | 881 |
]. |
882 |
img bits:newBits. |
|
883 |
^ img |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
884 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
885 |
"Modified: 8.6.1996 / 10:07:47 / cg" |
134 | 886 |
! |
887 |
||
283 | 888 |
width:w height:h fromArray:anArray |
889 |
"create a new image, given width, height. Assume a depth of 1 of the |
|
890 |
receiving class is Image. |
|
891 |
Data must be a ByteArray containing correctly aligned bits for depth 1 |
|
892 |
(i.e. 8 bits per byte)." |
|
893 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
894 |
|cls d pixels| |
283 | 895 |
|
896 |
cls := self. |
|
897 |
cls == Image ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
898 |
cls := self implementorForDepth:1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
899 |
d := 1. |
283 | 900 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
901 |
d := cls imageDepth |
283 | 902 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
903 |
anArray class isBytes ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
904 |
pixels := ByteArray withAll:anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
905 |
] ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
906 |
pixels := anArray |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
907 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
908 |
^ cls new width:w height:h depth:d fromArray:pixels |
191 | 909 |
|
910 |
" |
|
283 | 911 |
Image width:8 |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
912 |
height:8 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
913 |
fromArray:#[2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
914 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
915 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
916 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
917 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
918 |
2r00110011 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
919 |
2r11001100 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
920 |
2r00110011]. |
191 | 921 |
" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
922 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
923 |
"Modified: 8.6.1996 / 10:07:26 / cg" |
283 | 924 |
! ! |
925 |
||
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
926 |
!Image class methodsFor:'Signal constants'! |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
927 |
|
1307 | 928 |
badImageFormatQuerySignal |
929 |
"return the (query-) signal, which is raised if some |
|
930 |
bitmap-image could not be loaded due to an unrecognized format. |
|
931 |
If unhandled, the image-load returns nil. |
|
932 |
Otherwise, it returns whatever the handler proceeds with. |
|
933 |
The exception gets either the images fileName or an input stream |
|
934 |
as parameter" |
|
935 |
||
936 |
^ BadImageFormatQuerySignal |
|
937 |
||
938 |
"Created: 1.2.1997 / 14:40:29 / cg" |
|
939 |
! |
|
940 |
||
1385
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
941 |
cannotRepresentImageSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
942 |
"return the signal, which is raised if some |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
943 |
bitmap-image could not be saved in the requested format. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
944 |
This happens for example, if a true color image is saved in |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
945 |
xpm format or a color image saved in xbm format. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
946 |
Applications should either ask the class before saving |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
947 |
(via #canRepresent:) or handle the error and use an alternative |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
948 |
format then." |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
949 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
950 |
^ CannotRepresentImageSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
951 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
952 |
"Created: 27.2.1997 / 12:24:43 / cg" |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
953 |
! |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
954 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
955 |
fileCreationErrorSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
956 |
"return the signal which is raised if a file could not be |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
957 |
created in an image-save operation." |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
958 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
959 |
^ FileCreationErrorSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
960 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
961 |
"Created: 27.2.1997 / 12:32:59 / cg" |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
962 |
! |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
963 |
|
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
964 |
imageNotFoundQuerySignal |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
965 |
"return the (query-) signal, which is raised if some |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
966 |
bitmap-image could not be loaded from a file. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
967 |
If unhandled, the image-load returns nil. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
968 |
Otherwise, it returns whatever the handler proceeds with. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
969 |
The exception gets the images fileName as parameter" |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
970 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
971 |
^ ImageNotFoundQuerySignal |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
972 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
973 |
"Created: 7.1.1997 / 16:04:49 / cg" |
1385
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
974 |
! |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
975 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
976 |
imageSaveErrorSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
977 |
"return the parent signal of all image-save errors." |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
978 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
979 |
^ ImageSaveErrorSignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
980 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
981 |
"Created: 27.2.1997 / 12:32:23 / cg" |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
982 |
! |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
983 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
984 |
informationLostQuerySignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
985 |
"return the (query-) signal, which is raised if some |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
986 |
bitmap-image is saved in a format which cannot represent |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
987 |
the full image (for example: the images mask). |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
988 |
If unhandled, the image-save proceeds. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
989 |
Otherwise, the handler may show a warn box or whatever and decide |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
990 |
to proceed or abort the saving." |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
991 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
992 |
^ InformationLostQuerySignal |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
993 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
994 |
"Created: 27.2.1997 / 12:43:50 / cg" |
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
995 |
! ! |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
996 |
|
1230
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
997 |
!Image class methodsFor:'cleanup'! |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
998 |
|
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
999 |
releaseResourcesOnDevice:aDevice |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1000 |
"this is sent when a display connection is closed, |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1001 |
to release all cached Images from that device" |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1002 |
|
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1003 |
Lobby |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1004 |
unregisterAllForWhich:[:anImage | |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1005 |
|ok| |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1006 |
ok := anImage graphicsDevice == aDevice. |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1007 |
ok ifTrue:[ |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1008 |
anImage quickRelease |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1009 |
]. |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1010 |
ok |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1011 |
] |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1012 |
|
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1013 |
"Created: 16.1.1997 / 19:30:44 / cg" |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1014 |
"Modified: 16.1.1997 / 19:33:49 / cg" |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1015 |
! ! |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
1016 |
|
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1017 |
!Image class methodsFor:'file reading'! |
650 | 1018 |
|
1019 |
fromFile:aFileName |
|
1020 |
"read an image from a file - this methods tries to find |
|
1021 |
out the file format itself (by the extension and by contents) |
|
1143 | 1022 |
and lets the appropriate reader read the file. |
1023 |
Also, all bitmap directories along the searchPath are checked |
|
1024 |
for the file; thus, you can place your private images into a |
|
1025 |
separate directory, thereby overriding system bitmaps easily. |
|
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1026 |
If the file is unreadable or does not contain an appropriate image, |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1027 |
the ImageNotFoundQuerySignal is raised, which may be handled to |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1028 |
proceed with some replacement image. If unhandled, nil is returned." |
650 | 1029 |
|
1307 | 1030 |
|image name fn nm inStream suffix readerClass| |
650 | 1031 |
|
1032 |
" |
|
1143 | 1033 |
before trying each reader, check if the file is readable |
650 | 1034 |
" |
1307 | 1035 |
name := aFileName asFilename name. |
1036 |
||
650 | 1037 |
inStream := Smalltalk systemFileStreamFor:name. |
1038 |
inStream isNil ifTrue:[ |
|
1039 |
inStream := Smalltalk bitmapFileStreamFor:name. |
|
1040 |
inStream isNil ifTrue:[ |
|
1307 | 1041 |
|
1042 |
"/ this signal is a query - if noone seems to |
|
1043 |
"/ care, return nil. |
|
1044 |
"/ However, a handler may provide a replacement. |
|
1045 |
||
1046 |
"/ ('IMAGE: ' , aFileName , ' does not exist or is not readable') infoPrintCR. |
|
1047 |
^ ImageNotFoundQuerySignal |
|
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1048 |
raiseRequestWith:aFileName |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1049 |
errorString:('IMAGE: ''' , aFileName , ''' does not exist or is not readable'). |
650 | 1050 |
]. |
1051 |
name := 'bitmaps/' , name. |
|
1052 |
]. |
|
1053 |
inStream close. |
|
1054 |
||
1055 |
nm := name. |
|
1307 | 1056 |
fn := nm asFilename. |
1057 |
suffix := fn suffix. |
|
1058 |
||
1059 |
"/ |
|
1060 |
"/ handle compressed-suffix |
|
1061 |
"/ |
|
1062 |
(#('Z' 'gz') includes:suffix) ifTrue:[ |
|
1063 |
fn := fn withoutSuffix. |
|
1064 |
nm := fn name. |
|
1065 |
suffix := fn suffix. |
|
1066 |
]. |
|
1067 |
||
1068 |
suffix isEmpty ifTrue:[ |
|
1069 |
suffix := nm. |
|
1070 |
]. |
|
1071 |
||
1072 |
"/ |
|
1073 |
"/ get the imageReader class from the files extension |
|
1074 |
"/ and ask it first |
|
1075 |
||
1469
12e083fba6e0
handle no-suffix case in #fromFile:
Claus Gittinger <cg@exept.de>
parents:
1461
diff
changeset
|
1076 |
readerClass := FileFormats at:(suffix asLowercase) ifAbsent:nil. |
1307 | 1077 |
readerClass notNil ifTrue:[ |
1078 |
image := readerClass fromFile:name. |
|
1079 |
image notNil ifTrue:[^ image]. |
|
650 | 1080 |
]. |
1081 |
||
1082 |
" |
|
1083 |
no known extension - ask all readers if they know |
|
1084 |
this format ... |
|
1143 | 1085 |
... these look into the file, and investigate the header. |
1307 | 1086 |
therefore, it takes a bit longer. |
650 | 1087 |
" |
1088 |
FileFormats do:[:readerClass | |
|
1089 |
readerClass notNil ifTrue:[ |
|
1090 |
(readerClass isValidImageFile:name) ifTrue:[ |
|
1091 |
^ readerClass fromFile:name |
|
1092 |
] |
|
1093 |
] |
|
1094 |
]. |
|
1095 |
||
1307 | 1096 |
"/ nope - unknown format |
1097 |
"/ |
|
1098 |
"/ this signal is a query - if noone seems to |
|
1099 |
"/ care, return nil. |
|
1100 |
"/ However, a handler may provide a replacement. |
|
1101 |
||
1102 |
"/ 'IMAGE: unknown image file format: ' infoPrint. aFileName infoPrintNL. |
|
1103 |
^ ImageNotFoundQuerySignal |
|
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1104 |
raiseRequestWith:aFileName |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1105 |
errorString:('IMAGE: unknown image file format: ''' , aFileName , ''''). |
650 | 1106 |
|
1107 |
" |
|
1108 |
Image fromFile:'bitmaps/dano.tiff' |
|
1109 |
Image fromFile:'bitmaps/test.fax' |
|
1110 |
Image fromFile:'bitmaps/voice.tiff' |
|
1111 |
Image fromFile:'voice.tiff' |
|
1112 |
||
1113 |
Image fromFile:'../fileIn/bitmaps/claus.gif' |
|
1114 |
Image fromFile:'../fileIn/bitmaps/garfield.gif' |
|
1115 |
||
1116 |
Image fromFile:'../fileIn/bitmaps/founders.im8' |
|
1117 |
Image fromFile:'../goodies/faces/next.com/steve.face' |
|
1118 |
||
1119 |
Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico' |
|
1120 |
Image fromFile:'bitmaps/globe1.xbm' |
|
1121 |
Image fromFile:'bitmaps/globe1.xbm.Z' |
|
1122 |
Image fromFile:'bitmaps/hello_world.icon' |
|
1123 |
" |
|
1124 |
||
1156
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1125 |
" |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1126 |
Image fromFile:'fooBar' |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1127 |
" |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1128 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1129 |
"giving a messgage for non-existing images: |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1130 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1131 |
Image imageNotFoundQuerySignal |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1132 |
handle:[:ex | |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1133 |
ex errorString printCR. |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1134 |
ex proceedWith:nil |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1135 |
] do:[ |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1136 |
Image fromFile:'fooBar' |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1137 |
] |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1138 |
" |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1139 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1140 |
"giving a replacement for non-existing images: |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1141 |
|
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1142 |
Image imageNotFoundQuerySignal |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1143 |
answer:(Image fromFile:'bitmaps/SmalltalkX.xbm') |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1144 |
do:[ |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1145 |
Image fromFile:'fooBar' |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1146 |
] |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1147 |
" |
71ded63a3fae
dont output a message for non-existing images;
Claus Gittinger <cg@exept.de>
parents:
1143
diff
changeset
|
1148 |
|
1469
12e083fba6e0
handle no-suffix case in #fromFile:
Claus Gittinger <cg@exept.de>
parents:
1461
diff
changeset
|
1149 |
"Modified: 19.3.1997 / 23:14:44 / cg" |
1051 | 1150 |
! |
1151 |
||
1143 | 1152 |
fromFile:aFileName on:aDevice |
1153 |
"read an image from a file and prepare a device representation. |
|
1307 | 1154 |
Return nil (or whatever a handler returned), |
1155 |
if the file is unreadable or does not contain an appropriate image." |
|
1143 | 1156 |
|
1157 |
|img| |
|
1158 |
||
1159 |
img := self fromFile:aFileName. |
|
1160 |
img notNil ifTrue:[ |
|
1307 | 1161 |
^ img on:aDevice |
1143 | 1162 |
]. |
1163 |
^ nil |
|
1307 | 1164 |
|
1165 |
"Modified: 1.2.1997 / 14:48:07 / cg" |
|
1143 | 1166 |
! |
1167 |
||
1139 | 1168 |
fromFile:aFileName resolution:res |
1169 |
"read an image from a file and (if required) scale the image |
|
1143 | 1170 |
as appropriate (only with very high resolution displays). |
1307 | 1171 |
Return nil (or whatever a handler returned), |
1172 |
if the file is unreadable or does not contain an appropriate image." |
|
1143 | 1173 |
|
1174 |
^ self fromFile:aFileName resolution:res on:nil |
|
1139 | 1175 |
|
1176 |
"Created: 19.12.1996 / 14:02:13 / cg" |
|
1307 | 1177 |
"Modified: 1.2.1997 / 14:48:16 / cg" |
1139 | 1178 |
! |
1179 |
||
1143 | 1180 |
fromFile:aFileName resolution:dpi on:aDevice |
1139 | 1181 |
"read an image from a file and (if required) scale the image |
1143 | 1182 |
as appropriate (only with very high resolution displays). |
1183 |
Prepare a device representation. |
|
1307 | 1184 |
Return nil (or whatever a handler returned), |
1185 |
if the file is unreadable or does not contain an appropriate image." |
|
1143 | 1186 |
|
1187 |
|img dev dpiH mag| |
|
1188 |
||
1189 |
img := self fromFile:aFileName. |
|
1190 |
img isNil ifTrue:[^ nil]. |
|
1191 |
||
1192 |
"if the devices resolution is within +- 50% of dpi, no magnify is needed" |
|
1193 |
dev := aDevice. |
|
1194 |
dev isNil ifTrue:[ |
|
1195 |
"should not happen ..." |
|
1196 |
dev := Screen current |
|
1197 |
]. |
|
1198 |
||
1199 |
dpiH := dev horizontalPixelPerInch. |
|
1200 |
((dpi >= (dpiH * 0.75)) and:[dpi <= (dpiH * 1.5)]) ifTrue:[^ img]. |
|
1201 |
mag := (dpiH / dpi) rounded. |
|
1202 |
mag = 0 ifTrue:[^ img]. |
|
1203 |
mag = 1 ifTrue:[^ img]. |
|
1204 |
||
1205 |
img := img magnifiedBy:(mag @ mag). |
|
1206 |
aDevice notNil ifTrue:[ |
|
1207 |
"should not happen ..." |
|
1208 |
^ img on:aDevice |
|
1209 |
]. |
|
1210 |
^ img |
|
1307 | 1211 |
|
1212 |
"Modified: 1.2.1997 / 14:48:20 / cg" |
|
1139 | 1213 |
! |
1214 |
||
1051 | 1215 |
fromStream:aStream |
1216 |
"read an image from a stream - this methods tries to find |
|
1217 |
out the file format itself (by contents) |
|
1218 |
and lets the appropriate reader read the file. |
|
1307 | 1219 |
To do this, the stream must be positionable. |
1220 |
Return nil (or whatever a handler returned), |
|
1221 |
if the stream does not contain an appropriate image." |
|
1051 | 1222 |
|
1063 | 1223 |
|image| |
1051 | 1224 |
|
1225 |
" |
|
1226 |
ask all readers if they know |
|
1227 |
this format ... |
|
1228 |
" |
|
1229 |
FileFormats do:[:readerClass | |
|
1230 |
readerClass notNil ifTrue:[ |
|
1231 |
image := readerClass fromStream:aStream. |
|
1232 |
image notNil ifTrue:[^ image]. |
|
1233 |
] |
|
1234 |
]. |
|
1235 |
||
1236 |
" |
|
1237 |
nope - unknown format |
|
1238 |
" |
|
1307 | 1239 |
"/ 'Image [info]: unknown image file format in stream: ' infoPrintCR. |
1240 |
||
1241 |
^ ImageNotFoundQuerySignal |
|
1242 |
raiseRequestWith:aStream |
|
1243 |
errorString:('IMAGE: unknown image file format in stream'). |
|
1051 | 1244 |
|
1245 |
" |
|
1246 |
Image fromFile:'bitmaps/dano.tiff' |
|
1247 |
Image fromFile:'bitmaps/test.fax' |
|
1248 |
Image fromFile:'bitmaps/voice.tiff' |
|
1249 |
Image fromFile:'voice.tiff' |
|
1250 |
||
1251 |
Image fromFile:'../fileIn/bitmaps/claus.gif' |
|
1252 |
Image fromFile:'../fileIn/bitmaps/garfield.gif' |
|
1253 |
||
1254 |
Image fromFile:'../fileIn/bitmaps/founders.im8' |
|
1255 |
Image fromFile:'../goodies/faces/next.com/steve.face' |
|
1256 |
||
1257 |
Image fromFile:'/LocalLibrary/Images/OS2/dos3.ico' |
|
1258 |
Image fromFile:'bitmaps/globe1.xbm' |
|
1259 |
Image fromFile:'bitmaps/globe1.xbm.Z' |
|
1260 |
Image fromFile:'bitmaps/hello_world.icon' |
|
1261 |
" |
|
1262 |
||
1263 |
"Created: 13.9.1996 / 18:06:00 / cg" |
|
1307 | 1264 |
"Modified: 1.2.1997 / 14:48:41 / cg" |
1265 |
! |
|
1266 |
||
1267 |
fromStream:aStream using:aReaderClass |
|
1268 |
"read an image from a stream, given an imageReaderClass. |
|
1269 |
Use this, if you know the files format, but it has an invalid |
|
1270 |
extension (or non-definite header), so #fromStream: could not |
|
1271 |
find out the images format. |
|
1272 |
Return nil (or whatever a handler returned), |
|
1273 |
if the stream does not contain an appropriate image." |
|
1274 |
||
1275 |
|image| |
|
1276 |
||
1277 |
image := aReaderClass fromStream:aStream. |
|
1278 |
image notNil ifTrue:[^ image]. |
|
1279 |
||
1280 |
" |
|
1281 |
nope - unknown format |
|
1282 |
" |
|
1283 |
"/ 'Image [info]: unknown image file format in stream: ' infoPrintCR. |
|
1284 |
||
1285 |
^ ImageNotFoundQuerySignal |
|
1286 |
raiseRequestWith:aStream |
|
1287 |
errorString:('IMAGE: unknown image file format in stream'). |
|
1288 |
||
1289 |
"Created: 1.2.1997 / 14:46:20 / cg" |
|
1290 |
"Modified: 1.2.1997 / 14:48:53 / cg" |
|
650 | 1291 |
! ! |
1292 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1293 |
!Image class methodsFor:'misc'! |
283 | 1294 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1295 |
ditherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1296 |
"return the way we dither - |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1297 |
#threshold, or nil -> no dither |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1298 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1299 |
#error or #floydSteinberg -> errorDiffusion; much better |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1300 |
#burkes -> errorDiffusion; even better." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1301 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1302 |
^ DitherAlgorithm |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1303 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1304 |
"Created: 17.6.1996 / 18:57:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1305 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1306 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1307 |
ditherAlgorithm:aSymbol |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1308 |
"define how to dither - |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1309 |
#threshold, or nil -> no dither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1310 |
#pattern, or #ordered -> orderedDither (ugly, but fast) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1311 |
#error or #floydSteinberg -> errorDiffusion; much better |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1312 |
#burkes -> errorDiffusion; even better." |
283 | 1313 |
|
1314 |
DitherAlgorithm := aSymbol |
|
1315 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1316 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1317 |
Image dither:#pattern |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1318 |
Image dither:#floydSteinberg |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1319 |
Image dither:#burkes |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1320 |
Image dither:nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1321 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1322 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
1323 |
"Modified: 10.6.1996 / 12:27:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
1324 |
"Created: 17.6.1996 / 18:57:19 / cg" |
283 | 1325 |
! |
1326 |
||
1327 |
numberOfDitherColors:n |
|
1328 |
"define how many colors (i.e. patterns) to use when |
|
1329 |
doing a pattern dither" |
|
1330 |
||
1331 |
NumberOfDitherColors := n |
|
798 | 1332 |
! |
1333 |
||
1334 |
orderedDitherMatrixOfSize:sz |
|
1335 |
sz == 2 ifTrue:[ |
|
1336 |
^ #[ |
|
1337 |
0 2 |
|
1338 |
3 1 |
|
1339 |
]. |
|
1340 |
]. |
|
1341 |
||
1342 |
sz == 4 ifTrue:[ |
|
1343 |
^ #[ |
|
1344 |
0 8 2 10 |
|
1345 |
12 4 14 6 |
|
1346 |
3 11 1 9 |
|
1347 |
15 7 13 5 |
|
1348 |
]. |
|
1349 |
]. |
|
1350 |
||
1351 |
sz == 8 ifTrue:[ |
|
1352 |
^ #[ |
|
1353 |
0 32 8 40 2 34 10 42 |
|
1354 |
48 16 56 24 50 18 58 26 |
|
1355 |
12 44 4 36 14 46 6 38 |
|
1356 |
60 28 52 20 62 30 54 22 |
|
1357 |
||
1358 |
3 35 11 43 1 33 9 41 |
|
1359 |
51 19 59 27 49 17 57 25 |
|
1360 |
15 47 7 39 13 45 5 37 |
|
1361 |
63 31 55 23 61 29 53 21 |
|
1362 |
]. |
|
1363 |
]. |
|
1364 |
||
1365 |
^ nil |
|
1366 |
||
1367 |
"Created: 7.6.1996 / 14:15:05 / cg" |
|
283 | 1368 |
! ! |
1369 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1370 |
!Image class methodsFor:'queries'! |
283 | 1371 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1372 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1373 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1374 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1375 |
^ #blackIs0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1376 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1377 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1378 |
"Created: 10.6.1996 / 18:08:12 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1379 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1380 |
|
283 | 1381 |
imageDepth |
579 | 1382 |
"return the depth of images represented by instances of |
1383 |
this class. |
|
1384 |
Must be redefined in concrete subclasses" |
|
1385 |
||
1386 |
^ self shouldNotImplement |
|
1387 |
||
1388 |
"Modified: 20.4.1996 / 23:40:41 / cg" |
|
191 | 1389 |
! |
1390 |
||
1306 | 1391 |
imageFileSuffixes |
1392 |
"return a collection of suffixes which are recognized as image-file suffix" |
|
1393 |
||
1394 |
^ FileFormats keys |
|
1395 |
||
1396 |
" |
|
1397 |
Image imageFileSuffixes |
|
1398 |
" |
|
1399 |
! |
|
1400 |
||
1572 | 1401 |
imageReaderClassForSuffix:aSuffix |
1402 |
"return an appropriate imageReader class for a given file-suffix" |
|
1403 |
||
1404 |
^ FileFormats at:(aSuffix asLowercase) ifAbsent:nil. |
|
1405 |
||
1406 |
" |
|
1407 |
Image imageReaderClassForSuffix:'tiff' |
|
1408 |
" |
|
1409 |
||
1573 | 1410 |
"Modified: 10.4.1997 / 17:36:37 / cg" |
1572 | 1411 |
! |
1412 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
1413 |
implementorForDepth:depth |
283 | 1414 |
"return the class, which best implements images of depth" |
1415 |
||
1416 |
depth == 1 ifTrue:[^ Depth1Image]. |
|
1417 |
depth == 2 ifTrue:[^ Depth2Image]. |
|
1418 |
depth == 4 ifTrue:[^ Depth4Image]. |
|
1419 |
depth == 8 ifTrue:[^ Depth8Image]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
1420 |
depth == 15 ifTrue:[^ Depth16Image]. "/ kludge for 15bit XFree |
283 | 1421 |
depth == 16 ifTrue:[^ Depth16Image]. |
1422 |
depth == 24 ifTrue:[^ Depth24Image]. |
|
1423 |
^ self |
|
1424 |
! ! |
|
1425 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
1426 |
!Image class methodsFor:'screen capture'! |
283 | 1427 |
|
1428 |
fromScreen |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1429 |
"return an image of the full screen. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1430 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1431 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1432 |
(use #fromScreen:on:grab: with a false grabArg then)." |
283 | 1433 |
|
1434 |
|display| |
|
1435 |
||
1436 |
display := Screen current. |
|
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1437 |
^ self |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1438 |
fromScreen:(0@0 corner:(display width @ display height)) |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1439 |
on:display |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1440 |
grab:true |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1441 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1442 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1443 |
Image fromScreen |
1307 | 1444 |
Image fromScreen inspect |
1445 |
" |
|
1446 |
||
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1447 |
"Modified: 26.3.1997 / 10:44:55 / cg" |
283 | 1448 |
! |
1449 |
||
1450 |
fromScreen:aRectangle |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1451 |
"return an image of a part of the screen. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1452 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1453 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1454 |
(use #fromScreen:on:grab: with a false grabArg then)." |
283 | 1455 |
|
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1456 |
^ self |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1457 |
fromScreen:aRectangle |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1458 |
on:Screen current |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1459 |
grab:true |
283 | 1460 |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1461 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1462 |
Image fromScreen:(0@0 corner:100@100) |
1307 | 1463 |
(Image fromScreen:(0@0 corner:100@100)) inspect |
1464 |
" |
|
1465 |
||
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1466 |
"Modified: 26.3.1997 / 10:45:02 / cg" |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1467 |
! |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1468 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1469 |
fromScreen:aRectangle on:aDevice |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1470 |
"return an image of a part of a screen, which may be on |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1471 |
another display device. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1472 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1473 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1474 |
(use #fromScreen:on:grab: with a false grabArg then)." |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1475 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1476 |
^ self |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1477 |
fromScreen:aRectangle |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1478 |
on:aDevice |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1479 |
grab:true |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1480 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1481 |
" |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1482 |
Image fromScreen:(0@0 corner:100@100) |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1483 |
" |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1484 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1485 |
"get a snapshot of your friends screen ... |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1486 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1487 |
|dpy2| |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1488 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1489 |
dpy2 := XWorkstation new initializeFor:'idefix:0'. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1490 |
(Image fromScreen:(dpy2 bounds) on:dpy2) inspect |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1491 |
" |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1492 |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1493 |
"Modified: 26.3.1997 / 10:45:08 / cg" |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1494 |
! |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1495 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1496 |
fromScreen:aRectangle on:aDisplay grab:doGrab |
283 | 1497 |
"return an image of a part of the screen, which may be on |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1498 |
another Display. If the doGrab argument is true, the display |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1499 |
is grabbed (i.e. blocked for others) and a camera cursor is |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1500 |
shown while the readout is done. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1501 |
WARNING: with doGrab true, this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1502 |
and it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1503 |
(use with a false grabArg then)." |
283 | 1504 |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1505 |
|depth vis img| |
283 | 1506 |
|
1507 |
depth := aDisplay depth. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1508 |
|
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1509 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1510 |
"/ 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
|
1511 |
"/ (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
|
1512 |
"/ 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
|
1513 |
"/ |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1514 |
vis := aDisplay visualType. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1515 |
(vis == #TrueColor or:[vis == #DirectColor]) ifTrue:[ |
1307 | 1516 |
depth > 8 ifTrue:[ |
1517 |
depth := 24. |
|
1518 |
] |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1519 |
]. |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1520 |
|
283 | 1521 |
img := (self implementorForDepth: depth) new. |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1522 |
^ img fromScreen:aRectangle on:aDisplay grab:doGrab |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1523 |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1524 |
"Modified: 26.3.1997 / 10:44:39 / cg" |
283 | 1525 |
! |
1526 |
||
1527 |
fromScreenArea |
|
1528 |
"return an image of a part of the screen; |
|
1307 | 1529 |
let user specify screen area. |
1530 |
This is the same as #fromUser - kept for backward compatibility. |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1531 |
Use #fromUser for ST-80 compatibility. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1532 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1533 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1534 |
(use #fromScreen:on:grab: with a false grabArg then)." |
283 | 1535 |
|
1536 |
^ self fromScreen:(Rectangle fromUser) |
|
1537 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1538 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1539 |
Image fromScreenArea |
1307 | 1540 |
Image fromScreenArea inspect |
1541 |
" |
|
1542 |
||
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1543 |
"Modified: 26.3.1997 / 10:45:17 / cg" |
283 | 1544 |
! |
1545 |
||
1546 |
fromUser |
|
1547 |
"return an image of a part of the screen; let user specify screen area. |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1548 |
Same as fromScreenArea, for ST-80 compatibility. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1549 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1550 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1551 |
(use #fromScreen:on:grab: with a false grabArg then)." |
283 | 1552 |
|
1553 |
^ self fromScreenArea |
|
1554 |
||
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1555 |
" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
1556 |
Image fromUser |
1307 | 1557 |
Image fromUser inspect |
1558 |
" |
|
1559 |
||
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1560 |
"Modified: 26.3.1997 / 10:45:25 / cg" |
283 | 1561 |
! |
1562 |
||
1563 |
fromView:aView |
|
1564 |
"return an image taken from a views contents as currently |
|
1565 |
on the screen. The returned image has the same depth and photometric |
|
1307 | 1566 |
as the Display. |
1567 |
Notice, that for invisible or partial covered views, |
|
1568 |
the returned Image is NOT correct. |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1569 |
You may want to raise the view before using this method. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1570 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1571 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1572 |
(use #fromView:grab: with a false grabArg then)." |
283 | 1573 |
|
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1574 |
^ self |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1575 |
fromView:aView |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1576 |
grab:true |
191 | 1577 |
|
1578 |
" |
|
1307 | 1579 |
Image fromView:(Launcher allInstances first window topView) |
1580 |
Image fromView:(BrowserView allInstances first topView) |
|
1581 |
" |
|
1582 |
||
1583 |
"get a snapshot from whichever view is active: |
|
1584 |
||
1585 |
|active| |
|
1586 |
||
1587 |
active := WindowGroup activeGroup topViews first. |
|
1588 |
(Image fromView:active) inspect |
|
1589 |
" |
|
1590 |
||
1043
0688425d02c9
Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents:
1041
diff
changeset
|
1591 |
"Modified: 9.9.1996 / 22:41:01 / stefan" |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1592 |
"Modified: 26.3.1997 / 10:45:40 / cg" |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1593 |
! |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1594 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1595 |
fromView:aView grab:doGrab |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1596 |
"return an image taken from a views contents as currently |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1597 |
on the screen. If the doGrab argument is true, the display |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1598 |
is grabbed (i.e. blocked for others) and a camera cursor is |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1599 |
shown while the readout is done. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1600 |
The returned image has the same depth and photometric |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1601 |
as the Display. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1602 |
Notice, that for invisible or partial covered views, |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1603 |
the returned Image is NOT correct. |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1604 |
You may want to raise the view before using this method. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1605 |
WARNING: with doGrab true, this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1606 |
and it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1607 |
(use with a false grabArg then)." |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1608 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1609 |
|org dev| |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1610 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1611 |
dev := aView graphicsDevice. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1612 |
org := dev translatePoint:(0@0) |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1613 |
from:(aView id) |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1614 |
to:dev rootWindowId. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1615 |
^ self fromScreen:(org extent:aView extent) on:dev grab:doGrab |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1616 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
1617 |
"Created: 26.3.1997 / 10:34:20 / cg" |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1618 |
"Modified: 26.3.1997 / 10:45:50 / cg" |
157 | 1619 |
! ! |
1620 |
||
1279 | 1621 |
!Image methodsFor:'ST-80 compatibility'! |
1622 |
||
1623 |
asCachedImage |
|
1624 |
"return the receiver associated to the current screens device. |
|
1625 |
For ST-80 compatibility |
|
1626 |
(ST/X uses Image for both device- and nonDevice-images)" |
|
1627 |
||
1628 |
^ self on:Screen current |
|
1629 |
||
1630 |
"Modified: 23.4.1996 / 11:10:32 / cg" |
|
1631 |
! |
|
1632 |
||
1633 |
asRetainedMedium |
|
1634 |
"return the receiver associated to the current screens device. |
|
1635 |
For ST-80 compatibility |
|
1636 |
(ST/X uses Image for both device- and nonDevice-images)" |
|
1637 |
||
1638 |
^ self on:Screen current |
|
1639 |
||
1640 |
"Modified: 23.4.1996 / 11:10:32 / cg" |
|
1641 |
"Created: 27.1.1997 / 15:49:08 / cg" |
|
1325 | 1642 |
! |
1643 |
||
1644 |
bounds:newBounds |
|
1645 |
^ self |
|
1646 |
||
1647 |
"Created: 10.2.1997 / 12:44:46 / cg" |
|
1648 |
! |
|
1649 |
||
1433 | 1650 |
containsPoint:aPoint |
1651 |
"in st-80, images are visualComponents ..." |
|
1652 |
||
1653 |
^ self bounds containsPoint:aPoint |
|
1654 |
||
1655 |
"Created: 6.3.1997 / 15:24:12 / cg" |
|
1656 |
! |
|
1657 |
||
1403 | 1658 |
convertToPalette:aColormap renderedBy:anImageRenderer |
1659 |
"this does not really mimicri the corresponding ST-80 functionality" |
|
1660 |
||
1661 |
|monoBits convertedImage| |
|
1662 |
||
1663 |
aColormap size == 2 ifTrue:[ |
|
1664 |
anImageRenderer class == OrderedDither ifTrue:[ |
|
1665 |
monoBits := self orderedDitheredMonochromeBits. |
|
1666 |
] ifFalse:[ |
|
1667 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
|
1668 |
]. |
|
1669 |
(((aColormap at:1) = Color black) |
|
1670 |
and:[(aColormap at:2) = Color white]) ifTrue:[ |
|
1671 |
"/ ok |
|
1672 |
] ifFalse:[ |
|
1673 |
(((aColormap at:1) = Color white) |
|
1674 |
and:[(aColormap at:2) = Color black]) ifTrue:[ |
|
1675 |
monoBits invert |
|
1676 |
] |
|
1677 |
]. |
|
1678 |
convertedImage := Depth1Image width:width height:height fromArray:monoBits. |
|
1679 |
convertedImage palette:aColormap. |
|
1680 |
^ convertedImage |
|
1681 |
]. |
|
1682 |
||
1683 |
self error:'unimplemented operation'. |
|
1684 |
^ self |
|
1685 |
||
1686 |
"Modified: 1.3.1997 / 17:25:50 / cg" |
|
1687 |
! |
|
1688 |
||
1433 | 1689 |
paintBasis |
1690 |
"huh - whats that; |
|
1691 |
I guess, I have to return Color for images without a mask, |
|
1692 |
and CoverageValue for those with a mask; for now, always return Color" |
|
1693 |
||
1694 |
^ ColorValue |
|
1695 |
||
1696 |
"Created: 6.3.1997 / 15:24:19 / cg" |
|
1697 |
! |
|
1698 |
||
1325 | 1699 |
preferredBounds |
1700 |
^ self bounds |
|
1701 |
||
1702 |
"Created: 10.2.1997 / 12:42:36 / cg" |
|
1279 | 1703 |
! ! |
1704 |
||
0 | 1705 |
!Image methodsFor:'accessing'! |
1706 |
||
592 | 1707 |
bitsPerSample |
1708 |
"return the number of bits per sample. |
|
1709 |
The return value is an array of bits-per-plane." |
|
1710 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1711 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1712 |
^ Array with:self depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1713 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1714 |
"Modified: 10.6.1996 / 18:04:21 / cg" |
592 | 1715 |
! |
1716 |
||
1717 |
colorMap |
|
1718 |
"return the colormap" |
|
1719 |
||
1720 |
^ colorMap |
|
1721 |
! |
|
1722 |
||
852 | 1723 |
colorMap:aColorMap |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1724 |
"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
|
1725 |
|
852 | 1726 |
|sz "{ Class: SmallInteger }" |
1727 |
sameColors| |
|
1728 |
||
1729 |
(aColorMap isNil and:[colorMap isNil]) ifTrue:[^ self]. |
|
1730 |
photometric == #palette ifTrue:[ |
|
1731 |
"/ any change at all ? |
|
1732 |
(sz := aColorMap size) == colorMap size ifTrue:[ |
|
1733 |
sameColors := true. |
|
1734 |
||
1735 |
1 to:sz do:[:idx | |
|
1736 |
(aColorMap at:idx) = (colorMap at:idx) ifFalse:[ |
|
1737 |
sameColors := false. |
|
1738 |
] |
|
1739 |
]. |
|
1740 |
sameColors ifTrue:[^ self]. |
|
1741 |
] |
|
1742 |
]. |
|
1743 |
||
1744 |
colorMap := aColorMap. |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1745 |
colorMap notNil ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1746 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1747 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1748 |
(photometric == #palette) ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1749 |
photometric := #blackIs0 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1750 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1751 |
]. |
852 | 1752 |
deviceForm notNil ifTrue:[ |
1753 |
self release |
|
1754 |
] |
|
592 | 1755 |
|
1756 |
"Modified: 31.8.1995 / 03:05:59 / claus" |
|
1446
3007549e3d5e
never convert a colorArray to a colorMap
Claus Gittinger <cg@exept.de>
parents:
1433
diff
changeset
|
1757 |
"Modified: 7.3.1997 / 21:24:23 / cg" |
592 | 1758 |
! |
1759 |
||
757 | 1760 |
container:aVisualContainer |
1761 |
"ignored here - added to allow images to be used like |
|
1762 |
VisualComponents (later, Image should inherit from it)" |
|
1763 |
||
1764 |
"Created: 28.5.1996 / 23:43:49 / cg" |
|
1765 |
"Modified: 29.5.1996 / 10:22:23 / cg" |
|
1766 |
! |
|
1767 |
||
592 | 1768 |
depth |
1769 |
"return the depth of the image" |
|
1770 |
||
1771 |
^ self bitsPerPixel |
|
1772 |
! |
|
1773 |
||
1774 |
device |
|
1775 |
"return the device, the receiver is associated with. |
|
1776 |
Return nil, if the image is unassigned." |
|
1777 |
||
1778 |
^ device |
|
1779 |
! |
|
1780 |
||
1781 |
extent |
|
1782 |
"return the images extent" |
|
1783 |
||
1784 |
^ width@height |
|
1785 |
! |
|
1786 |
||
1787 |
fullColorId |
|
1788 |
"return the id of the full color image on the device. |
|
1789 |
Return nil, if the image is unassigned." |
|
1790 |
||
1791 |
fullColorDeviceForm isNil ifTrue:[^ nil]. |
|
1792 |
^ fullColorDeviceForm id |
|
1793 |
! |
|
1794 |
||
728 | 1795 |
graphicsDevice |
1796 |
"same as #device - for ST-80 compatibility" |
|
1797 |
||
1798 |
^ device |
|
1799 |
! |
|
744 | 1800 |
|
592 | 1801 |
height |
1802 |
"return the height of the image" |
|
1803 |
||
1804 |
^ height |
|
1805 |
! |
|
1806 |
||
1807 |
id |
|
1808 |
"return the id of the image on the device. |
|
1809 |
Return nil, if the image is unassigned." |
|
1810 |
||
1811 |
deviceForm isNil ifTrue:[^ nil]. |
|
1812 |
^ deviceForm id |
|
1813 |
! |
|
1814 |
||
896 | 1815 |
mask |
1816 |
^ mask |
|
1817 |
||
1818 |
"Created: 21.6.1996 / 12:57:44 / cg" |
|
1819 |
! |
|
1820 |
||
906 | 1821 |
mask:anotherImage |
1822 |
"set the images mask - currently, this may be nil or a Depth1Image. |
|
1823 |
(it is planned to support alpha information in a Depth8 maskImage in |
|
1824 |
the near future). |
|
1825 |
For depth1 masks: each pixel of the image where a corresponding |
|
1826 |
1-bit is present in the mask will be drawn; |
|
1827 |
0-bit mask pixels lead to transparent pixels. |
|
1828 |
||
1829 |
For depth8 masks: (future): |
|
1830 |
each pixel specifies the alpha value (0..255), |
|
1831 |
which specifies the transparency of that pixel. |
|
1832 |
0 means completely transparent, 255 means completely |
|
1833 |
opaque. The 1-plane mask is a special case of this, |
|
1834 |
interpreting a 0 as a 0 alpha value and 1's as an |
|
1835 |
alpha value of 255." |
|
1836 |
||
1837 |
mask := anotherImage |
|
1838 |
||
1839 |
"Created: 27.6.1996 / 17:45:22 / cg" |
|
1840 |
! |
|
1841 |
||
592 | 1842 |
monochromeId |
1843 |
"return the id of the monochrome image on the device. |
|
1844 |
Return nil, if the image is unassigned." |
|
1845 |
||
1846 |
monoDeviceForm isNil ifTrue:[^ nil]. |
|
1847 |
^ monoDeviceForm id |
|
1848 |
! |
|
1849 |
||
1850 |
palette |
|
1851 |
"return the colormap; ST-80 compatibility" |
|
1852 |
||
1853 |
^ colorMap |
|
1854 |
! |
|
1855 |
||
1856 |
palette:aColormap |
|
1857 |
"set the colormap; ST-80 compatibility" |
|
1858 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1859 |
self colorMap:aColormap |
592 | 1860 |
|
1861 |
"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
|
1862 |
"Modified: 8.6.1996 / 09:54:02 / cg" |
592 | 1863 |
! |
1864 |
||
1865 |
photometric |
|
1866 |
"return the photometric, a symbol such as #palette, #rgb etc." |
|
1867 |
||
1868 |
^ photometric |
|
1869 |
! |
|
1870 |
||
1871 |
samplesPerPixel |
|
1872 |
"return the number of samples per pixel in the image. |
|
1873 |
The return value is an array of bits-per-plane." |
|
1874 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1875 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1876 |
^ 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1877 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1878 |
"Modified: 10.6.1996 / 18:03:30 / cg" |
592 | 1879 |
! |
1880 |
||
1881 |
width |
|
1882 |
"return the width of the image" |
|
1883 |
||
1884 |
^ width |
|
1885 |
! ! |
|
1886 |
||
1887 |
!Image methodsFor:'accessing - pixels'! |
|
1888 |
||
0 | 1889 |
at:aPoint |
2 | 1890 |
"retrieve the pixel at aPoint; return a color. |
1891 |
Pixels start at 0@0 for upper left pixel, end at |
|
81 | 1892 |
(width-1)@(height-1) for lower right pixel. |
2 | 1893 |
You should not use this method for image-processing, its |
81 | 1894 |
very slow ... |
1895 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
0 | 1896 |
|
1897 |
^ self atX:aPoint x y:aPoint y |
|
1898 |
! |
|
1899 |
||
283 | 1900 |
at:aPoint put:aColor |
1901 |
"set the pixel at aPoint to aColor. |
|
1902 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1903 |
(width-1)@(height-1) for lower right pixel. |
|
1904 |
You should not use this method for image-processing, its |
|
1905 |
very slow ... |
|
1906 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
1907 |
||
1908 |
^ self atX:aPoint x y:aPoint y put:aColor |
|
1909 |
! |
|
1910 |
||
1911 |
atPoint:aPoint |
|
1912 |
"ST-80 compatibility: return the pixelValue at:aPoint." |
|
1913 |
||
1914 |
^ self valueAtX:aPoint x y:aPoint y |
|
1915 |
! |
|
1916 |
||
1433 | 1917 |
atPoint:aPoint put:aPixelValue |
1918 |
"ST-80 compatibility: set the pixelValue at:aPoint." |
|
1919 |
||
1920 |
^ self atX:aPoint x y:aPoint y putValue:aPixelValue |
|
1921 |
||
1922 |
"Created: 6.3.1997 / 15:24:14 / cg" |
|
1923 |
! |
|
1924 |
||
0 | 1925 |
atX:x y:y |
2 | 1926 |
"retrieve a pixel at x/y; return a color. |
81 | 1927 |
Pixels start at 0@0 for upper left pixel, end at |
1928 |
(width-1)@(height-1) for lower right pixel. |
|
2 | 1929 |
You should not use this method for image-processing, its |
81 | 1930 |
very slow ... |
1931 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 1932 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1933 |
|pixel maxPixel| |
89 | 1934 |
|
1935 |
pixel := self valueAtX:x y:y. |
|
1936 |
photometric == #blackIs0 ifTrue:[ |
|
746 | 1937 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1938 |
^ Color gray:(pixel * (100 / maxPixel)). |
|
89 | 1939 |
]. |
1940 |
photometric == #whiteIs0 ifTrue:[ |
|
746 | 1941 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1942 |
^ Color gray:100 - (pixel * (100 / maxPixel)). |
|
89 | 1943 |
]. |
1944 |
photometric == #palette ifTrue:[ |
|
746 | 1945 |
^ colorMap at:(pixel + 1) |
89 | 1946 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1947 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1948 |
^ self colorFromValue:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1949 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
1950 |
"Modified: 8.6.1996 / 10:53:22 / cg" |
2 | 1951 |
! |
1952 |
||
1953 |
atX:x y:y put:aColor |
|
1954 |
"set the pixel at x/y to aColor. |
|
81 | 1955 |
Pixels start at 0@0 for the upper left pixel, end at |
1956 |
(width-1)@(height-1) for the lower right pixel. |
|
89 | 1957 |
This method checks if the color can be stored in the image. |
1958 |
(i.e. if the receiver is a palette image, the color must be present in there). |
|
1959 |
You should not use this method for image-processing, it is very slow ... |
|
81 | 1960 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
1961 |
||
89 | 1962 |
|pixel maxPixel| |
1963 |
||
1964 |
photometric == #whiteIs0 ifTrue:[ |
|
798 | 1965 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
1966 |
pixel := maxPixel - (aColor brightness * maxPixel) rounded. |
|
89 | 1967 |
] ifFalse:[ |
798 | 1968 |
photometric == #blackIs0 ifTrue:[ |
1969 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
|
1970 |
pixel := (aColor brightness * maxPixel) rounded. |
|
1971 |
] ifFalse:[ |
|
1972 |
photometric ~~ #palette ifTrue:[ |
|
1973 |
self error:'format not supported'. |
|
1974 |
^ nil |
|
1975 |
]. |
|
1976 |
pixel := colorMap indexOf:aColor. |
|
1977 |
pixel == 0 ifTrue:[ |
|
1978 |
" |
|
1979 |
the color to be stored is not in the images colormap |
|
1980 |
" |
|
1981 |
self error:'invalid color - not in colorMap' |
|
1982 |
]. |
|
1983 |
pixel := pixel - 1 |
|
1984 |
] |
|
89 | 1985 |
]. |
1986 |
self atX:x y:y putValue:pixel. |
|
798 | 1987 |
|
1988 |
"Modified: 7.6.1996 / 19:17:48 / cg" |
|
81 | 1989 |
! |
1990 |
||
283 | 1991 |
atX:x y:y putValue:aPixelValue |
1992 |
"set the pixel at x/y to aPixelValue. |
|
1993 |
The interpretation of the pixelValue depends on the photometric |
|
1994 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1995 |
Pixels start at 0@0 for the upper left pixel, end at |
|
1996 |
(width-1) @ (height-1) for the lower right pixel. |
|
1997 |
You should not use this method for image-processing, its |
|
1998 |
very slow ... |
|
1999 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2000 |
||
2001 |
^ self subclassResponsibility |
|
2002 |
! |
|
2003 |
||
2004 |
bits |
|
2005 |
"return the raw image data; depending on the photometric, |
|
2006 |
this has to be interpreted as monochrome, greyscale, |
|
2007 |
palette or rgb data. It is also packed to be dense, so |
|
2008 |
a 4 bitPerSample palette image will store 2 pixels per byte." |
|
2009 |
||
2010 |
^ bytes |
|
2011 |
! |
|
2012 |
||
2013 |
data |
|
2014 |
"for backward compatibility - will vanish" |
|
2015 |
||
2016 |
^ bytes |
|
2017 |
! |
|
2018 |
||
2019 |
data:aByteArray |
|
2020 |
"for backward compatibility - will vanish" |
|
2021 |
||
2022 |
bytes := aByteArray |
|
2023 |
! |
|
2024 |
||
1433 | 2025 |
rowAt:rowIndex putAll:pixelArray |
2026 |
"replace a single rows bits from bits in the argument; |
|
2027 |
Notice: row indexing starts at 0. |
|
2028 |
This is a slow fallBack method, which works with any depth; |
|
2029 |
concrete image subclasses should redefine this for more performance." |
|
2030 |
||
2031 |
|bytesPerRow x| |
|
2032 |
||
2033 |
0 to:(width-1) do:[:col | |
|
2034 |
self atX:col y:rowIndex putValue:(pixelArray at:(col + 1)) |
|
2035 |
]. |
|
2036 |
^ pixelArray |
|
2037 |
||
2038 |
"Created: 6.3.1997 / 15:24:09 / cg" |
|
2039 |
! |
|
2040 |
||
81 | 2041 |
valueAt:aPoint |
2042 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
2043 |
Pixels start at 0@0 for upper left pixel, end at |
|
2044 |
width-1@height-1 for lower right pixel. |
|
2045 |
The returned numbers interpretation depends on the photometric |
|
2046 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
2 | 2047 |
You should not use this method for image-processing, its |
81 | 2048 |
very slow ... |
2049 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2050 |
||
2051 |
^ self valueAtX:aPoint x y:aPoint y |
|
2052 |
! |
|
2053 |
||
2054 |
valueAtX:x y:y |
|
2055 |
"retrieve the pixelValue at aPoint; return an integer number. |
|
2056 |
Pixels start at 0/0 for upper left pixel, and end at |
|
2057 |
width-1@height-1 for lower right pixel. |
|
2058 |
The returned numbers interpretation depends on the photometric |
|
2059 |
and the colormap. (see also Image>>at: and Image>>atX:y:) |
|
2060 |
You should not use this method for image-processing of |
|
2061 |
big images, its very slow ... |
|
2062 |
(it is meant to access individual pixels - for example, in a bitmap editor)" |
|
2 | 2063 |
|
2064 |
^ self subclassResponsibility |
|
592 | 2065 |
! ! |
2066 |
||
2067 |
!Image methodsFor:'accessing - private'! |
|
2068 |
||
2069 |
bits:aByteArray |
|
2070 |
"set the raw data. |
|
2071 |
||
2072 |
This interface is only to be used when initializing |
|
2073 |
instances or by image readers. Calling for a change of an |
|
2074 |
existing image may confuse later pixel interpretation." |
|
2075 |
||
2076 |
bytes := aByteArray |
|
2077 |
||
2078 |
"Modified: 23.4.1996 / 11:08:28 / cg" |
|
2 | 2079 |
! |
2080 |
||
592 | 2081 |
bitsPerSample:aNumber |
2082 |
"set the number of bits per sample. |
|
2083 |
||
2084 |
This interface is only to be used when initializing |
|
2085 |
instances or by image readers. Calling for a change of an |
|
2086 |
existing image may confuse later pixel interpretation." |
|
2087 |
||
2088 |
bitsPerSample := aNumber |
|
2089 |
||
2090 |
"Modified: 23.4.1996 / 11:08:31 / cg" |
|
2091 |
! |
|
2092 |
||
2093 |
depth:d |
|
2094 |
"set the depth of the image. |
|
2095 |
||
2096 |
This interface is only to be used when initializing |
|
2097 |
instances or by image readers. Calling for a change of an |
|
2098 |
existing image may confuse later pixel interpretation." |
|
2099 |
||
1362
454d644f6ff7
set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
2100 |
depth := self depth. |
454d644f6ff7
set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
2101 |
bitsPerPixel := d. |
592 | 2102 |
d == 24 ifTrue:[ |
2103 |
samplesPerPixel := 3. |
|
2104 |
bitsPerSample := #(8 8 8) |
|
2105 |
] ifFalse:[ |
|
2106 |
samplesPerPixel := 1. |
|
2107 |
bitsPerSample := Array with:d |
|
2108 |
] |
|
2109 |
||
1362
454d644f6ff7
set depth & bitsPerPixel for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
1349
diff
changeset
|
2110 |
"Modified: 20.2.1997 / 14:39:10 / cg" |
592 | 2111 |
! |
2112 |
||
2113 |
extent:anExtent |
|
2114 |
"set the images extent. |
|
2115 |
||
2116 |
This interface is only to be used when initializing |
|
2117 |
instances or by image readers. Calling for a change of an |
|
2118 |
existing image may confuse later pixel interpretation." |
|
2119 |
||
2120 |
width := anExtent x. |
|
2121 |
height := anExtent y |
|
2122 |
||
2123 |
"Modified: 23.4.1996 / 11:08:38 / cg" |
|
2124 |
! |
|
2125 |
||
2126 |
height:aNumber |
|
2127 |
"set the height of the image. |
|
2128 |
||
2129 |
This interface is only to be used when initializing |
|
2130 |
instances or by image readers. Calling for a change of an |
|
2131 |
existing image may confuse later pixel interpretation." |
|
2132 |
||
2133 |
height := aNumber |
|
2134 |
||
2135 |
"Modified: 23.4.1996 / 11:08:40 / cg" |
|
2136 |
! |
|
2137 |
||
2138 |
photometric:aSymbol |
|
2139 |
"set the photometric interpretation of the pixel values. |
|
2140 |
The argument, aSymbol is one of: |
|
2141 |
#blackIs0, #whiteIs0, #palette, #rgb |
|
2142 |
See TIFF documentation, from which the photometric concept is borrowed. |
|
2143 |
||
2144 |
This interface is only to be used when initializing |
|
2145 |
instances or by image readers. Calling for a change of an |
|
2146 |
existing image may confuse later pixel interpretation." |
|
2147 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2148 |
|b| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2149 |
|
798 | 2150 |
photometric := aSymbol. |
2151 |
bitsPerSample isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2152 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2153 |
b := self class imageDepth // 3. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2154 |
bitsPerSample := Array with:b with:b with:b |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2155 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2156 |
bitsPerSample := Array with:(self class imageDepth) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2157 |
]. |
798 | 2158 |
]. |
2159 |
samplesPerPixel isNil ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2160 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2161 |
samplesPerPixel := 3 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2162 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2163 |
samplesPerPixel := 1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2164 |
] |
798 | 2165 |
]. |
2166 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2167 |
"Modified: 10.6.1996 / 18:21:29 / cg" |
592 | 2168 |
! |
2169 |
||
2170 |
samplesPerPixel:aNumber |
|
2171 |
"set the array of samples per pixel. |
|
2172 |
||
2173 |
This interface is only to be used when initializing |
|
2174 |
instances or by image readers. Calling for a change of an |
|
2175 |
existing image may confuse later pixel interpretation." |
|
2176 |
||
2177 |
samplesPerPixel := aNumber |
|
2178 |
||
2179 |
"Modified: 23.4.1996 / 11:08:45 / cg" |
|
81 | 2180 |
! |
2181 |
||
283 | 2182 |
width:aNumber |
592 | 2183 |
"set the width of the image. |
2184 |
||
2185 |
This interface is only to be used when initializing |
|
2186 |
instances or by image readers. Calling for a change of an |
|
2187 |
existing image may confuse later pixel interpretation." |
|
283 | 2188 |
|
2189 |
width := aNumber |
|
592 | 2190 |
|
2191 |
"Modified: 23.4.1996 / 11:08:48 / cg" |
|
100 | 2192 |
! |
2193 |
||
283 | 2194 |
width:w height:h |
592 | 2195 |
"set the width and height of the image. |
2196 |
||
2197 |
This interface is only to be used when initializing |
|
2198 |
instances or by image readers. Calling for a change of an |
|
2199 |
existing image may confuse later pixel interpretation." |
|
283 | 2200 |
|
2201 |
width := w. |
|
2202 |
height := h |
|
592 | 2203 |
|
2204 |
"Modified: 23.4.1996 / 11:08:53 / cg" |
|
81 | 2205 |
! |
2 | 2206 |
|
283 | 2207 |
width:w height:h depth:d |
592 | 2208 |
"set the width, height and depth of the image. |
2209 |
||
2210 |
This interface is only to be used when initializing |
|
2211 |
instances or by image readers. Calling for a change of an |
|
2212 |
existing image may confuse later pixel interpretation." |
|
283 | 2213 |
|
2214 |
width := w. |
|
2215 |
height := h. |
|
2216 |
self depth:d. |
|
592 | 2217 |
|
2218 |
"Modified: 23.4.1996 / 11:08:56 / cg" |
|
89 | 2219 |
! |
2220 |
||
283 | 2221 |
width:w height:h depth:d fromArray:bits |
592 | 2222 |
"set the width, height, depth and pixels of the image. |
2223 |
||
2224 |
This interface is only to be used when initializing |
|
2225 |
instances or by image readers. Calling for a change of an |
|
2226 |
existing image may confuse later pixel interpretation." |
|
283 | 2227 |
|
2228 |
width := w. |
|
2229 |
height := h. |
|
2230 |
self depth:d. |
|
2231 |
bytes := bits |
|
592 | 2232 |
|
2233 |
"Modified: 23.4.1996 / 11:08:59 / cg" |
|
2234 |
! |
|
2235 |
||
1433 | 2236 |
width:w height:h depth:d palette:aColormap |
2237 |
"set the width, height and depth of the image. |
|
2238 |
||
2239 |
This interface is only to be used when initializing |
|
2240 |
instances or by image readers. Calling for a change of an |
|
2241 |
existing image may confuse later pixel interpretation." |
|
2242 |
||
2243 |
width := w. |
|
2244 |
height := h. |
|
2245 |
self depth:d. |
|
2246 |
colorMap := aColormap. |
|
2247 |
aColormap notNil ifTrue:[ |
|
2248 |
photometric := #palette |
|
2249 |
] |
|
2250 |
||
2251 |
"Modified: 23.4.1996 / 11:08:56 / cg" |
|
2252 |
"Created: 6.3.1997 / 15:23:57 / cg" |
|
2253 |
! |
|
2254 |
||
592 | 2255 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels |
2256 |
"set all relevant internal state of the image. |
|
2257 |
||
2258 |
This interface is only to be used when initializing |
|
2259 |
instances or by image readers. Calling for a change of an |
|
2260 |
existing image may confuse later pixel interpretation." |
|
2261 |
||
894
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2262 |
^ self |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2263 |
width:w |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2264 |
height:h |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2265 |
photometric:p |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2266 |
samplesPerPixel:spp |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2267 |
bitsPerSample:bps |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2268 |
colorMap:cm |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2269 |
bits:pixels |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2270 |
mask:nil |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2271 |
|
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2272 |
"Modified: 20.6.1996 / 17:10:24 / cg" |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2273 |
! |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2274 |
|
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2275 |
width:w height:h photometric:p samplesPerPixel:spp bitsPerSample:bps colorMap:cm bits:pixels mask:m |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2276 |
"set all relevant internal state of the image. |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2277 |
|
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2278 |
This interface is only to be used when initializing |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2279 |
instances or by image readers. Calling for a change of an |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2280 |
existing image may confuse later pixel interpretation." |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2281 |
|
592 | 2282 |
width := w. |
2283 |
height := h. |
|
2284 |
photometric := p. |
|
2285 |
samplesPerPixel := spp. |
|
2286 |
bitsPerSample := bps. |
|
2287 |
colorMap := cm. |
|
2288 |
bytes := pixels. |
|
894
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2289 |
mask := m. |
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2290 |
|
592 | 2291 |
"Modified: 23.4.1996 / 11:09:02 / cg" |
894
1041c0edbd35
prepare to read mask/alpha channel
Claus Gittinger <cg@exept.de>
parents:
891
diff
changeset
|
2292 |
"Created: 20.6.1996 / 17:09:53 / cg" |
0 | 2293 |
! ! |
2294 |
||
283 | 2295 |
!Image methodsFor:'binary storage'! |
2296 |
||
2297 |
readBinaryContentsFrom: stream manager: manager |
|
2298 |
"read a binary representation of an image from stream. |
|
2299 |
Redefined to flush any device data." |
|
2300 |
||
2301 |
super readBinaryContentsFrom: stream manager: manager. |
|
2302 |
device := nil. |
|
2303 |
deviceForm := nil. |
|
2304 |
monoDeviceForm := nil. |
|
2305 |
fullColorDeviceForm := nil. |
|
0 | 2306 |
! |
2307 |
||
283 | 2308 |
storeBinaryDefinitionOn: stream manager: manager |
2309 |
"store a binary representation of the receiver on stream. |
|
592 | 2310 |
This is an internal interface for binary storage mechanism. |
283 | 2311 |
Redefined to not store the device form (which is recreated at |
2312 |
load time anyway)" |
|
2313 |
||
2314 |
|tDevice tDeviceForm tMonoDeviceForm tFullColorDeviceForm| |
|
2315 |
||
2316 |
tDevice := device. |
|
2317 |
tDeviceForm := deviceForm. |
|
2318 |
tMonoDeviceForm := monoDeviceForm. |
|
2319 |
tFullColorDeviceForm := fullColorDeviceForm. |
|
2320 |
||
2321 |
device := nil. |
|
2322 |
deviceForm := nil. |
|
2323 |
monoDeviceForm := nil. |
|
2324 |
fullColorDeviceForm := nil. |
|
2325 |
||
2326 |
super storeBinaryDefinitionOn: stream manager: manager. |
|
2327 |
||
2328 |
device := tDevice. |
|
2329 |
deviceForm := tDeviceForm. |
|
2330 |
monoDeviceForm := tMonoDeviceForm. |
|
2331 |
fullColorDeviceForm := tFullColorDeviceForm. |
|
592 | 2332 |
|
2333 |
"Modified: 23.4.1996 / 09:30:50 / cg" |
|
0 | 2334 |
! ! |
2335 |
||
2336 |
!Image methodsFor:'converting'! |
|
2337 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2338 |
asBurkesDitheredMonochromeImage |
837 | 2339 |
"return a burkes dithered monochrome image from the receiver image. |
2340 |
Depending on the images contents, this may or may not look better than |
|
2341 |
a floyd-steinberg dithered image. |
|
2342 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
2343 |
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
|
2344 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2345 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2346 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2347 |
monoBits := self burkesDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2348 |
^ 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
|
2349 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2350 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2351 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2352 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2353 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2354 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2355 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2356 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2357 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2358 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2359 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2360 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2361 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2362 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2363 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2364 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2365 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2366 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2367 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2368 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2369 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2370 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2371 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2372 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2373 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2374 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2375 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2376 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2377 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2378 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2379 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2380 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2381 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2382 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2383 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2384 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2385 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2386 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2387 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2388 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2389 |
"Created: 10.6.1996 / 12:34:44 / cg" |
837 | 2390 |
"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
|
2391 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2392 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2393 |
asErrorDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2394 |
"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
|
2395 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2396 |
DitherAlgorithm == #burkes ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2397 |
^ self asBurkesDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2398 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2399 |
DitherAlgorithm == #stevensonArce ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2400 |
^ self asStevensonArgceDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2401 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2402 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2403 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2404 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2405 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2406 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2407 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2408 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2409 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2410 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2411 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2412 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2413 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2414 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2415 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2416 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2417 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2418 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2419 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2420 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2421 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2422 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2423 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2424 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2425 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2426 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2427 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2428 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2429 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2430 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2431 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2432 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2433 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2434 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2435 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2436 |
i asErrorDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2437 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2438 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2439 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2440 |
"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
|
2441 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2442 |
|
854 | 2443 |
asFloydSteinbergDitheredDepth8FormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2444 |
"return a floyd-steinberg dithered pseudoForm from the palette picture. |
|
2445 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
|
2446 |
colors assigned to aDevice, such as the preallocated colors of the |
|
2447 |
Color class. |
|
2448 |
By passing the ditherColors as extra array, this method can |
|
2449 |
also be used to dither an 8bit image into a smaller number of colors, |
|
2450 |
for example to create dithered Depth4Images from Depth8Images." |
|
2451 |
||
2452 |
|pseudoBits f has8BitImage deviceDepth |
|
2453 |
map | |
|
2454 |
||
2455 |
deviceDepth := aDevice depth. |
|
2456 |
deviceDepth == 8 ifTrue:[ |
|
2457 |
has8BitImage := true. |
|
2458 |
] ifFalse:[ |
|
2459 |
has8BitImage := false. |
|
2460 |
aDevice supportedImageFormats do:[:fmt | |
|
2461 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
2462 |
has8BitImage := true. |
|
2463 |
] |
|
2464 |
] |
|
2465 |
]. |
|
2466 |
has8BitImage ifFalse:[^ nil]. |
|
2467 |
||
2468 |
pseudoBits := self floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue. |
|
2469 |
pseudoBits isNil ifTrue:[^ nil]. |
|
2470 |
||
2471 |
f := Form width:width height:height depth:deviceDepth on:aDevice. |
|
2472 |
f isNil ifTrue:[^ nil]. |
|
2473 |
||
2474 |
"/ |
|
2475 |
"/ have to create a funny colorMap, where |
|
2476 |
"/ color at:index == color colorId:index |
|
2477 |
"/ |
|
2478 |
map := Array new:256. |
|
2479 |
fixColors do:[:clr | |
|
2480 |
map at:clr colorId + 1 put:clr |
|
2481 |
]. |
|
2482 |
f colorMap:map. |
|
2483 |
f initGC. |
|
2484 |
f bits:pseudoBits. |
|
2485 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
|
2486 |
width:width height:height |
|
2487 |
x:0 y:0 |
|
2488 |
into:(f id) x:0 y:0 |
|
2489 |
width:width height:height with:(f gcId). |
|
2490 |
^ f |
|
2491 |
||
2492 |
" |
|
2493 |
example: |
|
2494 |
color reduction from Depth8 to Depth4 (dithering) can be done by: |
|
2495 |
||
2496 |
|img8 reducedImg8 img4 map form| |
|
2497 |
||
2498 |
map := #( |
|
2499 |
(0 0 0) |
|
2500 |
(0 0 100) |
|
2501 |
(0 50 0) |
|
2502 |
(0 50 100) |
|
2503 |
(0 100 0) |
|
2504 |
(0 100 100) |
|
2505 |
(100 0 0) |
|
2506 |
(100 0 100) |
|
2507 |
(100 50 0) |
|
2508 |
(100 50 100) |
|
2509 |
(100 100 0) |
|
2510 |
(100 100 100)) collect:[:rgb | (Color red:(rgb at:1) |
|
2511 |
green:(rgb at:2) |
|
2512 |
blue:(rgb at:3)) on:Display]. |
|
2513 |
||
2514 |
img8 := Image fromFile:'bitmaps/bf.im8'. |
|
2515 |
form := img8 paletteImageAsDitheredPseudoFormOn:Display |
|
2516 |
colors:map |
|
2517 |
nRed:2 |
|
2518 |
nGreen:3 |
|
2519 |
nBlue:2. |
|
2520 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
|
2521 |
img4 := Depth4Image fromImage:img8. |
|
2522 |
" |
|
2523 |
||
2524 |
"Modified: 14.6.1996 / 16:52:34 / cg" |
|
2525 |
! |
|
2526 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2527 |
asFloydSteinbergDitheredGrayFormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2528 |
"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
|
2529 |
|
1063 | 2530 |
|depth bits| |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2531 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2532 |
depth := aDevice depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2533 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2534 |
"/ for monochrome, there is specialized |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2535 |
"/ monochrome dither code available |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2536 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2537 |
bits := self floydSteinbergDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2538 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2539 |
bits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2540 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2541 |
|
816 | 2542 |
^ 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
|
2543 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2544 |
" |
1063 | 2545 |
|i| |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2546 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2547 |
i := Image fromFile:'bitmaps/claus.gif'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2548 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2549 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2550 |
|
841 | 2551 |
" |
1063 | 2552 |
|i| |
841 | 2553 |
|
2554 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
2555 |
(i asFloydSteinbergDitheredGrayFormOn:Display) inspect |
|
2556 |
" |
|
2557 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2558 |
"Created: 10.6.1996 / 14:11:39 / cg" |
841 | 2559 |
"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
|
2560 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2561 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2562 |
asFloydSteinbergDitheredGrayImageDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2563 |
"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
|
2564 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2565 |
|ditheredBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2566 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2567 |
depth == 1 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2568 |
^ self asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2569 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2570 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2571 |
ditheredBits := self floydSteinbergDitheredBitsDepth:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2572 |
^ (self class implementorForDepth:depth) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2573 |
width:width height:height fromArray:ditheredBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2574 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2575 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2576 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2577 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2578 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2579 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2580 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2581 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2582 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2583 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2584 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2585 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2586 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2587 |
|
829 | 2588 |
i := Depth24Image width:4 height:1 |
2589 |
fromArray:#[ |
|
2590 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
2591 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
2592 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 |
|
2593 |
16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00 16rFF 16r00 16r00]. |
|
2594 |
i := i magnifiedBy:4@1. |
|
2595 |
i inspect. |
|
2596 |
||
2597 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
2598 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
2599 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
2600 |
" |
|
2601 |
||
2602 |
" |
|
2603 |
|i| |
|
2604 |
||
2605 |
i := Depth24Image width:4 height:6 |
|
2606 |
fromArray:#[ |
|
2607 |
16r00 16r00 16r00 16r00 16r00 16r80 16r00 16r00 16rff 16r00 16r80 16r00 |
|
2608 |
16r00 16r80 16r80 16r00 16rFF 16r00 16r00 16rFF 16r80 16r00 16rFF 16rFF |
|
2609 |
16r80 16r00 16r00 16r80 16r00 16r80 16r80 16r00 16rff 16r80 16r80 16r00 |
|
2610 |
16r80 16r80 16r80 16r80 16rFF 16r00 16r80 16rFF 16r80 16r80 16rFF 16rFF |
|
2611 |
16rFF 16r00 16r00 16rFF 16r00 16r80 16rFF 16r00 16rff 16rFF 16r80 16r00 |
|
2612 |
16rFF 16r80 16r80 16rFF 16rFF 16r00 16rFF 16rFF 16r80 16rFF 16rFF 16rFF]. |
|
2613 |
i := i magnifiedBy:30. |
|
2614 |
i inspect. |
|
2615 |
||
2616 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
2617 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
2618 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
2619 |
" |
|
2620 |
" |
|
2621 |
|i| |
|
2622 |
||
2623 |
i := Image fromFile:'granite.tiff'. |
|
2624 |
i inspect. |
|
2625 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
|
2626 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
|
2627 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
|
2628 |
" |
|
2629 |
||
2630 |
" |
|
2631 |
|i| |
|
2632 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2633 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2634 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2635 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2636 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2637 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2638 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2639 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2640 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2641 |
|i| |
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 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2644 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2645 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2646 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2647 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2648 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2649 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2650 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2651 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2652 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2653 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2654 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2655 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2656 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2657 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2658 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2659 |
"Created: 10.6.1996 / 12:33:47 / cg" |
829 | 2660 |
"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
|
2661 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2662 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2663 |
asFloydSteinbergDitheredMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2664 |
"return a dithered moncohrome form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2665 |
|
1063 | 2666 |
|monoBits| |
816 | 2667 |
|
2668 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
|
2669 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2670 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2671 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2672 |
|i f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2673 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2674 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2675 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2676 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2677 |
|
816 | 2678 |
" |
2679 |
|i f| |
|
2680 |
||
2681 |
i := Depth2Image width:8 height:8 |
|
2682 |
fromArray:#[ |
|
2683 |
4r0000 4r0000 |
|
2684 |
4r0000 4r0000 |
|
2685 |
4r1111 4r1111 |
|
2686 |
4r1111 4r1111 |
|
2687 |
4r2222 4r2222 |
|
2688 |
4r2222 4r2222 |
|
2689 |
4r3333 4r3333 |
|
2690 |
4r3333 4r3333 |
|
2691 |
]. |
|
2692 |
(i asFloydSteinbergDitheredMonochromeFormOn:Display) inspect. |
|
2693 |
" |
|
2694 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2695 |
"Created: 10.6.1996 / 14:11:39 / cg" |
816 | 2696 |
"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
|
2697 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2698 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2699 |
asFloydSteinbergDitheredMonochromeImage |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2700 |
"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
|
2701 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2702 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2703 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2704 |
monoBits := self floydSteinbergDitheredMonochromeBits. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2705 |
^ 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
|
2706 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2707 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2708 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2709 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2710 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2711 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2712 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2713 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2714 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2715 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2716 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2717 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2718 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2719 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2720 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2721 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2722 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2723 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2724 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2725 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2726 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2727 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2728 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2729 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2730 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2731 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2732 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2733 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2734 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2735 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2736 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2737 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2738 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2739 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2740 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2741 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2742 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2743 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2744 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2745 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2746 |
"Created: 10.6.1996 / 12:33:47 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2747 |
"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
|
2748 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
2749 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2750 |
asFloydSteinbergDitheredPseudoFormUsing:colors on:aDevice |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2751 |
"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
|
2752 |
using colors in colors for dithering." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2753 |
|
1041 | 2754 |
|pseudoBits pseudoBits8 f has8BitImage deviceDepth |
2755 |
map d | |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2756 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2757 |
deviceDepth := aDevice depth. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2758 |
deviceDepth == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2759 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2760 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2761 |
has8BitImage := false. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2762 |
aDevice supportedImageFormats do:[:fmt | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2763 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2764 |
has8BitImage := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2765 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2766 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2767 |
]. |
1041 | 2768 |
has8BitImage ifFalse:[ |
2769 |
deviceDepth == 4 ifFalse:[^ nil]. |
|
2770 |
||
2771 |
pseudoBits8 := self nfloydSteinbergDitheredDepth8BitsColors:colors. |
|
2772 |
pseudoBits8 isNil ifTrue:[^ nil]. |
|
2773 |
"/ convert to devices depth |
|
2774 |
||
2775 |
pseudoBits := ByteArray new:(width*4+7//8 * height). |
|
2776 |
pseudoBits8 compressPixels:4 width:width height:height into:pseudoBits mapping:nil. |
|
2777 |
d := 4. |
|
2778 |
] ifTrue:[ |
|
2779 |
pseudoBits := self nfloydSteinbergDitheredDepth8BitsColors:colors. |
|
2780 |
pseudoBits isNil ifTrue:[^ nil]. |
|
2781 |
d := 8. |
|
2782 |
]. |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2783 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2784 |
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
|
2785 |
f isNil ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2786 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2787 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2788 |
"/ have to create a funny colorMap, where |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2789 |
"/ color at:index == color colorId:index |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2790 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2791 |
map := Array new:256 withAll:0. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2792 |
colors do:[:clr | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2793 |
clr notNil ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2794 |
map at:clr colorId + 1 put:clr |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2795 |
] |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2796 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2797 |
f colorMap:map. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2798 |
f initGC. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2799 |
f bits:pseudoBits. |
1041 | 2800 |
aDevice drawBits:pseudoBits bitsPerPixel:d depth:deviceDepth |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2801 |
width:width height:height |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2802 |
x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2803 |
into:(f id) x:0 y:0 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2804 |
width:width height:height with:(f gcId). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2805 |
^ f |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2806 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2807 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2808 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2809 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2810 |
i := Image fromFile:'bitmaps/garfield.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2811 |
(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
|
2812 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2813 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2814 |
|i| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2815 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2816 |
i := Image fromFile:'bitmaps/claus.gif'. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2817 |
(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
|
2818 |
" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2819 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2820 |
"Created: 17.6.1996 / 12:13:35 / cg" |
1041 | 2821 |
"Modified: 5.9.1996 / 19:42:57 / cg" |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2822 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
2823 |
|
0 | 2824 |
asFormOn:aDevice |
72 | 2825 |
"get a device form, with best possible approximation. |
2826 |
remember it in case someone asks again." |
|
2827 |
||
1041 | 2828 |
|form visual| |
72 | 2829 |
|
2830 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
|
0 | 2831 |
|
901 | 2832 |
mask notNil ifTrue:[ |
2833 |
mask := mask on:aDevice |
|
2834 |
]. |
|
2835 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2836 |
aDevice depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2837 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2838 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2839 |
|
1041 | 2840 |
((visual := aDevice visualType) == #StaticGray) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2841 |
^ self asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2842 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2843 |
|
1041 | 2844 |
(visual == #PseudoColor |
2845 |
or:[visual == #StaticColor]) ifTrue:[ |
|
873 | 2846 |
form := self asPseudoFormQuickOn:aDevice. |
2847 |
form notNil ifTrue:[ |
|
2848 |
^ form |
|
2849 |
]. |
|
2850 |
]. |
|
2851 |
||
0 | 2852 |
(photometric == #palette) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2853 |
form := self paletteImageAsFormOn:aDevice |
72 | 2854 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2855 |
(photometric == #rgb) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2856 |
form := self rgbImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2857 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2858 |
form := self greyImageAsFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2859 |
] |
0 | 2860 |
]. |
2861 |
||
72 | 2862 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2863 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2864 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2865 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2866 |
deviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2867 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2868 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2869 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2870 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2871 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2872 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2873 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2874 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2875 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2876 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2877 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2878 |
] |
0 | 2879 |
]. |
2880 |
||
72 | 2881 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2882 |
|
1041 | 2883 |
"Modified: 10.7.1996 / 21:55:44 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2884 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2885 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2886 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2887 |
"get a gray device form" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2888 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2889 |
^ self asGrayFormOn:aDevice dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2890 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2891 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2892 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2893 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2894 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2895 |
(i asGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2896 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2897 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2898 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2899 |
"Created: 10.6.1996 / 18:44:42 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2900 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2901 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2902 |
asGrayFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2903 |
"get a greyscale device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2904 |
|
1063 | 2905 |
|depth| |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2906 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2907 |
depth := aDevice depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2908 |
depth == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2909 |
^ self asMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2910 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2911 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2912 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2913 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2914 |
^ self asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2915 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2916 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2917 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2918 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2919 |
^ self asOrderedDitheredGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2920 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2921 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2922 |
^ self asFloydSteinbergDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2923 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2924 |
"Created: 10.6.1996 / 18:42:01 / cg" |
852 | 2925 |
"Modified: 14.6.1996 / 15:17:28 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2926 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2927 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2928 |
asGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2929 |
"get a gray image from the receiver" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2930 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2931 |
^ self asGrayImageDepth:depth dither:DitherAlgorithm. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2932 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2933 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2934 |
|i| |
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 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2937 |
(i asGrayFormOn:Display) inspect. |
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 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2940 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2941 |
"Created: 10.6.1996 / 19:07:08 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2942 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2943 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2944 |
asGrayImageDepth:depth dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2945 |
"get a greyscale image, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2946 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2947 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2948 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2949 |
^ self asThresholdGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2950 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2951 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2952 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2953 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2954 |
^ self asOrderedDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2955 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2956 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2957 |
^ self asFloydSteinbergDitheredGrayImageDepth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2958 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2959 |
"Created: 10.6.1996 / 19:08:21 / cg" |
0 | 2960 |
! |
2961 |
||
2962 |
asMonochromeFormOn:aDevice |
|
2963 |
"get a monochrome device form" |
|
2964 |
||
72 | 2965 |
|form| |
2966 |
||
2967 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ monoDeviceForm]. |
|
2968 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2969 |
form := self asMonochromeFormOn:aDevice dither:DitherAlgorithm. |
0 | 2970 |
|
72 | 2971 |
(device isNil or:[aDevice == device]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2972 |
"remember this form in the receiver ..." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2973 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2974 |
form notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2975 |
monoDeviceForm := form. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2976 |
device isNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2977 |
device := aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2978 |
Lobby register:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2979 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2980 |
Lobby registerChange:self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2981 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2982 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2983 |
can save space, by not keeping the images data-bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2984 |
twice (here and in the device form) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2985 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2986 |
form forgetBits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2987 |
] |
0 | 2988 |
]. |
2989 |
||
72 | 2990 |
^ form |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2991 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2992 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2993 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2994 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2995 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2996 |
(i asMonochromeFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2997 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2998 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
2999 |
"Modified: 10.6.1996 / 17:39:30 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3000 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3001 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3002 |
asMonochromeFormOn:aDevice dither:aDitherAlgorithm |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3003 |
"get a monochrome device form, using aDitherAlgorithm." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3004 |
|
1063 | 3005 |
|monoBits| |
813
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 |
(aDitherAlgorithm isNil |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3008 |
or:[aDitherAlgorithm == #threshold]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3009 |
^ self asThresholdMonochromeFormOn:aDevice |
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 |
aDitherAlgorithm == #burkes ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3013 |
monoBits := self burkesDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3014 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3015 |
aDitherAlgorithm == #stevensonArce ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3016 |
monoBits := self stevensonArceDitheredMonochromeBits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3017 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3018 |
(aDitherAlgorithm == #pattern |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3019 |
or:[aDitherAlgorithm == #ordered]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3020 |
^ self asOrderedDitheredGrayFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3021 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3022 |
^ self asFloydSteinbergDitheredMonochromeFormOn:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3023 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3024 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3025 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3026 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3027 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3028 |
"/ make its pixel interpretation correct for the device |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3029 |
"/ |
816 | 3030 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
3031 |
||
3032 |
"Modified: 10.6.1996 / 20:18:05 / cg" |
|
89 | 3033 |
! |
3034 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3035 |
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
|
3036 |
"return a nearest paint pseudoForm from the palette picture. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3037 |
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
|
3038 |
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
|
3039 |
Color class. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3040 |
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
|
3041 |
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
|
3042 |
for example to create dithered Depth4Images from Depth8Images." |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3043 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3044 |
|pseudoBits f has8BitImage deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3045 |
map | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3046 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3047 |
deviceDepth := aDevice depth. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3048 |
deviceDepth == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3049 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3050 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3051 |
has8BitImage := false. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3052 |
aDevice supportedImageFormats do:[:fmt | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3053 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3054 |
has8BitImage := true. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3055 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3056 |
] |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3057 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3058 |
has8BitImage ifFalse:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3059 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3060 |
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
|
3061 |
pseudoBits isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3062 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3063 |
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
|
3064 |
f isNil ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3065 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3066 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3067 |
"/ have to create a funny colorMap, where |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3068 |
"/ color at:index == color colorId:index |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3069 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3070 |
map := Array new:256. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3071 |
fixColors do:[:clr | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3072 |
map at:clr colorId + 1 put:clr |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3073 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3074 |
f colorMap:map. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3075 |
f initGC. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3076 |
f bits:pseudoBits. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3077 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3078 |
width:width height:height |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3079 |
x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3080 |
into:(f id) x:0 y:0 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3081 |
width:width height:height with:(f gcId). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3082 |
^ f |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3083 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3084 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3085 |
example: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3086 |
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
|
3087 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3088 |
|img8 reducedImg8 img4 map form| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3089 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3090 |
map := #( |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3091 |
(0 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3092 |
(0 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3093 |
(0 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3094 |
(0 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3095 |
(0 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3096 |
(0 100 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3097 |
(100 0 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3098 |
(100 0 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3099 |
(100 50 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3100 |
(100 50 100) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3101 |
(100 100 0) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3102 |
(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
|
3103 |
green:(rgb at:2) |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3104 |
blue:(rgb at:3)) on:Display]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3105 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3106 |
img8 := Image fromFile:'bitmaps/claus.gif'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3107 |
form := img8 asNearestPaintDepth8FormOn:Display |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3108 |
colors:map |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3109 |
nRed:2 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3110 |
nGreen:3 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3111 |
nBlue:2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3112 |
img8 := Depth8Image fromForm:form. 'dithered version of original image'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3113 |
img4 := Depth4Image fromImage:img8. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3114 |
" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3115 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3116 |
"Created: 17.6.1996 / 18:47:46 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3117 |
"Modified: 17.6.1996 / 18:52:47 / cg" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3118 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
3119 |
|
808 | 3120 |
asOrderedDitheredGrayFormOn:aDevice |
3121 |
"return a dithered depth-x grey form from the receiver image. |
|
3122 |
Uses an 8x8 dithermatrix." |
|
3123 |
||
1063 | 3124 |
|depth bits| |
808 | 3125 |
|
3126 |
depth := aDevice depth. |
|
3127 |
depth == 1 ifTrue:[ |
|
3128 |
"/ for monochrome, there is highly specialized |
|
3129 |
"/ monochrome dither code available |
|
3130 |
||
3131 |
^ self asOrderedDitheredMonochromeFormOn:aDevice |
|
3132 |
]. |
|
3133 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3134 |
bits := self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3135 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
808 | 3136 |
ditherWidth:8 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3137 |
depth:depth. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3138 |
|
816 | 3139 |
^ self makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3140 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3141 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3142 |
|i| |
808 | 3143 |
|
3144 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3145 |
(i asOrderedDitheredGrayFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3146 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3147 |
|
816 | 3148 |
"Modified: 10.6.1996 / 20:10:07 / cg" |
808 | 3149 |
! |
3150 |
||
798 | 3151 |
asOrderedDitheredGrayImageDepth:depth |
3152 |
"return a dithered depth-x grey image from the receiver image. |
|
3153 |
Uses an 8x8 dithermatrix." |
|
3154 |
||
3155 |
|dither| |
|
3156 |
||
3157 |
dither := self class orderedDitherMatrixOfSize:8. |
|
3158 |
||
3159 |
depth == 1 ifTrue:[ |
|
3160 |
"/ for monochrome, there is highly specialized |
|
3161 |
"/ monochrome dither code available |
|
3162 |
||
3163 |
^ Depth1Image |
|
3164 |
width:width |
|
3165 |
height:height |
|
3166 |
fromArray:( |
|
3167 |
self |
|
3168 |
orderedDitheredMonochromeBitsWithDitherMatrix:dither |
|
3169 |
ditherWidth:8) |
|
3170 |
]. |
|
3171 |
||
3172 |
^ (self class implementorForDepth:depth) |
|
3173 |
width:width |
|
3174 |
height:height |
|
3175 |
fromArray:( |
|
3176 |
self |
|
3177 |
orderedDitheredBitsWithDitherMatrix:dither |
|
3178 |
ditherWidth:8 |
|
3179 |
depth:depth) |
|
3180 |
||
3181 |
" |
|
3182 |
|i i1 i2 i4 i8| |
|
3183 |
||
3184 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3185 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
3186 |
i1 inspect. |
|
3187 |
||
3188 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
3189 |
i2 inspect. |
|
3190 |
||
3191 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
3192 |
i4 inspect. |
|
3193 |
||
3194 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
3195 |
i8 inspect. |
|
3196 |
" |
|
3197 |
||
3198 |
" |
|
3199 |
|i i1 i2 i4 i8| |
|
3200 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3201 |
i1 := i asOrderedDitheredGrayImageDepth:1. |
|
3202 |
i1 inspect. |
|
3203 |
||
3204 |
i2 := i asOrderedDitheredGrayImageDepth:2. |
|
3205 |
i2 inspect. |
|
3206 |
||
3207 |
i4 := i asOrderedDitheredGrayImageDepth:4. |
|
3208 |
i4 inspect. |
|
3209 |
||
3210 |
i8 := i asOrderedDitheredGrayImageDepth:8. |
|
3211 |
i8 inspect. |
|
800 | 3212 |
|
3213 |
i2 := i8 asOrderedDitheredGrayImageDepth:2. |
|
3214 |
i2 inspect. |
|
798 | 3215 |
" |
3216 |
||
3217 |
"Created: 7.6.1996 / 18:03:54 / cg" |
|
800 | 3218 |
"Modified: 7.6.1996 / 19:41:59 / cg" |
798 | 3219 |
! |
3220 |
||
3221 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
3222 |
"return a dithered monochrome form from the grey image. |
|
3223 |
Uses a 4x4 dithermatrix." |
|
3224 |
||
3225 |
"/ 4x4 seems a good comprimize between: |
|
3226 |
"/ number of grey levels (8x8 is better) |
|
3227 |
"/ artifacts (4x4 is better) |
|
3228 |
"/ |
|
3229 |
"/ could look at the image and decide upon the number of |
|
3230 |
"/ distinct colors present. Use 8x8 for high-number, |
|
3231 |
"/ 4x4 for small number of colors ... |
|
3232 |
||
3233 |
^ self |
|
3234 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
3235 |
ditherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
3236 |
ditherWidth:4 |
|
3237 |
||
3238 |
"/ ^ self |
|
3239 |
"/ asOrderedDitheredMonochromeFormOn:aDevice |
|
3240 |
"/ ditherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
3241 |
"/ ditherWidth:8 |
|
3242 |
||
3243 |
" |
|
3244 |
|i f| |
|
3245 |
||
3246 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3247 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
3248 |
||
3249 |
||
3250 |
|i f| |
|
3251 |
||
3252 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
3253 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
3254 |
||
3255 |
||
3256 |
|i f| |
|
3257 |
||
3258 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3259 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
3260 |
||
3261 |
||
3262 |
|i f| |
|
3263 |
||
3264 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
3265 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
3266 |
||
3267 |
||
3268 |
|i f| |
|
3269 |
||
3270 |
i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1. |
|
3271 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
3272 |
" |
|
3273 |
||
3274 |
"Created: 7.6.1996 / 14:52:32 / cg" |
|
3275 |
"Modified: 7.6.1996 / 16:37:47 / cg" |
|
3276 |
! |
|
3277 |
||
3278 |
asOrderedDitheredMonochromeFormOn:aDevice ditherMatrix:ditherMatrix ditherWidth:dW |
|
3279 |
"return a dithered monochrome form from the image. |
|
3280 |
Uses the passed ditherMatrix and ditherWidth." |
|
3281 |
||
1063 | 3282 |
|monoBits| |
798 | 3283 |
|
3284 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
816 | 3285 |
^ self makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3286 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3287 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3288 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3289 |
|i| |
798 | 3290 |
|
3291 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3292 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3293 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3294 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3295 |
|i| |
798 | 3296 |
|
3297 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3298 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3299 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3300 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3301 |
|i| |
798 | 3302 |
|
3303 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3304 |
(i asOrderedDitheredMonochromeFormOn:Display) inspect |
798 | 3305 |
" |
3306 |
||
3307 |
"Created: 7.6.1996 / 14:51:42 / cg" |
|
816 | 3308 |
"Modified: 10.6.1996 / 20:18:07 / cg" |
798 | 3309 |
! |
3310 |
||
3311 |
asOrderedDitheredMonochromeImage |
|
3312 |
"return a dithered monochrome image from the receiver image. |
|
3313 |
Uses a 4x4 dithermatrix." |
|
3314 |
||
3315 |
"/ 4x4 seems a good comprimize between: |
|
3316 |
"/ number of grey levels (8x8 is better) |
|
3317 |
"/ artifacts (4x4 is better) |
|
3318 |
"/ |
|
3319 |
"/ could look at the image and decide upon the number of |
|
3320 |
"/ distinct colors present. Use 8x8 for high-number, |
|
3321 |
"/ 4x4 for small number of colors ... |
|
3322 |
||
3323 |
^ self |
|
3324 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:4) |
|
3325 |
ditherWidth:4 |
|
3326 |
||
3327 |
"/ ^ self |
|
3328 |
"/ asOrderedDitheredMonochromeImageWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
3329 |
"/ ditherWidth:8 |
|
3330 |
||
3331 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3332 |
|i| |
798 | 3333 |
|
3334 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3335 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3336 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3337 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3338 |
|i| |
798 | 3339 |
|
3340 |
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
|
3341 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3342 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3343 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3344 |
|i| |
798 | 3345 |
|
3346 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3347 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3348 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3349 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3350 |
|i| |
798 | 3351 |
|
3352 |
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
|
3353 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3354 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3355 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3356 |
|i| |
798 | 3357 |
|
3358 |
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
|
3359 |
i asOrderedDitheredMonochromeImage inspect |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3360 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3361 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3362 |
|i| |
798 | 3363 |
|
3364 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3365 |
i asOrderedDitheredMonochromeImage inspect |
798 | 3366 |
" |
3367 |
||
3368 |
"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
|
3369 |
"Modified: 10.6.1996 / 11:15:09 / cg" |
798 | 3370 |
! |
3371 |
||
3372 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
3373 |
"return a dithered monochrome image from the receiver image. |
|
3374 |
Uses the passed ditherMatrix and ditherWidth." |
|
3375 |
||
3376 |
|monoBits| |
|
3377 |
||
3378 |
monoBits := self orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW. |
|
3379 |
^ (Depth1Image width:width height:height fromArray:monoBits) photometric:#blackIs0 |
|
3380 |
||
3381 |
"order-4 dither: |
|
3382 |
||
3383 |
|i| |
|
3384 |
||
3385 |
i := Image fromFile:'garfield.gif'. |
|
3386 |
i |
|
3387 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:4) |
|
3388 |
ditherWidth:4 |
|
3389 |
" |
|
3390 |
||
3391 |
"order-6 dither: |
|
3392 |
||
3393 |
|i| |
|
3394 |
||
3395 |
i := Image fromFile:'garfield.gif'. |
|
3396 |
i |
|
3397 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(Image orderedDitherMatrixOfSize:8) |
|
3398 |
ditherWidth:8 |
|
3399 |
" |
|
3400 |
||
3401 |
||
3402 |
"thresholding at:0.5 (all above 0.5 becomes white): |
|
3403 |
||
3404 |
|i| |
|
3405 |
||
3406 |
i := Image fromFile:'garfield.gif'. |
|
3407 |
i |
|
3408 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:8) |
|
3409 |
ditherWidth:4 |
|
3410 |
" |
|
3411 |
||
3412 |
"thresholding at: 0.25 (all above 0.25 becomes white): |
|
3413 |
||
3414 |
|i| |
|
3415 |
||
3416 |
i := Image fromFile:'garfield.gif'. |
|
3417 |
i |
|
3418 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:3) |
|
3419 |
ditherWidth:4 |
|
3420 |
" |
|
3421 |
||
3422 |
"thresholding at: 0.75 (all above 0.75 becomes white): |
|
3423 |
||
3424 |
|i| |
|
3425 |
||
3426 |
i := Image fromFile:'garfield.gif'. |
|
3427 |
i |
|
3428 |
asOrderedDitheredMonochromeImageWithDitherMatrix:(ByteArray new:16 withAll:11) |
|
3429 |
ditherWidth:4 |
|
3430 |
" |
|
3431 |
||
3432 |
"Modified: 7.6.1996 / 17:23:47 / cg" |
|
3433 |
! |
|
3434 |
||
873 | 3435 |
asPseudoFormQuickOn:aDevice |
3436 |
"return a pseudo-deviceForm from the image. |
|
878 | 3437 |
Fail if any color is not available (i.e. do not dither)." |
873 | 3438 |
|
1063 | 3439 |
|f d dDev temp temp8 bits clr cMap idMap |
878 | 3440 |
nClr "{ Class: SmallInteger }" |
3441 |
usedColors | |
|
873 | 3442 |
|
3443 |
d := self depth. |
|
3444 |
(d == 1 |
|
3445 |
or:[d == 2 |
|
3446 |
or:[d == 4 |
|
3447 |
or:[d == 8]]]) ifFalse:[^ nil]. |
|
3448 |
||
3449 |
"/ |
|
3450 |
"/ see if all of the images colors are representable |
|
3451 |
"/ on the device |
|
3452 |
||
3453 |
bits := self bitsPerPixel. |
|
3454 |
nClr := (1 bitShift:bits). |
|
3455 |
cMap := Array new:nClr. |
|
3456 |
idMap := ByteArray new:nClr. |
|
3457 |
||
3458 |
photometric == #palette ifTrue:[ |
|
3459 |
nClr := nClr min:(colorMap size) |
|
3460 |
]. |
|
3461 |
||
878 | 3462 |
d == 8 ifTrue:[ |
3463 |
usedColors := bytes usedValues. "gets us an array filled with used values" |
|
3464 |
1 to:nClr do:[:pixel | |
|
3465 |
(usedColors includes:(pixel - 1)) ifFalse:[ |
|
3466 |
clr := Color black |
|
3467 |
] ifTrue:[ |
|
3468 |
clr := self colorFromValue:pixel-1. |
|
3469 |
clr := clr exactOn:aDevice. |
|
3470 |
clr isNil ifTrue:[^ nil]. |
|
3471 |
]. |
|
3472 |
cMap at:(pixel) put:clr. |
|
3473 |
idMap at:(pixel) put:(clr colorId). |
|
3474 |
]. |
|
3475 |
] ifFalse:[ |
|
3476 |
1 to:nClr do:[:pixel | |
|
3477 |
clr := self colorFromValue:pixel-1. |
|
3478 |
clr := clr exactOn:aDevice. |
|
3479 |
clr isNil ifTrue:[^ nil]. |
|
3480 |
||
3481 |
cMap at:(pixel) put:clr. |
|
3482 |
idMap at:(pixel) put:(clr colorId). |
|
3483 |
]. |
|
873 | 3484 |
]. |
3485 |
||
3486 |
"/ got all colors; good - simply change depth & translate pixels |
|
3487 |
||
3488 |
dDev := aDevice depth. |
|
3489 |
||
3490 |
(d == 8 and:[dDev == 8]) ifTrue:[ |
|
3491 |
"/ only translate |
|
3492 |
temp := ByteArray uninitializedNew:(width * height). |
|
3493 |
bytes expandPixels:8 "xlate only" |
|
3494 |
width:width |
|
3495 |
height:height |
|
3496 |
into:temp |
|
3497 |
mapping:idMap. |
|
3498 |
] ifFalse:[ |
|
3499 |
||
3500 |
"/ stupid: expandPixels can only handle any-to-8 |
|
3501 |
"/ compressPixels can only handle 8-to-any |
|
3502 |
||
3503 |
d ~~ 8 ifTrue:[ |
|
3504 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
3505 |
||
3506 |
bytes expandPixels:d |
|
3507 |
width:width |
|
3508 |
height:height |
|
3509 |
into:temp8 |
|
3510 |
mapping:idMap. |
|
3511 |
idMap := nil. |
|
3512 |
] ifFalse:[ |
|
3513 |
temp8 := bytes. |
|
3514 |
]. |
|
3515 |
||
3516 |
dDev ~~ 8 ifTrue:[ |
|
3517 |
temp := ByteArray uninitializedNew:((width * dDev + 7) // 8 * height). |
|
3518 |
||
3519 |
temp8 compressPixels:dDev |
|
3520 |
width:width |
|
3521 |
height:height |
|
3522 |
into:temp |
|
3523 |
mapping:idMap. |
|
3524 |
] ifFalse:[ |
|
3525 |
temp := temp8 |
|
3526 |
]. |
|
3527 |
]. |
|
3528 |
||
3529 |
f := Form width:width height:height depth:dDev on:aDevice. |
|
3530 |
f isNil ifTrue:[^ nil]. |
|
3531 |
||
3532 |
f colorMap:cMap. |
|
3533 |
f initGC. |
|
3534 |
||
3535 |
aDevice |
|
3536 |
drawBits:temp |
|
3537 |
depth:dDev |
|
3538 |
width:width |
|
3539 |
height:height |
|
3540 |
x:0 y:0 |
|
3541 |
into:(f id) x:0 y:0 |
|
3542 |
width:width |
|
3543 |
height:height |
|
3544 |
with:(f gcId). |
|
3545 |
||
3546 |
^ f |
|
3547 |
||
3548 |
" |
|
3549 |
( |
|
3550 |
(((Depth4Image |
|
3551 |
width:4 |
|
3552 |
height:4 |
|
3553 |
fromArray:#[ |
|
3554 |
16r01 16r23 |
|
3555 |
16r45 16r67 |
|
3556 |
16r89 16rab |
|
3557 |
16rcd 16ref |
|
3558 |
])) |
|
3559 |
magnifiedBy:30 |
|
3560 |
) |
|
3561 |
asPseudoFormQuickOn:Display |
|
3562 |
) inspect |
|
3563 |
" |
|
3564 |
||
878 | 3565 |
"Modified: 17.6.1996 / 17:31:49 / cg" |
873 | 3566 |
! |
3567 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3568 |
asStevensonArceDitheredMonochromeImage |
837 | 3569 |
"return a stevenson-arce dithered monochrome image from the receiver image. |
3570 |
Depending on the images contents, this may or may not look better than |
|
3571 |
a floyd-steinberg dithered image. |
|
3572 |
Notice, that floyd-steinberg dithering is faster; both because less |
|
3573 |
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
|
3574 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3575 |
|monoBits| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3576 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3577 |
monoBits := self stevensonArceDitheredMonochromeBits. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3578 |
^ (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
|
3579 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3580 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3581 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3582 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3583 |
i := Image fromFile:'garfield.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3584 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3585 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3586 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3587 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3588 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3589 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3590 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3591 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3592 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3593 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3594 |
i := Image fromFile:'claus.gif'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3595 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3596 |
i asFloydSteinbergDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3597 |
i asBurkesDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3598 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3599 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3600 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3601 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3602 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3603 |
|i| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3604 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3605 |
i := Depth4Image |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3606 |
width:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3607 |
height:4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3608 |
fromArray:#[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3609 |
16r01 16r23 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3610 |
16r45 16r67 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3611 |
16r89 16rab |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3612 |
16rcd 16ref |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3613 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3614 |
i := i magnifiedBy:30. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3615 |
i inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3616 |
i asStevensonArceDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3617 |
i asOrderedDitheredMonochromeImage inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3618 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3619 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3620 |
"Created: 10.6.1996 / 12:38:29 / cg" |
837 | 3621 |
"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
|
3622 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3623 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3624 |
asThresholdGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3625 |
"return a thresholded grey form from the receiver image." |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3626 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3627 |
|depth| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3628 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3629 |
(depth := aDevice depth) == 1 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3630 |
^ self asThresholdMonochromeFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3631 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3632 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3633 |
^ self |
816 | 3634 |
makeDeviceGrayPixmapOn:aDevice |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3635 |
depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3636 |
fromArray:(self |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3637 |
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
|
3638 |
ditherWidth:4 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3639 |
depth:depth) |
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 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3642 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3643 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3644 |
i := Image fromFile:'bitmaps/claus.gif'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3645 |
(i asThresholdGrayFormOn:Display) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3646 |
" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3647 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3648 |
"Created: 10.6.1996 / 18:38:31 / cg" |
816 | 3649 |
"Modified: 10.6.1996 / 20:10:26 / cg" |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3650 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3651 |
|
798 | 3652 |
asThresholdGrayImageDepth:depth |
3653 |
"return a thresholded depth-x grey image from the receiver image." |
|
3654 |
||
800 | 3655 |
depth == 1 ifTrue:[ |
3656 |
"/ for monochrome, there is highly specialized |
|
3657 |
"/ monochrome dither code available |
|
3658 |
||
3659 |
^ Depth1Image |
|
3660 |
width:width |
|
3661 |
height:height |
|
3662 |
fromArray:( |
|
3663 |
self |
|
3664 |
orderedDitheredMonochromeBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3665 |
ditherWidth:4) |
|
3666 |
]. |
|
3667 |
||
798 | 3668 |
^ (self class implementorForDepth:depth) |
3669 |
width:width |
|
3670 |
height:height |
|
3671 |
fromArray:( |
|
3672 |
self |
|
3673 |
orderedDitheredBitsWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3674 |
ditherWidth:4 |
|
3675 |
depth:depth) |
|
3676 |
||
3677 |
" |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3678 |
|i| |
798 | 3679 |
|
3680 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3681 |
(i asThresholdGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3682 |
(i asThresholdGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3683 |
(i asThresholdGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3684 |
(i asThresholdGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3685 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3686 |
(i asOrderedDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3687 |
(i asOrderedDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3688 |
(i asOrderedDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3689 |
(i asOrderedDitheredGrayImageDepth:8) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3690 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3691 |
(i asFloydSteinbergDitheredGrayImageDepth:1) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3692 |
(i asFloydSteinbergDitheredGrayImageDepth:2) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3693 |
(i asFloydSteinbergDitheredGrayImageDepth:4) inspect. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
3694 |
(i asFloydSteinbergDitheredGrayImageDepth:8) inspect. |
798 | 3695 |
" |
3696 |
||
3697 |
"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
|
3698 |
"Modified: 10.6.1996 / 14:20:56 / cg" |
798 | 3699 |
! |
3700 |
||
3701 |
asThresholdMonochromeFormOn:aDevice |
|
3702 |
"return a threshold monochrome form from the image." |
|
3703 |
||
3704 |
^ self |
|
3705 |
asOrderedDitheredMonochromeFormOn:aDevice |
|
3706 |
ditherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3707 |
ditherWidth:4 |
|
3708 |
||
3709 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3710 |
|i| |
798 | 3711 |
|
3712 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3713 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3714 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3715 |
|
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 |
|i| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3718 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3719 |
i := (Image fromFile:'bitmaps/a11.ico') magnifiedBy:10. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3720 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3721 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3722 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3723 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3724 |
|i| |
798 | 3725 |
|
3726 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3727 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3728 |
(i asThresholdMonochromeFormOn:Display) inspect |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3729 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3730 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3731 |
|i| |
798 | 3732 |
|
3733 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3734 |
i inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3735 |
(i asThresholdMonochromeFormOn:Display) inspect |
798 | 3736 |
" |
3737 |
||
3738 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3739 |
"Modified: 10.6.1996 / 17:44:29 / cg" |
798 | 3740 |
! |
3741 |
||
3742 |
asThresholdMonochromeImage |
|
3743 |
"return a threshold monochrome image from the image. |
|
3744 |
Threshold means: brightness < 0.5 -> black / otherwise white" |
|
3745 |
||
3746 |
^ self |
|
3747 |
asOrderedDitheredMonochromeImageWithDitherMatrix:#[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8] |
|
3748 |
ditherWidth:4 |
|
3749 |
||
3750 |
" |
|
3751 |
|i i2| |
|
3752 |
||
3753 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3754 |
i2 := i asThresholdMonochromeImage |
|
3755 |
||
3756 |
||
3757 |
|i i2| |
|
3758 |
||
3759 |
i := (Image fromFile:'/cdrom/icons/a/a11.ico') magnifiedBy:10. |
|
3760 |
i2 := i asThresholdMonochromeImage |
|
3761 |
||
3762 |
||
3763 |
|i i2| |
|
3764 |
||
3765 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
3766 |
i2 := i asThresholdMonochromeImage |
|
3767 |
||
3768 |
||
3769 |
|i i2| |
|
3770 |
||
3771 |
i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10. |
|
3772 |
i2 := i asThresholdMonochromeImage |
|
3773 |
" |
|
3774 |
||
3775 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3776 |
"Modified: 7.6.1996 / 17:16:10 / cg" |
|
3777 |
! |
|
3778 |
||
808 | 3779 |
asThresholdMonochromeImage:thresholdBrighness |
3780 |
"return a threshold monochrome image from the image. |
|
3781 |
The argument (0..1) gives the threshold value; |
|
3782 |
Threshold means: brightness < threshold -> black / otherwise white" |
|
3783 |
||
3784 |
|value ditherMatrix| |
|
3785 |
||
3786 |
value := thresholdBrighness * 255. |
|
3787 |
ditherMatrix := ByteArray new:256 withAll:(value truncated). |
|
3788 |
||
3789 |
^ self |
|
3790 |
asOrderedDitheredMonochromeImageWithDitherMatrix:ditherMatrix |
|
3791 |
ditherWidth:16 |
|
3792 |
||
3793 |
" |
|
3794 |
|i| |
|
3795 |
||
3796 |
i := Image width:4 height:4 depth:4 |
|
3797 |
fromArray:#[ 16r01 16r23 |
|
3798 |
16r45 16r67 |
|
3799 |
16r89 16rab |
|
3800 |
16rcd 16ref ]. |
|
3801 |
i := i magnifiedBy:30. |
|
3802 |
i inspect. |
|
3803 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3804 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3805 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3806 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3807 |
(i asThresholdMonochromeImage:1) inspect. |
|
3808 |
" |
|
3809 |
||
3810 |
" |
|
3811 |
|i| |
|
3812 |
||
3813 |
i := Image fromFile:'bitmaps/claus.gif'. |
|
3814 |
i inspect. |
|
3815 |
(i asThresholdMonochromeImage:0.125) inspect. |
|
3816 |
(i asThresholdMonochromeImage:0.25) inspect. |
|
3817 |
(i asThresholdMonochromeImage:0.5) inspect. |
|
3818 |
(i asThresholdMonochromeImage:0.625) inspect. |
|
3819 |
(i asThresholdMonochromeImage:0.75) inspect. |
|
3820 |
" |
|
3821 |
||
3822 |
"Created: 7.6.1996 / 16:15:17 / cg" |
|
3823 |
"Modified: 8.6.1996 / 14:51:57 / cg" |
|
3824 |
! |
|
3825 |
||
283 | 3826 |
fromForm:aForm |
592 | 3827 |
"setup the receiver from a form" |
283 | 3828 |
|
3829 |
|map c0 c1| |
|
3830 |
||
3831 |
width := aForm width. |
|
3832 |
height := aForm height. |
|
3833 |
bitsPerSample := self bitsPerSample. |
|
3834 |
samplesPerPixel := self samplesPerPixel. |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3835 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3836 |
aForm hasBits ifFalse:[ |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3837 |
"/ must read the data from the device |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3838 |
self from:aForm in:(0@0 extent:aForm extent). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3839 |
^ self |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3840 |
]. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3841 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3842 |
"/ the form has all data available |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3843 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3844 |
bytes := aForm bits. |
283 | 3845 |
map := aForm colorMap. |
3846 |
||
3847 |
aForm depth == 1 ifTrue:[ |
|
592 | 3848 |
map isNil ifTrue:[ |
3849 |
photometric := #whiteIs0 |
|
3850 |
] ifFalse:[ |
|
3851 |
c0 := map at:1. |
|
3852 |
c1 := map at:2. |
|
3853 |
((c0 = Color white) |
|
3854 |
and:[c1 = Color black]) ifTrue:[ |
|
3855 |
photometric := #whiteIs0 |
|
3856 |
] ifFalse:[ |
|
3857 |
((c0 = Color black) |
|
3858 |
and:[c1 = Color white]) ifTrue:[ |
|
3859 |
photometric := #blackIs0 |
|
3860 |
] ifFalse:[ |
|
3861 |
photometric := #palette. |
|
3862 |
colorMap := Array with:c0 with:c1. |
|
3863 |
] |
|
3864 |
] |
|
3865 |
] |
|
283 | 3866 |
] ifFalse:[ |
592 | 3867 |
map notNil ifTrue:[ |
3868 |
photometric := #palette. |
|
3869 |
colorMap := map copy. |
|
3870 |
] ifFalse:[ |
|
3871 |
" |
|
3872 |
photometric stays at default |
|
3873 |
(which is rgb for d24, greyscale for others) |
|
3874 |
" |
|
3875 |
] |
|
283 | 3876 |
]. |
592 | 3877 |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
3878 |
"Modified: 5.7.1996 / 16:24:31 / cg" |
283 | 3879 |
! |
3880 |
||
89 | 3881 |
fromImage:anImage |
3882 |
"setup the receiver from another image. |
|
3883 |
Color precision may be lost, if conversion is from a higher depth |
|
191 | 3884 |
image. |
3885 |
WARNING: |
|
3886 |
This implementation is a slow fallback (the loop over the |
|
89 | 3887 |
source pixels is very slow). If this method is used heavily, you |
3888 |
may want to redefine it in concrete subclasses for common source images." |
|
3889 |
||
3890 |
width := anImage width. |
|
3891 |
height := anImage height. |
|
3892 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3893 |
bitsPerSample := self bitsPerSample. |
|
3894 |
samplesPerPixel := self samplesPerPixel. |
|
191 | 3895 |
self colormapFromImage:anImage. |
1374
ab515c0576c6
preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents:
1362
diff
changeset
|
3896 |
self mask:anImage mask. |
89 | 3897 |
anImage colorsFromX:0 y:0 toX:(width-1) y:(height-1) do:[:x :y :clr | |
798 | 3898 |
self atX:x y:y put:clr |
89 | 3899 |
]. |
3900 |
||
3901 |
" |
|
798 | 3902 |
|i i2 i4 i8 i16 i24| |
89 | 3903 |
|
3904 |
i := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
3905 |
i inspect. |
|
3906 |
i2 := Depth2Image fromImage:i. |
|
3907 |
i2 inspect. |
|
3908 |
i4 := Depth4Image fromImage:i. |
|
3909 |
i4 inspect. |
|
3910 |
i8 := Depth8Image fromImage:i. |
|
3911 |
i8 inspect. |
|
3912 |
i24 := Depth24Image fromImage:i. |
|
3913 |
i24 inspect. |
|
3914 |
" |
|
191 | 3915 |
|
3916 |
"Created: 20.9.1995 / 00:59:03 / claus" |
|
1374
ab515c0576c6
preserve mask when creating an image from another image.
Claus Gittinger <cg@exept.de>
parents:
1362
diff
changeset
|
3917 |
"Modified: 25.2.1997 / 17:47:02 / cg" |
191 | 3918 |
! |
3919 |
||
3920 |
fromSubImage:anImage in:aRectangle |
|
3921 |
"setup the receiver from another image, extracting a rectangular |
|
3922 |
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
|
3923 |
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
|
3924 |
represented. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3925 |
|
191 | 3926 |
WARNING: |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3927 |
This implementation is a slow fallback (the loop over the |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3928 |
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
|
3929 |
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
|
3930 |
of creating a subImage with the same depth & palette." |
191 | 3931 |
|
3932 |
|x0 y0| |
|
3933 |
||
3934 |
width := aRectangle width + 1. |
|
3935 |
height := aRectangle height + 1. |
|
3936 |
bytes := ByteArray uninitializedNew:(self bytesPerRow * height). |
|
3937 |
bitsPerSample := self bitsPerSample. |
|
3938 |
samplesPerPixel := self samplesPerPixel. |
|
3939 |
self colormapFromImage:anImage. |
|
3940 |
x0 := aRectangle left. |
|
3941 |
y0 := aRectangle top. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3942 |
|
191 | 3943 |
((photometric == anImage photometric) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3944 |
and:[self bitsPerPixel = anImage bitsPerPixel |
191 | 3945 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3946 |
"/ can do it by value |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3947 |
anImage valuesFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3948 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3949 |
do:[:x :y :pixelValue | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3950 |
self atX:x-x0 y:y-y0 putValue:pixelValue. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3951 |
] |
191 | 3952 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3953 |
"/ must do it by colors |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3954 |
anImage colorsFromX:x0 y:y0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3955 |
toX:aRectangle right y:aRectangle bottom |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3956 |
do:[:x :y :clr | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3957 |
self atX:x-x0 y:y-y0 put:clr. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3958 |
] |
191 | 3959 |
]. |
3960 |
||
3961 |
" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3962 |
|i i2 i4 i8 i16 i24| |
191 | 3963 |
|
3964 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
3965 |
i inspect. |
|
3966 |
i4 := Depth4Image fromSubImage:i in:(300@160 corner:340@200). |
|
3967 |
i4 inspect. |
|
3968 |
i8 := Depth8Image fromSubImage:i in:(300@160 corner:340@200). |
|
3969 |
i8 inspect. |
|
3970 |
i24 := Depth24Image fromSubImage:i in:(300@160 corner:340@200). |
|
3971 |
i24 inspect. |
|
3972 |
" |
|
3973 |
||
3974 |
"Created: 20.9.1995 / 01:06:02 / claus" |
|
3975 |
"Modified: 20.9.1995 / 10:15:37 / claus" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
3976 |
"Modified: 10.6.1996 / 18:30:17 / cg" |
89 | 3977 |
! |
3978 |
||
283 | 3979 |
monochromeOn:aDevice |
3980 |
"return a monochrome device image of the receiver for aDevice. |
|
3981 |
(monochrome, even if device supports colors)" |
|
3982 |
||
3983 |
((aDevice == device) and:[monoDeviceForm notNil]) ifTrue:[^ self]. |
|
3984 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
|
3985 |
"oops, I am already accociated to another device |
|
3986 |
- need a copy ... |
|
3987 |
" |
|
3988 |
^ self copy monochromeOn:aDevice |
|
3989 |
]. |
|
3990 |
monoDeviceForm := self asMonochromeFormOn:aDevice. |
|
3991 |
! |
|
3992 |
||
3993 |
on:aDevice |
|
3994 |
"return an image with the same pixels as the receiver, but |
|
3995 |
associated to aDevice. If the receiver is not yet bound to |
|
3996 |
a device, this will be the receiver. Otherwise, a new image |
|
3997 |
is returned." |
|
3998 |
||
3999 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ self]. |
|
852 | 4000 |
|
283 | 4001 |
(device notNil and:[aDevice ~~ device]) ifTrue:[ |
852 | 4002 |
"oops, I am already accociated to another device |
4003 |
- need a copy ... |
|
4004 |
" |
|
4005 |
^ self copy on:aDevice |
|
283 | 4006 |
]. |
4007 |
deviceForm := self asFormOn:aDevice. |
|
1057
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
4008 |
device := aDevice. |
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
4009 |
Lobby register:self |
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
4010 |
|
410f0fec2872
oops - must register Image after assigning a deviceForm
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
4011 |
"Modified: 16.9.1996 / 21:02:33 / cg" |
1496
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4012 |
! |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4013 |
|
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4014 |
onDevice:aDevice |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4015 |
"return an image with the same pixels as the receiver, but |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4016 |
associated to aDevice. If the receiver is not yet bound to |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4017 |
a device, this will be the receiver. Otherwise, a new image |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4018 |
is returned." |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4019 |
|
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4020 |
^ self on:aDevice |
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4021 |
|
fc27b03282af
added #onDevice: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
1488
diff
changeset
|
4022 |
"Created: 28.3.1997 / 16:05:53 / cg" |
283 | 4023 |
! ! |
4024 |
||
4025 |
!Image methodsFor:'converting greyscale images'! |
|
4026 |
||
4027 |
greyImageAsFormOn:aDevice |
|
4028 |
"return a thresholded grey-deviceForm from the grey image." |
|
4029 |
||
1063 | 4030 |
|pictureDepth nPlanes| |
283 | 4031 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4032 |
|
283 | 4033 |
nPlanes := samplesPerPixel. |
4034 |
(nPlanes == 2) ifTrue:[ |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4035 |
'Image [info]: alpha plane ignored' infoPrintCR. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4036 |
nPlanes := 1 |
283 | 4037 |
]. |
4038 |
||
4039 |
pictureDepth := bitsPerSample at:1. |
|
4040 |
||
4041 |
"monochrome is very easy ..." |
|
4042 |
||
4043 |
(pictureDepth == 1) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4044 |
^ Form width:width height:height fromArray:bytes on:aDevice |
283 | 4045 |
]. |
4046 |
||
4047 |
(aDevice visualType == #TrueColor) ifTrue:[ |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4048 |
^ self greyImageAsTrueColorFormOn:aDevice |
283 | 4049 |
]. |
4050 |
||
858 | 4051 |
"/ (aDevice visualType == #PseudoColor |
4052 |
"/ or:[aDevice visualType == #GrayScale |
|
4053 |
"/ or:[aDevice visualType == #StaticColor]]) ifTrue:[ |
|
4054 |
||
4055 |
"/ PseudoColor conversion also works for StaticColor, |
|
4056 |
"/ GrayScale and DirectColor; although possibly with suboptimal results |
|
4057 |
||
4058 |
^ self greyImageAsPseudoFormOn:aDevice |
|
4059 |
||
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4060 |
"Modified: 10.1.1997 / 17:52:49 / cg" |
283 | 4061 |
! |
4062 |
||
4063 |
greyImageAsPseudoFormOn:aDevice |
|
4064 |
"return an 8-bit pseudo Form from the grey image" |
|
4065 |
||
4066 |
|wideBits pictureDepth f map |
|
4067 |
colorMap usedColors nUsed aColor |
|
4068 |
nColors "{ Class: SmallInteger }" |
|
4069 |
range id| |
|
4070 |
||
4071 |
pictureDepth := bitsPerSample at:1. |
|
4072 |
||
4073 |
(#(2 4 8) includes:pictureDepth) ifFalse:[ |
|
746 | 4074 |
self error:'currently only depth-2, 4 or 8 supported'. |
4075 |
^ nil |
|
283 | 4076 |
]. |
4077 |
||
4078 |
wideBits := ByteArray uninitializedNew:(width * height). |
|
4079 |
||
4080 |
(pictureDepth == 8) ifTrue:[ |
|
746 | 4081 |
"for 8bits, we scan for used colors first; |
4082 |
to avoid allocating too many colors" |
|
4083 |
||
4084 |
usedColors := bytes usedValues. |
|
4085 |
nUsed := usedColors max + 1. |
|
4086 |
||
4087 |
colorMap := Array new:nUsed. |
|
4088 |
photometric == #blackIs0 ifTrue:[ |
|
4089 |
usedColors do:[:grey | |
|
4090 |
colorMap at:(grey + 1) put:(Color gray:(100.0 / 256.0 * grey)) |
|
4091 |
] |
|
4092 |
] ifFalse:[ |
|
4093 |
usedColors do:[:grey | |
|
4094 |
colorMap at:(grey + 1) put:(Color gray:(100 - (100.0 / 256.0 * grey))) |
|
4095 |
] |
|
4096 |
] |
|
89 | 4097 |
] ifFalse:[ |
746 | 4098 |
nColors := (1 bitShift:pictureDepth). |
4099 |
colorMap := Array new:nColors. |
|
4100 |
range := 100 / (nColors - 1) asFloat. |
|
4101 |
photometric == #blackIs0 ifTrue:[ |
|
4102 |
1 to:nColors do:[:i | |
|
4103 |
colorMap at:i put:(Color gray:(i - 1) * range). |
|
4104 |
]. |
|
4105 |
] ifFalse:[ |
|
4106 |
1 to:nColors do:[:i | |
|
4107 |
colorMap at:(nColors - i + 1) put:(Color gray:(i - 1) * range). |
|
4108 |
]. |
|
4109 |
]. |
|
283 | 4110 |
]. |
4111 |
||
4112 |
"XXX should reduce 8->6->4->2 planes, if not all colors could be allocated" |
|
4113 |
||
4114 |
"setup the translation map" |
|
4115 |
map := ByteArray uninitializedNew:256. |
|
4116 |
nColors := colorMap size. |
|
4117 |
1 to:nColors do:[:i | |
|
746 | 4118 |
aColor := colorMap at:i. |
4119 |
aColor notNil ifTrue:[ |
|
4120 |
aColor := aColor on:aDevice. |
|
4121 |
colorMap at:i put:aColor. |
|
4122 |
id := aColor colorId. |
|
4123 |
id notNil ifTrue:[ |
|
4124 |
map at:i put:id |
|
4125 |
] ifFalse:[ |
|
4126 |
map at:i put:0 |
|
4127 |
] |
|
4128 |
] |
|
89 | 4129 |
]. |
283 | 4130 |
|
4131 |
"expand & translate" |
|
4132 |
bytes expandPixels:pictureDepth |
|
746 | 4133 |
width:width |
4134 |
height:height |
|
4135 |
into:wideBits |
|
4136 |
mapping:map. |
|
283 | 4137 |
|
4138 |
f := Form width:width height:height depth:8 on:aDevice. |
|
4139 |
f isNil ifTrue:[^ nil]. |
|
4140 |
f colorMap:colorMap. |
|
4141 |
f initGC. |
|
4142 |
aDevice drawBits:wideBits depth:8 width:width height:height |
|
746 | 4143 |
x:0 y:0 |
4144 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
283 | 4145 |
^ f |
746 | 4146 |
|
4147 |
"Modified: 28.5.1996 / 20:55:57 / cg" |
|
0 | 4148 |
! |
4149 |
||
283 | 4150 |
greyImageAsTrueColorFormOn:aDevice |
4151 |
"return a true-color device-form for the grey-image receiver. |
|
4152 |
TODO: the pixel loops ought to be implemented as inline primitive code ..." |
|
4153 |
||
4154 |
|depth |
|
1143 | 4155 |
myDepth "{ Class: SmallInteger }" |
4156 |
nColors "{ Class: SmallInteger }" |
|
283 | 4157 |
colorValues |
1143 | 4158 |
scaleDown |
4159 |
scaleRed "{ Class: SmallInteger }" |
|
4160 |
scaleGreen "{ Class: SmallInteger }" |
|
4161 |
scaleBlue "{ Class: SmallInteger }" |
|
4162 |
redShift "{ Class: SmallInteger }" |
|
4163 |
blueShift "{ Class: SmallInteger }" |
|
4164 |
greenShift "{ Class: SmallInteger }" |
|
4165 |
form bestFormat usedDeviceDepth usedDeviceBitsPerPixel imageBits |
|
4166 |
destIndex "{ Class: SmallInteger }" |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4167 |
greyValue "{ Class: SmallInteger }" |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4168 |
endRow "{ Class: SmallInteger }" |
1143 | 4169 |
endCol "{ Class: SmallInteger }"| |
283 | 4170 |
|
4171 |
"/ this is a slow fallback method; this ought to be |
|
4172 |
"/ redefined in DepthxImage for more performance. |
|
4173 |
||
4174 |
depth := aDevice depth. |
|
4175 |
myDepth := self depth. |
|
4176 |
myDepth > 12 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4177 |
self error:'unsupported trueColor depth in greyImageAsTrueColorFormOn:'. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4178 |
^ nil |
0 | 4179 |
]. |
4180 |
||
283 | 4181 |
"/ compute scale to map from my pixels into devices range |
4182 |
||
4183 |
scaleDown := 1 bitShift:myDepth. |
|
4184 |
scaleRed := (1 bitShift:aDevice bitsRed). |
|
4185 |
scaleGreen := (1 bitShift:aDevice bitsGreen). |
|
4186 |
scaleBlue := (1 bitShift:aDevice bitsBlue). |
|
4187 |
redShift := aDevice shiftRed. |
|
4188 |
greenShift := aDevice shiftGreen. |
|
4189 |
blueShift := aDevice shiftBlue. |
|
4190 |
||
1143 | 4191 |
"/ prepare the map |
4192 |
||
283 | 4193 |
nColors := (1 bitShift:myDepth). |
4194 |
colorValues := Array new:nColors. |
|
4195 |
1 to:nColors do:[:i | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4196 |
|v gv bv rv nv| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4197 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4198 |
"/ scale down to 0..1 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4199 |
v := (i-1) / scaleDown. |
1143 | 4200 |
rv := (v * scaleRed) truncated. |
4201 |
gv := (v * scaleGreen) truncated. |
|
4202 |
bv := (v * scaleBlue) truncated. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4203 |
nv := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4204 |
nv := nv bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4205 |
nv := nv bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4206 |
colorValues at:i put:nv |
0 | 4207 |
]. |
283 | 4208 |
photometric == #whiteIs0 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4209 |
"/ reverse the order; 0 is brightest |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4210 |
colorValues reverse |
283 | 4211 |
]. |
193 | 4212 |
|
4213 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4214 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4215 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 4216 |
|
283 | 4217 |
"/ for now, only support some depths |
4218 |
||
4219 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4220 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4221 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4222 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4223 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4224 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4225 |
destIndex := 1. |
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4226 |
endRow := height - 1. |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4227 |
endCol := width - 1. |
1143 | 4228 |
0 to:endRow do:[:y | |
4229 |
0 to:endCol do:[:x | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4230 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4231 |
imageBits wordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4232 |
destIndex := destIndex + 2. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4233 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4234 |
] |
283 | 4235 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4236 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4237 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4238 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4239 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4240 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4241 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4242 |
destIndex := 1. |
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4243 |
endRow := height - 1. |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4244 |
endCol := width - 1. |
1143 | 4245 |
0 to:endRow do:[:y | |
4246 |
0 to:endCol do:[:x | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4247 |
greyValue := self valueAtX:x y:y. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4248 |
imageBits doubleWordAt:destIndex put:(colorValues at:greyValue + 1) MSB:true. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4249 |
destIndex := destIndex + 4. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4250 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4251 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4252 |
] |
193 | 4253 |
]. |
4254 |
||
283 | 4255 |
imageBits isNil ifTrue:[ |
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4256 |
'Image [warning]: unimplemented trueColor depth on greyImageAsTrueColorFormOn:' errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4257 |
^ self asMonochromeFormOn:aDevice |
283 | 4258 |
]. |
4259 |
||
4260 |
form := |
|
193 | 4261 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
283 | 4262 |
form isNil ifTrue:[^ nil]. |
193 | 4263 |
form initGC. |
4264 |
||
4265 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4266 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4267 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4268 |
x:0 y:0 toX:0 y:0. |
193 | 4269 |
|
4270 |
^ form |
|
4271 |
||
283 | 4272 |
"Created: 20.10.1995 / 22:05:10 / cg" |
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4273 |
"Modified: 10.1.1997 / 17:53:05 / cg" |
0 | 4274 |
! ! |
4275 |
||
4276 |
!Image methodsFor:'converting palette images'! |
|
4277 |
||
4278 |
paletteImageAsFormOn:aDevice |
|
72 | 4279 |
"return a device-form for the palette-image receiver" |
4280 |
||
380 | 4281 |
|type ddepth| |
193 | 4282 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4283 |
ddepth := aDevice depth. |
379 | 4284 |
|
193 | 4285 |
((type := aDevice visualType) == #StaticGray) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4286 |
ddepth == 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4287 |
^ self paletteImageAsGray8FormOn:aDevice |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4288 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4289 |
^ self asGrayFormOn:aDevice |
0 | 4290 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4291 |
|
193 | 4292 |
(type == #TrueColor) ifTrue:[ |
854 | 4293 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
4294 |
ddepth == 8 ifTrue:[ |
|
4295 |
self depth == 8 ifTrue:[ |
|
4296 |
"/ use fixColor dither algorithm |
|
4297 |
^ self asDitheredTrueColor8FormOn:aDevice |
|
4298 |
] |
|
4299 |
] |
|
4300 |
]. |
|
4301 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4302 |
^ self paletteImageAsTrueColorFormOn:aDevice |
193 | 4303 |
]. |
858 | 4304 |
|
4305 |
"/ the PseudoColor conversion also works for |
|
4306 |
"/ StaticColor, GrayScale & DirectColor; although possibly with suboptimal results |
|
4307 |
||
4308 |
^ self paletteImageAsPseudoFormOn:aDevice |
|
4309 |
||
4310 |
"Modified: 14.6.1996 / 19:31:01 / cg" |
|
0 | 4311 |
! |
4312 |
||
4313 |
paletteImageAsPseudoFormOn:aDevice |
|
72 | 4314 |
"return a pseudo-deviceForm from the palette image." |
0 | 4315 |
|
89 | 4316 |
|tempImage d temp8| |
4317 |
||
4318 |
d := self depth. |
|
4319 |
(#(1 2 4 8) includes:d) ifTrue:[ |
|
4320 |
" |
|
4321 |
fallback code for some depth's: |
|
4322 |
create a temporary Depth8Image and use its conversion method |
|
4323 |
" |
|
4324 |
temp8 := ByteArray uninitializedNew:(width * height). |
|
4325 |
||
4326 |
bytes expandPixels:d |
|
4327 |
width:width |
|
4328 |
height:height |
|
4329 |
into:temp8 |
|
4330 |
mapping:nil. |
|
4331 |
||
4332 |
tempImage := Image width:width height:height depth:8 fromArray:temp8. |
|
4333 |
tempImage colorMap:colorMap. |
|
4334 |
^ tempImage paletteImageAsPseudoFormOn:aDevice |
|
4335 |
]. |
|
2 | 4336 |
^ self subclassResponsibility |
0 | 4337 |
! |
4338 |
||
193 | 4339 |
paletteImageAsTrueColorFormOn:aDevice |
4340 |
"return a true-color device-form for the palette-image receiver." |
|
4341 |
||
209 | 4342 |
|depth |
4343 |
myDepth "{ Class: SmallInteger }" |
|
4344 |
nColors "{ Class: SmallInteger }" |
|
4345 |
colorValues |
|
193 | 4346 |
scaleRed scaleGreen scaleBlue redShift greenShift blueShift |
194 | 4347 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
854 | 4348 |
destIndex| |
193 | 4349 |
|
4350 |
"/ this is a slow fallback method; this ought to be |
|
4351 |
"/ redefined in DepthxImage for more performance. |
|
4352 |
||
4353 |
depth := aDevice depth. |
|
4354 |
myDepth := self bitsPerPixel. |
|
4355 |
myDepth > 12 ifTrue:[ |
|
1170 | 4356 |
('Image [warning]: palette images with depth ' , myDepth printString , ' are not supported (limit is 12)') errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4357 |
^ nil |
193 | 4358 |
]. |
4359 |
||
4360 |
"/ gather r/g/b values for all colors in the map ... |
|
4361 |
||
4362 |
nColors := colorMap size. |
|
4363 |
||
4364 |
"/ precompute scales to map from 0..100 into devices range |
|
4365 |
"/ (this may be different for the individual components) |
|
4366 |
||
4367 |
scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100. |
|
4368 |
scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100. |
|
4369 |
scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100. |
|
4370 |
redShift := aDevice shiftRed. |
|
4371 |
greenShift := aDevice shiftGreen. |
|
4372 |
blueShift := aDevice shiftBlue. |
|
4373 |
||
4374 |
colorValues := Array uninitializedNew:nColors. |
|
4375 |
||
4376 |
1 to:nColors do:[:index | |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4377 |
|clr rv gv bv v "{ Class: SmallInteger }" | |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4378 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4379 |
clr := colorMap at:index. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4380 |
clr notNil ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4381 |
rv := (clr red * scaleRed) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4382 |
gv := (clr green * scaleGreen) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4383 |
bv := (clr blue * scaleBlue) rounded. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4384 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4385 |
v := rv bitShift:redShift. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4386 |
v := v bitOr:(gv bitShift:greenShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4387 |
v := v bitOr:(bv bitShift:blueShift). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4388 |
colorValues at:index put:v. |
193 | 4389 |
"/ clr print. ' ' print. |
4390 |
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print. |
|
4391 |
"/ ' -> ' print. v printNL. |
|
4392 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4393 |
] |
193 | 4394 |
]. |
4395 |
||
4396 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4397 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4398 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 4399 |
|
4400 |
"/ for now, only support some depths |
|
4401 |
||
854 | 4402 |
"/ 16 bits/pixel |
4403 |
||
193 | 4404 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4405 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4406 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4407 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4408 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4409 |
|
854 | 4410 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4411 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4412 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4413 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4414 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4415 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4416 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4417 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4418 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4419 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4420 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4421 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4422 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4423 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4424 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4425 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4426 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4427 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4428 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4429 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4430 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4431 |
v = __intVal(clr); |
193 | 4432 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4433 |
((short *)dstPtr)[0] = v; |
193 | 4434 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4435 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4436 |
dstPtr[1] = (v) & 0xFF; |
193 | 4437 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4438 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4439 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4440 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4441 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4442 |
} |
193 | 4443 |
%}. |
4444 |
] ifFalse:[ |
|
854 | 4445 |
"/ 32 bits/pixel |
4446 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4447 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4448 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4449 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4450 |
"/ now, walk over the image and replace |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4451 |
"/ colorMap indices by color values in the bits array |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4452 |
|
854 | 4453 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4454 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4455 |
&& __isArray(colorValues) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4456 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4457 |
&& (myDepth == __MKSMALLINT(8)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4458 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4459 |
int x, y, w, h, nPix; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4460 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4461 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4462 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4463 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4464 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4465 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4466 |
h = __intVal(_INST(height)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4467 |
nPix = w * h; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4468 |
while (nPix > 0) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4469 |
unsigned idx, v; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4470 |
OBJ clr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4471 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4472 |
idx = *srcPtr; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4473 |
clr = ap[idx]; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4474 |
v = __intVal(clr); |
193 | 4475 |
#ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4476 |
((long *)dstPtr)[0] = v; |
193 | 4477 |
#else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4478 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4479 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4480 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4481 |
dstPtr[3] = (v) & 0xFF; |
193 | 4482 |
#endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4483 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4484 |
srcPtr += 1; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4485 |
nPix--; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4486 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4487 |
} |
193 | 4488 |
%}. |
854 | 4489 |
] ifFalse:[ |
4490 |
"/ 8 bits/pixel |
|
4491 |
||
4492 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
4493 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
4494 |
||
4495 |
"/ now, walk over the image and replace |
|
4496 |
"/ colorMap indices by color values in the bits array |
|
4497 |
||
4498 |
%{ |
|
4499 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
4500 |
&& __isArray(colorValues) |
|
4501 |
&& __isByteArray(_INST(bytes)) |
|
4502 |
&& (myDepth == __MKSMALLINT(8)) |
|
4503 |
&& __isByteArray(imageBits)) { |
|
4504 |
int x, y, w, h, nPix; |
|
4505 |
||
4506 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
4507 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
4508 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
|
4509 |
||
4510 |
w = __intVal(_INST(width)); |
|
4511 |
h = __intVal(_INST(height)); |
|
4512 |
nPix = w * h; |
|
4513 |
while (nPix > 0) { |
|
4514 |
unsigned idx, v; |
|
4515 |
OBJ clr; |
|
4516 |
||
4517 |
idx = *srcPtr; |
|
4518 |
clr = ap[idx]; |
|
4519 |
v = __intVal(clr); |
|
4520 |
||
4521 |
dstPtr[0] = v; |
|
4522 |
||
4523 |
dstPtr += 1; |
|
4524 |
srcPtr += 1; |
|
4525 |
nPix--; |
|
4526 |
} |
|
4527 |
} |
|
4528 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4529 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4530 |
] |
193 | 4531 |
]. |
4532 |
||
4533 |
imageBits isNil ifTrue:[ |
|
1169 | 4534 |
'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4535 |
^ self asMonochromeFormOn:aDevice |
193 | 4536 |
]. |
4537 |
||
4538 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
4539 |
form isNil ifTrue:[^ nil]. |
|
4540 |
form initGC. |
|
4541 |
||
4542 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4543 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4544 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4545 |
x:0 y:0 toX:0 y:0. |
193 | 4546 |
|
4547 |
^ form |
|
4548 |
||
4549 |
"Created: 20.10.1995 / 22:05:10 / cg" |
|
4550 |
"Modified: 21.10.1995 / 19:30:26 / cg" |
|
0 | 4551 |
! ! |
4552 |
||
283 | 4553 |
!Image methodsFor:'converting rgb images'! |
4554 |
||
854 | 4555 |
asDitheredTrueColor8FormOn:aDevice |
4556 |
"convert an rgb image to a dithered depth8-form on aDevice. |
|
4557 |
Return the device-form." |
|
4558 |
||
4559 |
|fixColors pixel |
|
4560 |
dstIdx "{ Class: SmallInteger }" |
|
4561 |
shiftRed "{ Class: SmallInteger }" |
|
4562 |
shiftGreen "{ Class: SmallInteger }" |
|
4563 |
shiftBlue "{ Class: SmallInteger }" |
|
4564 |
nRed "{ Class: SmallInteger }" |
|
4565 |
nGreen "{ Class: SmallInteger }" |
|
4566 |
nBlue "{ Class: SmallInteger }"| |
|
4567 |
||
4568 |
shiftRed := aDevice shiftRed. |
|
4569 |
shiftGreen := aDevice shiftGreen. |
|
4570 |
shiftBlue := aDevice shiftBlue. |
|
4571 |
||
4572 |
nRed := (1 bitShift:aDevice bitsRed). |
|
4573 |
nGreen := (1 bitShift:aDevice bitsGreen). |
|
4574 |
nBlue := (1 bitShift:aDevice bitsBlue). |
|
4575 |
||
4576 |
fixColors := Array new:(nRed * nGreen * nBlue). |
|
4577 |
||
4578 |
dstIdx := 1. |
|
4579 |
0 to:nRed - 1 do:[:sR | |
|
4580 |
0 to:nGreen - 1 do:[:sG | |
|
4581 |
0 to:nBlue - 1 do:[:sB | |
|
4582 |
pixel := (sR bitShift:shiftRed) |
|
4583 |
+ (sG bitShift:shiftGreen) |
|
4584 |
+ (sB bitShift:shiftBlue). |
|
4585 |
fixColors at:dstIdx put:(Color colorId:(pixel)). |
|
4586 |
dstIdx := dstIdx + 1 |
|
4587 |
] |
|
4588 |
] |
|
4589 |
]. |
|
4590 |
||
4591 |
^ self |
|
4592 |
asFloydSteinbergDitheredDepth8FormOn:aDevice |
|
4593 |
colors:fixColors |
|
4594 |
nRed:nRed nGreen:nGreen nBlue:nBlue |
|
4595 |
||
4596 |
"Modified: 14.6.1996 / 17:18:57 / cg" |
|
4597 |
"Created: 14.6.1996 / 17:23:52 / cg" |
|
4598 |
! |
|
4599 |
||
283 | 4600 |
rgbImageAsFormOn:aDevice |
4601 |
"convert am rgb image to a device-form on aDevice. |
|
4602 |
Return the device-form." |
|
4603 |
||
4604 |
|visual| |
|
4605 |
||
4606 |
visual := aDevice visualType. |
|
4607 |
(visual == #StaticGray) ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4608 |
^ self asGrayFormOn:aDevice |
0 | 4609 |
]. |
283 | 4610 |
(visual == #TrueColor) ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4611 |
^ self rgbImageAsTrueColorFormOn:aDevice |
0 | 4612 |
]. |
858 | 4613 |
|
4614 |
"/ PseudoColor conversion also works for StaticColor, GrayScale |
|
4615 |
"/ and DirectColor displays; although possibly with suboptimal results |
|
4616 |
||
283 | 4617 |
^ self rgbImageAsPseudoFormOn:aDevice |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4618 |
|
858 | 4619 |
"Modified: 14.6.1996 / 19:30:06 / cg" |
283 | 4620 |
! |
4621 |
||
4622 |
rgbImageAsPseudoFormOn:aDevice |
|
4623 |
"return a pseudocolor form from the rgb-picture" |
|
4624 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4625 |
|n "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4626 |
depth "{ Class: SmallInteger }" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4627 |
palette f| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4628 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4629 |
(depth := self depth) <= 8 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4630 |
"/ 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
|
4631 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4632 |
palette := Array new:(1 bitShift:depth). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4633 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4634 |
n := (1 bitShift:depth)-1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4635 |
0 to:n do:[:pixelValue | |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4636 |
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
|
4637 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4638 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4639 |
colorMap := palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4640 |
photometric := #palette. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4641 |
f := self paletteImageAsPseudoFormOn:aDevice. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4642 |
colorMap := nil. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4643 |
photometric := #rgb. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4644 |
^ f |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4645 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4646 |
|
283 | 4647 |
^ self subclassResponsibility |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4648 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
4649 |
"Modified: 8.6.1996 / 10:58:25 / cg" |
283 | 4650 |
! |
4651 |
||
4652 |
rgbImageAsTrueColorFormOn:aDevice |
|
4653 |
"return a truecolor form from the rgb-picture." |
|
4654 |
||
1063 | 4655 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
283 | 4656 |
form| |
193 | 4657 |
|
4658 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4659 |
usedDeviceDepth := bestFormat at:#depth. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
4660 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
193 | 4661 |
|
854 | 4662 |
"/ 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
|
4663 |
usedDeviceBitsPerPixel == 15 ifTrue:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4664 |
usedDeviceBitsPerPixel := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
4665 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
4666 |
|
283 | 4667 |
"/ |
4668 |
"/ only the trivial case, where the depths match |
|
4669 |
"/ is handled here; conversions are supposed to |
|
4670 |
"/ be done in concrete subclasses (see D24Image) |
|
4671 |
"/ |
|
4672 |
self bitsPerPixel == usedDeviceBitsPerPixel ifFalse:[ |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4673 |
'Image [warning]: unimplemented trueColor depth in rgbImageAsTrueColorFormOn: ' errorPrint. self bitsPerPixel errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4674 |
^ self asMonochromeFormOn:aDevice |
193 | 4675 |
]. |
4676 |
||
283 | 4677 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
4678 |
form isNil ifTrue:[ |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4679 |
'Image [warning]: display bitmap creation failed' errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4680 |
^ nil |
193 | 4681 |
]. |
4682 |
form initGC. |
|
4683 |
||
4684 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4685 |
copyBitsFrom:bytes bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4686 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
4687 |
x:0 y:0 toX:0 y:0. |
193 | 4688 |
|
4689 |
^ form |
|
4690 |
||
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
4691 |
"Modified: 10.1.1997 / 17:53:23 / cg" |
283 | 4692 |
! ! |
4693 |
||
4694 |
!Image methodsFor:'copying'! |
|
4695 |
||
4696 |
postCopy |
|
592 | 4697 |
"redefined to also copy the pixels and the colorMap |
4698 |
and clear out any device handles in the copy." |
|
4699 |
||
283 | 4700 |
bytes := bytes copy. |
916 | 4701 |
colorMap := colorMap copy. |
283 | 4702 |
device := deviceForm := monoDeviceForm := fullColorDeviceForm := nil |
592 | 4703 |
|
916 | 4704 |
"Modified: 5.7.1996 / 13:16:04 / cg" |
283 | 4705 |
! ! |
4706 |
||
4707 |
!Image methodsFor:'displaying'! |
|
4708 |
||
758 | 4709 |
displayFilledOn:aGC |
759 | 4710 |
"display the receiver as an opaque image. |
758 | 4711 |
This allows Images to be wrapped by a FillingWrapper" |
4712 |
||
4713 |
aGC displayOpaqueForm:self x:0 y:0. |
|
4714 |
||
4715 |
"Created: 29.5.1996 / 10:34:18 / cg" |
|
759 | 4716 |
"Modified: 29.5.1996 / 10:52:36 / cg" |
758 | 4717 |
! |
4718 |
||
283 | 4719 |
displayOn:aGC at:aPoint |
592 | 4720 |
"draw the receiver in the graphicsContext, aGC. |
283 | 4721 |
Smalltalk-80 compatibility" |
4722 |
||
672 | 4723 |
self displayOn:aGC x:aPoint x y:aPoint y. |
4724 |
||
4725 |
"Modified: 12.5.1996 / 20:16:38 / cg" |
|
4726 |
! |
|
4727 |
||
4728 |
displayOn:aGC x:x y:y |
|
4729 |
"draw the receiver in the graphicsContext, aGC. |
|
4730 |
Smalltalk-80 compatibility" |
|
4731 |
||
4732 |
aGC displayForm:self x:x y:y. |
|
592 | 4733 |
|
4734 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
|
672 | 4735 |
"Created: 12.5.1996 / 20:14:31 / cg" |
758 | 4736 |
! |
4737 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4738 |
displayOpaqueOn:aGC x:x y:y |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4739 |
"draw the receiver in the graphicsContext, aGC. |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4740 |
Smalltalk-80 compatibility" |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4741 |
|
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4742 |
aGC displayOpaqueForm:self x:x y:y. |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4743 |
|
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4744 |
"Modified: 23.4.1996 / 11:12:31 / cg" |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4745 |
"Created: 22.10.1996 / 16:35:49 / cg" |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4746 |
! |
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
4747 |
|
758 | 4748 |
displayStrokedOn:aGC |
759 | 4749 |
"display the receiver as an non opaque image. |
758 | 4750 |
This allows Images to be wrapped by a StrokingWrapper" |
4751 |
||
4752 |
aGC displayForm:self x:0 y:0. |
|
4753 |
||
759 | 4754 |
"Created: 29.5.1996 / 10:34:18 / cg" |
4755 |
"Modified: 29.5.1996 / 10:52:30 / cg" |
|
283 | 4756 |
! ! |
4757 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4758 |
!Image methodsFor:'dither helpers'! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4759 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4760 |
burkesDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4761 |
"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
|
4762 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4763 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4764 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4765 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4766 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4767 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4768 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4769 |
errorArray1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4770 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4771 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4772 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4773 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4774 |
byte "{Class: SmallInteger }" |
1063 | 4775 |
grey| |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4776 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4777 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4778 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4779 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4780 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4781 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4782 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4783 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4784 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4785 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4786 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4787 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4788 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4789 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4790 |
errorArray := Array new:(w+4). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4791 |
errorArray1 := Array new:(w+4) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4792 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4793 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4794 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4795 |
"/ 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
|
4796 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4797 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4798 |
greyValues := self greyMapForRange:(255*1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4799 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4800 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4801 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4802 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4803 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4804 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4805 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4806 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4807 |
errorArray1 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4808 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4809 |
errorArray1 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4810 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4811 |
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
|
4812 |
|eP "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4813 |
eD |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4814 |
eI "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4815 |
xE "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4816 |
xN "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4817 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4818 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4819 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4820 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4821 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4822 |
xE := x + 2 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4823 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4824 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4825 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4826 |
grey > (127*1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4827 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4828 |
e := grey - (255*1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4829 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4830 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4831 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4832 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4833 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4834 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4835 |
"/ XX 8 4 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4836 |
"/ 2 4 8 4 2 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4837 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4838 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4839 |
eI := e // 32. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4840 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4841 |
eP := eI * 8. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4842 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4843 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4844 |
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
|
4845 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4846 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4847 |
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
|
4848 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4849 |
eP := eI * 4. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4850 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4851 |
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
|
4852 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4853 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4854 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4855 |
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
|
4856 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4857 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4858 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4859 |
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
|
4860 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4861 |
eP := eI * 2. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4862 |
xN := xE - 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4863 |
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
|
4864 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4865 |
eD := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4866 |
xN := xE + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4867 |
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
|
4868 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4869 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4870 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4871 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4872 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4873 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4874 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4875 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4876 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4877 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4878 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4879 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4880 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4881 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4882 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4883 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4884 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4885 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4886 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4887 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4888 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4889 |
"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
|
4890 |
"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
|
4891 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4892 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4893 |
floydSteinbergDitheredBitsDepth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4894 |
"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
|
4895 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4896 |
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
|
4897 |
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
|
4898 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4899 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4900 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4901 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4902 |
outBits greyValues greyErrors greyPixels greyLevels |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4903 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4904 |
nextErrorArray |
1063 | 4905 |
t |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4906 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4907 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4908 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4909 |
byte "{Class: SmallInteger }" |
1063 | 4910 |
grey |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4911 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4912 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4913 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4914 |
self error:'unimplemented conversion'. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4915 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4916 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4917 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4918 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4919 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4920 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4921 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4922 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4923 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4924 |
^ nil |
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 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4927 |
greyLevels := (1 bitShift:depth) - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4928 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4929 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4930 |
nextErrorArray := Array new:w+2. |
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 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4933 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4934 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4935 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4936 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4937 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4938 |
"/ 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
|
4939 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4940 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4941 |
greyValues := self greyMapForRange:(greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4942 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4943 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4944 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4945 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4946 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4947 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4948 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4949 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4950 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4951 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4952 |
] ifFalse:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4953 |
((v - v truncated) * 1024) truncated |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4954 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4955 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4956 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4957 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4958 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4959 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4960 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4961 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4962 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4963 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4964 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4965 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4966 |
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
|
4967 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4968 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4969 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4970 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4971 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4972 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4973 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4974 |
pixel := greyPixels at:(value + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4975 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4976 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4977 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4978 |
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
|
4979 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4980 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4981 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4982 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4983 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4984 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4985 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4986 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4987 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4988 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4989 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4990 |
e16 := e // 16. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4991 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4992 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4993 |
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
|
4994 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4995 |
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
|
4996 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4997 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4998 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
4999 |
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
|
5000 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5001 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5002 |
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
|
5003 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5004 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5005 |
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
|
5006 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5007 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5008 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5009 |
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
|
5010 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5011 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5012 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5013 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5014 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5015 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5016 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5017 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5018 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5019 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5020 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5021 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5022 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5023 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5024 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5025 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5026 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5027 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5028 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5029 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5030 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5031 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5032 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5033 |
byte := 0. |
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 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5036 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5037 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5038 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5039 |
nextErrorArray atAllPut:0. |
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 |
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
|
5042 |
|e "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5043 |
pixel "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5044 |
error "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5045 |
e16 "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5046 |
xE "{ Class: SmallInteger }" |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5047 |
xN "{ Class: SmallInteger }" | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5048 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5049 |
grey := (clr brightness * greyLevels). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5050 |
pixel := grey truncated. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5051 |
error := ((grey - pixel) * 1024) truncated. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5052 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5053 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5054 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5055 |
error := error + (errorArray at:xE). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5056 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5057 |
byte := byte bitShift:depth. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5058 |
error > 512 "0.5" ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5059 |
pixel := pixel + 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5060 |
e := error - 1024 "1.0" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5061 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5062 |
e := error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5063 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5064 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5065 |
byte := byte bitOr:pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5066 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5067 |
e ~= 0 ifTrue:[ |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5068 |
e16 := e // 16. |
809
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 |
eR := e16 * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5071 |
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
|
5072 |
eB := e16 * 5. "/ 5/16 to below |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5073 |
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
|
5074 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5075 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5076 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5077 |
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
|
5078 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5079 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5080 |
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
|
5081 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5082 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5083 |
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
|
5084 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5085 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5086 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5087 |
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
|
5088 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5089 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5090 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5091 |
bitCnt := bitCnt - depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5092 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5093 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5094 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5095 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5096 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5097 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5098 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5099 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5100 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5101 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5102 |
outBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5103 |
bitCnt := 8. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5104 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5105 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5106 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5107 |
]. |
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 |
^ outBits |
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 |
"Created: 10.6.1996 / 13:28:22 / cg" |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5113 |
"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
|
5114 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5115 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5116 |
floydSteinbergDitheredDepth8BitsColors:colors |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5117 |
"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
|
5118 |
which must be a depth-8 image. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5119 |
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
|
5120 |
(which need not be a colorCubes colors)." |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5121 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5122 |
|pseudoBits |
882 | 5123 |
rgbBytes |
5124 |
ditherRGBBytes ditherColors |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5125 |
w "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5126 |
h "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5127 |
index "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5128 |
fixR "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5129 |
fixG "{Class: SmallInteger }" |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5130 |
fixB "{Class: SmallInteger }" |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5131 |
ditherIds failed map lastColor colorsByDistance qScramble |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5132 |
clrLookup lookupPos |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5133 |
error clr| |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5134 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5135 |
self depth ~~ 8 ifTrue:[^ nil]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5136 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5137 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5138 |
"/ 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
|
5139 |
"/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5140 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5141 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5142 |
photometric == #palette ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5143 |
lastColor := colorMap size - 1 |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5144 |
] ifFalse:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5145 |
lastColor := 255. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5146 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5147 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5148 |
0 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5149 |
clr := self colorFromValue:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5150 |
rgbBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5151 |
rgbBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5152 |
rgbBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5153 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5154 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5155 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5156 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5157 |
"/ collect valid ditherColors ... |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5158 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5159 |
ditherColors := colors select:[:clr | clr notNil]. |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5160 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5161 |
"/ ... and sort by manhatten distance from black |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5162 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5163 |
qScramble := #( |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5164 |
"/ 2rX00X00X00X00 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5165 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5166 |
2r000000000000 "/ 0 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5167 |
2r000000000100 "/ 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5168 |
2r000000100000 "/ 2 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5169 |
2r000000100100 "/ 3 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5170 |
2r000100000000 "/ 4 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5171 |
2r000100000100 "/ 5 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5172 |
2r000100100000 "/ 6 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5173 |
2r000100100100 "/ 7 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5174 |
2r100000000000 "/ 8 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5175 |
2r100000000100 "/ 9 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5176 |
2r100000100000 "/ a |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5177 |
2r100000100100 "/ b |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5178 |
2r100100000000 "/ c |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5179 |
2r100100000100 "/ d |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5180 |
2r100100100000 "/ e |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5181 |
2r100100100100 "/ f |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5182 |
). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5183 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5184 |
ditherColors := ditherColors sort:[:a :b | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5185 |
|cr "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5186 |
cg "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5187 |
cb "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5188 |
i1 "{Class: SmallInteger }" |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5189 |
i2 "{Class: SmallInteger }"| |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5190 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5191 |
cr := a redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5192 |
cg := a greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5193 |
cb := a blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5194 |
i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5195 |
i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5196 |
i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5197 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5198 |
cr := b redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5199 |
cg := b greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5200 |
cb := b blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5201 |
i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5202 |
i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5203 |
i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5204 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5205 |
i1 < i2 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5206 |
]. |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5207 |
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
|
5208 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5209 |
"/ build an index table, for fast lookup from manhatten-r-g-b distance |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5210 |
"/ to the position in the colorList |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5211 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5212 |
clrLookup := ByteArray new:(4096). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5213 |
index := 0. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5214 |
ditherColors keysAndValuesDo:[:clrPosition :clr | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5215 |
|r g b i| |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5216 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5217 |
r := clr redByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5218 |
g := clr greenByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5219 |
b := clr blueByte. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5220 |
i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5221 |
i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5222 |
i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5223 |
lookupPos := i. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5224 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5225 |
[index < lookupPos] whileTrue:[ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5226 |
clrLookup at:(index+1) put:(clrPosition-1-1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5227 |
index := index + 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5228 |
] |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5229 |
]. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5230 |
clrLookup from:index+1 to:4096 put:(ditherColors size - 1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5231 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5232 |
"/ [index <= (4095)] whileTrue:[ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5233 |
"/ clrLookup at:(index+1) put:(ditherColors size - 1). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5234 |
"/ index := index + 1. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5235 |
"/ ]. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5236 |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5237 |
"/ collect ditherColor components |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5238 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5239 |
lastColor := ditherColors size. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5240 |
ditherIds := ByteArray uninitializedNew:lastColor. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5241 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5242 |
index := 1. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5243 |
1 to:lastColor do:[:pix | |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5244 |
clr := ditherColors at:pix. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5245 |
ditherRGBBytes at:index put:(clr redByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5246 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5247 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5248 |
ditherIds at:pix put:clr colorId. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5249 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5250 |
index := index + 3. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5251 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5252 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5253 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5254 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5255 |
w := width + 2. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5256 |
error := ByteArray uninitializedNew:w*(3*2). |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5257 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5258 |
w := width. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5259 |
h := height. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5260 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5261 |
failed := true. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5262 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5263 |
%{ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5264 |
int __x, __y; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5265 |
int __eR, __eG, __eB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5266 |
unsigned char *srcP, *dstP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5267 |
unsigned char *rgbP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5268 |
unsigned char *idP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5269 |
unsigned char *dp; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5270 |
unsigned char *__clrLookup; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5271 |
short *errP, *eP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5272 |
int __fR, __fG, __fB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5273 |
int iR, iG, iB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5274 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5275 |
int __w = __intVal(w); |
882 | 5276 |
int __h = __intVal(h); |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5277 |
int __nColors = __intVal(lastColor); |
882 | 5278 |
int __wR = -1, __wG, __wB; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5279 |
static int __qScramble[16] = { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5280 |
0x000 /* 2r000000000000 0 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5281 |
0x004 /* 2r000000000100 1 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5282 |
0x020 /* 2r000000100000 2 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5283 |
0x024 /* 2r000000100100 3 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5284 |
0x100 /* 2r000100000000 4 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5285 |
0x104 /* 2r000100000100 5 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5286 |
0x120 /* 2r000100100000 6 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5287 |
0x124 /* 2r000100100100 7 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5288 |
0x800 /* 2r100000000000 8 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5289 |
0x804 /* 2r100000000100 9 */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5290 |
0x820 /* 2r100000100000 a */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5291 |
0x824 /* 2r100000100100 b */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5292 |
0x900 /* 2r100100000000 c */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5293 |
0x904 /* 2r100100000100 d */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5294 |
0x920 /* 2r100100100000 e */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5295 |
0x924 /* 2r100100100100 f */, |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5296 |
}; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5297 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5298 |
if (__isByteArray(__INST(bytes)) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5299 |
&& __isByteArray(pseudoBits) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5300 |
&& __isByteArray(rgbBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5301 |
&& __isByteArray(ditherRGBBytes) |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5302 |
&& __isByteArray(ditherIds) |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5303 |
&& __isByteArray(clrLookup) |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5304 |
&& __isByteArray(error)) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5305 |
failed = false; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5306 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5307 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5308 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5309 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5310 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5311 |
__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5312 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5313 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5314 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5315 |
* clear error accumulator |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5316 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5317 |
eP = errP; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5318 |
bzero(eP, (__w+2) * 2 * 3); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5319 |
|
882 | 5320 |
for (__y=__h; __y>0; __y--) { |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5321 |
__eR = __eG = __eB = 0; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5322 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5323 |
eP = &(errP[3]); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5324 |
__eR = eP[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5325 |
__eG = eP[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5326 |
__eB = eP[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5327 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5328 |
for (__x=__w; __x>0; __x--) { |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5329 |
int __want; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5330 |
int pix; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5331 |
int __wantR, __wantG, __wantB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5332 |
int idx; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5333 |
int tR, tG, tB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5334 |
int nR, nG, nB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5335 |
int dR, dG, dB; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5336 |
int minDelta, bestIdx; |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5337 |
int cnt; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5338 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5339 |
pix = *srcP++; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5340 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5341 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5342 |
* 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
|
5343 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5344 |
idx = pix+pix+pix; /* pix * 3 */ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5345 |
|
882 | 5346 |
__wantR = rgbP[idx] + __eR; |
5347 |
__wantG = rgbP[idx+1] + __eG; |
|
5348 |
__wantB = rgbP[idx+2] + __eB; |
|
5349 |
||
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5350 |
#define RED_SCALE 30 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5351 |
#define GREEN_SCALE 59 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5352 |
#define BLUE_SCALE 11 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5353 |
#define GOOD_DELTA 30 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5354 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5355 |
#define xRED_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5356 |
#define xGREEN_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5357 |
#define xBLUE_SCALE 1 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5358 |
#define xGOOD_DELTA 3 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5359 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5360 |
#define FAST_LOOKUP |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5361 |
/* #define ONE_SHOT */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5362 |
#define NPROBE 8 |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5363 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5364 |
#ifndef FAST_LOOKUP |
882 | 5365 |
if ((__wantR == __wR) |
5366 |
&& (__wantG == __wG) |
|
5367 |
&& (__wantB == __wB)) { |
|
5368 |
/* |
|
5369 |
* same color again - reuse last bestMatch |
|
5370 |
*/ |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5371 |
} else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5372 |
#endif |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5373 |
{ |
882 | 5374 |
__wR = __wantR; |
5375 |
__wG = __wantG; |
|
5376 |
__wB = __wantB; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5377 |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5378 |
#ifdef FAST_LOOKUP |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5379 |
if(__wR > 255) __wR = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5380 |
else if (__wR < 0) __wR = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5381 |
if(__wG > 255) __wG = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5382 |
else if (__wG < 0) __wG = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5383 |
if(__wB > 255) __wB = 255; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5384 |
else if (__wB < 0) __wB = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5385 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5386 |
{ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5387 |
int lookupIndex; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5388 |
int idx, idx0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5389 |
int d, delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5390 |
unsigned char *dp0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5391 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5392 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5393 |
lookupIndex = __qScramble[((__wR & 0xF0)>>4)]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5394 |
lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5395 |
lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5396 |
idx = bestIdx =__clrLookup[lookupIndex]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5397 |
dp += (idx+idx+idx); |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5398 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5399 |
/* try color at lookupIndex */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5400 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5401 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5402 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5403 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5404 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5405 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5406 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5407 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5408 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5409 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5410 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5411 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5412 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5413 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5414 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5415 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5416 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5417 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5418 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5419 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5420 |
# ifndef ONE_SHOT |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5421 |
idx0 = idx; dp0 = dp; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5422 |
cnt = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5423 |
while ((++cnt <= NPROBE) && (idx > 0)) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5424 |
/* try previous color(s) */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5425 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5426 |
idx--; dp -= 3; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5427 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5428 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5429 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5430 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5431 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5432 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5433 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5434 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5435 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5436 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5437 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5438 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5439 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5440 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5441 |
if (delta < minDelta) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5442 |
bestIdx = idx; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5443 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5444 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5445 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5446 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5447 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5448 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5449 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5450 |
idx = idx0; dp = dp0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5451 |
cnt = 0; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5452 |
while ((++cnt <= NPROBE) && (++idx < __nColors)) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5453 |
/* try next color */ |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5454 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5455 |
dp += 3; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5456 |
d = dp[0]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5457 |
delta = (__wR - d) * RED_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5458 |
if (delta < 0) delta = -delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5459 |
d = dp[1]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5460 |
if (__wG > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5461 |
delta += (__wG - d) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5462 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5463 |
delta += (d - __wG) * GREEN_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5464 |
d = dp[2]; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5465 |
if (__wB > d) |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5466 |
delta += (__wB - d) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5467 |
else |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5468 |
delta += (d - __wB) * BLUE_SCALE; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5469 |
|
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5470 |
if (delta < minDelta) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5471 |
bestIdx = idx; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5472 |
if (delta <= GOOD_DELTA) { |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5473 |
goto foundBest; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5474 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5475 |
minDelta = delta; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5476 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5477 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5478 |
# endif |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5479 |
} |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5480 |
foundBest: ; |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5481 |
#else |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5482 |
/* |
882 | 5483 |
if(__wR > 255) __wR = 255; |
5484 |
else if (__wR < 0) __wR = 0; |
|
5485 |
if(__wG > 255) __wG = 255; |
|
5486 |
else if (__wG < 0) __wG = 0; |
|
5487 |
if(__wB > 255) __wB = 255; |
|
5488 |
else if (__wB < 0) __wB = 0; |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5489 |
*/ |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5490 |
|
882 | 5491 |
/* find the best matching color */ |
5492 |
||
5493 |
minDelta = 99999; |
|
5494 |
bestIdx = -1; |
|
5495 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
5496 |
for (idx = 0; idx<__nColors; idx++) { |
|
5497 |
int d, delta; |
|
5498 |
||
5499 |
d = dp[0]; |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5500 |
delta = (__wR - d) * RED_SCALE; |
882 | 5501 |
if (delta < 0) delta = -delta; |
878 | 5502 |
if (delta < minDelta) { |
882 | 5503 |
d = dp[1]; |
5504 |
if (__wG > d) |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5505 |
delta += (__wG - d) * GREEN_SCALE; |
878 | 5506 |
else |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5507 |
delta += (d - __wG) * GREEN_SCALE; |
878 | 5508 |
if (delta < minDelta) { |
882 | 5509 |
d = dp[2]; |
5510 |
if (__wB > d) |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5511 |
delta += (__wB - d) * BLUE_SCALE; |
882 | 5512 |
else |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5513 |
delta += (d - __wB) * BLUE_SCALE; |
882 | 5514 |
|
5515 |
if (delta < minDelta) { |
|
5516 |
bestIdx = idx; |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5517 |
if (delta <= GOOD_DELTA) { |
882 | 5518 |
break; |
5519 |
} |
|
5520 |
minDelta = delta; |
|
878 | 5521 |
} |
5522 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5523 |
} |
882 | 5524 |
dp += 3; |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5525 |
} |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
5526 |
#endif |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5527 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5528 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5529 |
dp += bestIdx * 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5530 |
dR = dp[0]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5531 |
dG = dp[1]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5532 |
dB = dp[2]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5533 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5534 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5535 |
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
|
5536 |
__wantR, __wantG, __wantB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5537 |
__wR, __wG, __wB, |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5538 |
dR, dG, dB); |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5539 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5540 |
/* |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5541 |
* store the corresponding dither colors colorId |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5542 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5543 |
*dstP++ = idP[bestIdx]; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5544 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5545 |
/* |
882 | 5546 |
* the new error & distribute the error |
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5547 |
*/ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5548 |
__eR = __wantR - dR; |
882 | 5549 |
if (__eR) { |
5550 |
tR = __eR >> 4; /* 16th of error */ |
|
5551 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
5552 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
5553 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
5554 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
5555 |
__eR = nR; |
|
5556 |
} else { |
|
5557 |
__eR = eP[3]; |
|
5558 |
eP[0] = eP[-3] = eP[3] = 0; |
|
5559 |
} |
|
5560 |
||
5561 |
__eG = __wantG - dG; |
|
5562 |
if (__eG) { |
|
5563 |
tG = __eG >> 4; |
|
5564 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
5565 |
eP[1] = tG*5; |
|
5566 |
eP[-2] = tG*3; |
|
5567 |
eP[4] = __eG - (tG*15); |
|
5568 |
__eG = nG; |
|
5569 |
} else { |
|
5570 |
__eG = eP[4]; |
|
5571 |
eP[1] = eP[-2] = eP[4] = 0; |
|
5572 |
} |
|
5573 |
||
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5574 |
__eB = __wantB - dB; |
882 | 5575 |
if (__eB) { |
5576 |
tB = __eB >> 4; |
|
5577 |
nB = eP[5] + (tB * 7); |
|
5578 |
eP[2] = tB*5; |
|
5579 |
eP[-1] = tB*3; |
|
5580 |
eP[5] = __eB - (tB*15); |
|
5581 |
__eB = nB; |
|
5582 |
} else { |
|
5583 |
__eB = eP[5]; |
|
5584 |
eP[2] = eP[-1] = eP[5] = 0; |
|
5585 |
} |
|
874
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5586 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5587 |
eP += 3; |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5588 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5589 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5590 |
} |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5591 |
%}. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5592 |
failed ifTrue:[ |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5593 |
self primitiveFailed. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5594 |
^ nil |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5595 |
]. |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5596 |
|
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5597 |
^ pseudoBits |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5598 |
! |
cce9c1029d38
added floydSteinberg dithering for pseudo-8 images
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
5599 |
|
854 | 5600 |
floydSteinbergDitheredDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
858 | 5601 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
5602 |
which must be a depth-8 image. |
|
5603 |
This is a special-cased dither method for 8-bit palette images being displayed on |
|
5604 |
an 8-bit pseudoColor display, AND fixColor dithering is used. |
|
854 | 5605 |
Use the colors in the fixColors array, which must be fixR x fixG x fixB |
5606 |
colors assigned to aDevice, such as the preallocated colors of the |
|
5607 |
Color class. |
|
5608 |
By passing the ditherColors as extra array, this method can |
|
5609 |
also be used to dither an 8bit image into a smaller number of colors, |
|
5610 |
for example to create dithered Depth4Images from Depth8Images." |
|
5611 |
||
858 | 5612 |
|pseudoBits |
854 | 5613 |
rgbBytes |
5614 |
w "{Class: SmallInteger }" |
|
5615 |
h "{Class: SmallInteger }" |
|
5616 |
index "{Class: SmallInteger }" |
|
5617 |
fixR "{Class: SmallInteger }" |
|
5618 |
fixG "{Class: SmallInteger }" |
|
5619 |
fixB "{Class: SmallInteger }" |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5620 |
fixGfixB |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5621 |
fixIds failed map lastColor |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5622 |
rgbIDX "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5623 |
idxAndErrRBytes idxAndErrGBytes idxAndErrBBytes |
854 | 5624 |
error clr| |
5625 |
||
858 | 5626 |
self depth ~~ 8 ifTrue:[^ nil]. |
5627 |
||
854 | 5628 |
fixR := nRed. |
5629 |
fixR == 0 ifTrue:[ ^ nil]. |
|
5630 |
fixG := nGreen. |
|
5631 |
fixG == 0 ifTrue:[ ^ nil]. |
|
5632 |
fixB := nBlue. |
|
5633 |
fixB == 0 ifTrue:[ ^ nil]. |
|
5634 |
||
5635 |
"/ simple check |
|
5636 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
5637 |
self error:'invalid color array passed'. |
|
5638 |
^ nil |
|
5639 |
]. |
|
5640 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
5641 |
||
5642 |
"/ |
|
5643 |
"/ collect color components as integer values (for integer arithmetic) |
|
5644 |
"/ |
|
5645 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
|
5646 |
||
5647 |
index := 1. |
|
5648 |
||
5649 |
photometric == #palette ifTrue:[ |
|
5650 |
lastColor := colorMap size - 1 |
|
5651 |
] ifFalse:[ |
|
5652 |
lastColor := 255. |
|
5653 |
]. |
|
5654 |
0 to:lastColor do:[:pix | |
|
5655 |
clr := self colorFromValue:pix. |
|
5656 |
rgbBytes at:index put:(clr redByte). |
|
5657 |
rgbBytes at:index+1 put:(clr greenByte). |
|
5658 |
rgbBytes at:index+2 put:(clr blueByte). |
|
5659 |
||
5660 |
index := index + 3. |
|
5661 |
]. |
|
5662 |
||
5663 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
5664 |
||
5665 |
w := width + 2. |
|
5666 |
error := ByteArray uninitializedNew:w*(3*2). |
|
5667 |
||
5668 |
w := width. |
|
5669 |
h := height. |
|
5670 |
||
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5671 |
idxAndErrRBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5672 |
idxAndErrGBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5673 |
idxAndErrBBytes := ByteArray uninitializedNew:256*2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5674 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5675 |
fixGfixB := fixG * fixB. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5676 |
index := 1. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5677 |
0 to:255 do:[:i | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5678 |
rgbIDX := (i * (fixR-1) + 128) // 255. "red index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5679 |
idxAndErrRBytes at:index put:(rgbIDX * fixGfixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5680 |
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
|
5681 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5682 |
rgbIDX := (i * (fixG-1) + 128) // 255. "green index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5683 |
idxAndErrGBytes at:index put:(rgbIDX * fixB). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5684 |
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
|
5685 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5686 |
rgbIDX := (i * (fixB-1) + 128) // 255. "blue index rounded" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5687 |
idxAndErrBBytes at:index put:(rgbIDX ). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5688 |
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
|
5689 |
index := index + 2. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5690 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5691 |
|
854 | 5692 |
failed := true. |
5693 |
||
5694 |
%{ |
|
5695 |
int __x, __y; |
|
5696 |
int __eR, __eG, __eB; |
|
5697 |
unsigned char *srcP, *dstP; |
|
5698 |
unsigned char *rgbP; |
|
5699 |
unsigned char *idP; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5700 |
unsigned char *__idxAndErrRBytes, *__idxAndErrGBytes, *__idxAndErrBBytes; |
854 | 5701 |
short *errP, *eP; |
5702 |
int idx; |
|
5703 |
int __w = __intVal(w); |
|
5704 |
||
5705 |
if (__isByteArray(__INST(bytes)) |
|
5706 |
&& __isByteArray(pseudoBits) |
|
5707 |
&& __isByteArray(rgbBytes) |
|
5708 |
&& __isByteArray(fixIds) |
|
5709 |
&& __isByteArray(error) |
|
5710 |
&& __bothSmallInteger(fixR, fixG) |
|
5711 |
&& __isSmallInteger(fixB)) { |
|
5712 |
failed = false; |
|
5713 |
||
5714 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
5715 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
5716 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
|
5717 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5718 |
__idxAndErrRBytes = __ByteArrayInstPtr(idxAndErrRBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5719 |
__idxAndErrGBytes = __ByteArrayInstPtr(idxAndErrGBytes)->ba_element; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5720 |
__idxAndErrBBytes = __ByteArrayInstPtr(idxAndErrBBytes)->ba_element; |
854 | 5721 |
errP = (short *) _ByteArrayInstPtr(error)->ba_element; |
5722 |
||
5723 |
/* |
|
5724 |
* clear error accumulator |
|
5725 |
*/ |
|
5726 |
eP = errP; |
|
5727 |
bzero(eP, (__w+2) * 2 * 3); |
|
5728 |
||
5729 |
for (__y=__intVal(h); __y>0; __y--) { |
|
5730 |
__eR = __eG = __eB = 0; |
|
5731 |
||
5732 |
eP = &(errP[3]); |
|
5733 |
__eR = eP[0]; |
|
5734 |
__eG = eP[1]; |
|
5735 |
__eB = eP[2]; |
|
5736 |
||
5737 |
for (__x=__w; __x>0; __x--) { |
|
5738 |
int __want; |
|
5739 |
int pix; |
|
5740 |
int idx; |
|
5741 |
int tR, tG, tB; |
|
5742 |
int nR, nG, nB; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5743 |
int iRGB; |
854 | 5744 |
|
5745 |
pix = *srcP++; |
|
5746 |
||
5747 |
/* |
|
5748 |
* wR, wG and wB is the wanted r/g/b value; |
|
5749 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5750 |
pix = pix+pix+pix; /* pix * 3 */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5751 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5752 |
/* |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5753 |
* compute indexR/G/B and the new error: |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5754 |
*/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5755 |
__want = rgbP[pix] + __eR; |
854 | 5756 |
if (__want > 255) __want = 255; |
5757 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5758 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5759 |
idx = __idxAndErrRBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5760 |
__eR = __idxAndErrRBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5761 |
__eR -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5762 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5763 |
__want = rgbP[pix+1] + __eG; |
854 | 5764 |
if (__want > 255) __want = 255; |
5765 |
else if (__want < 0) __want = 0; |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5766 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5767 |
idx += __idxAndErrGBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5768 |
__eG = __idxAndErrGBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5769 |
__eG -= 128; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5770 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5771 |
__want = rgbP[pix+2] + __eB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5772 |
if (__want > 255) __want = 255; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5773 |
else if (__want < 0) __want = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5774 |
__want += __want; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5775 |
idx += __idxAndErrBBytes[__want]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5776 |
__eB = __idxAndErrBBytes[__want+1]; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5777 |
__eB -= 128; |
854 | 5778 |
|
5779 |
/* |
|
5780 |
* store the corresponding dither colors colorId |
|
5781 |
*/ |
|
5782 |
*dstP++ = idP[idx]; |
|
5783 |
||
5784 |
/* |
|
5785 |
* distribute the error |
|
5786 |
*/ |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5787 |
if (__eR) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5788 |
tR = __eR >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5789 |
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
|
5790 |
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
|
5791 |
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
|
5792 |
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
|
5793 |
__eR = nR; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5794 |
} else { |
882 | 5795 |
__eR = eP[3]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5796 |
eP[0] = eP[-3] = eP[3] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5797 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5798 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5799 |
if (__eG) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5800 |
tG = __eG >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5801 |
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
|
5802 |
eP[1] = tG*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5803 |
eP[-2] = tG*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5804 |
eP[4] = __eG - (tG*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5805 |
__eG = nG; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5806 |
} else { |
882 | 5807 |
__eG = eP[4]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5808 |
eP[1] = eP[-2] = eP[4] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5809 |
} |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5810 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5811 |
if (__eB) { |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5812 |
tB = __eB >> 4; /* 16th of error */ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5813 |
nB = eP[5] + (tB * 7); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5814 |
eP[2] = tB*5; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5815 |
eP[-1] = tB*3; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5816 |
eP[5] = __eB - (tB*15); |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5817 |
__eB = nB; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5818 |
} else { |
882 | 5819 |
__eB = eP[5]; |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5820 |
eP[2] = eP[-1] = eP[5] = 0; |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
5821 |
} |
854 | 5822 |
|
5823 |
eP += 3; |
|
5824 |
} |
|
5825 |
} |
|
5826 |
} |
|
5827 |
%}. |
|
5828 |
failed ifTrue:[ |
|
5829 |
self primitiveFailed. |
|
5830 |
^ nil |
|
5831 |
]. |
|
5832 |
||
5833 |
^ pseudoBits |
|
5834 |
||
5835 |
||
5836 |
! |
|
5837 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5838 |
floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5839 |
"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
|
5840 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5841 |
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
|
5842 |
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
|
5843 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5844 |
|dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5845 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5846 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5847 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5848 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5849 |
nextErrorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5850 |
e eD t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5851 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5852 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5853 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5854 |
byte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5855 |
grey dT |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5856 |
eR eRB eB eLB | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5857 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5858 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5859 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5860 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5861 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5862 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5863 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5864 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5865 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5866 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5867 |
errorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5868 |
nextErrorArray := Array new:w+2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5869 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5870 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5871 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5872 |
dstIndex := 1. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5873 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5874 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5875 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5876 |
self depth <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5877 |
"/ 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
|
5878 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5879 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5880 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5881 |
greyValues := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5882 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5883 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5884 |
v rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5885 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5886 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5887 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5888 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5889 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5890 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5891 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5892 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5893 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5894 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5895 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5896 |
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
|
5897 |
%{ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5898 |
int __grey, __e; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5899 |
int __byte = __intVal(byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5900 |
OBJ *__errorArray = __ArrayInstPtr(errorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5901 |
OBJ *__nextErrorArray = __ArrayInstPtr(nextErrorArray)->a_element; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5902 |
int __x = __intVal(x); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5903 |
int __eR, __eB, __eRB, __eLB, __eI; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5904 |
int __bitCnt = __intVal(bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5905 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5906 |
__grey = __intVal(__ArrayInstPtr(greyValues)->a_element[__intVal(pixel)]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5907 |
__grey += __intVal(__errorArray[__x+1]); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5908 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5909 |
__byte <<= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5910 |
if (__grey > 127*1024) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5911 |
__e = __grey - (255*1024); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5912 |
__byte |= 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5913 |
} else { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5914 |
__e = __grey; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5915 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5916 |
if (__e) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5917 |
__eI = __e >> 4; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5918 |
__eR = __eI * 7; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5919 |
__eRB = __eI * 1; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5920 |
__eB = __eI * 5; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5921 |
__eLB = __e - __eR - __eRB - __eB; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5922 |
__errorArray[__x+2] = __MKSMALLINT(__intVal(__errorArray[__x+2]) + __eR); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5923 |
__nextErrorArray[__x+2] = __MKSMALLINT(__intVal(__nextErrorArray[__x+2]) + __eRB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5924 |
__nextErrorArray[__x+1] = __MKSMALLINT(__intVal(__nextErrorArray[__x+1]) + __eB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5925 |
__nextErrorArray[__x ] = __MKSMALLINT(__intVal(__nextErrorArray[__x ]) + __eLB); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5926 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5927 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5928 |
__bitCnt--; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5929 |
if (__bitCnt == 0) { |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5930 |
int __dstIndex = __intVal(dstIndex); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5931 |
|
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5932 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIndex-1] = __byte; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5933 |
dstIndex = __MKSMALLINT(__dstIndex + 1); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5934 |
__byte = 0; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5935 |
__bitCnt = 8; |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5936 |
} |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5937 |
byte = __MKSMALLINT(__byte); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5938 |
bitCnt = __MKSMALLINT(__bitCnt); |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5939 |
%}. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5940 |
|
829 | 5941 |
"/ |eI "{ Class: SmallInteger }" |
5942 |
"/ xE "{ Class: SmallInteger }" |
|
5943 |
"/ xN "{ Class: SmallInteger }" | |
|
5944 |
"/ |
|
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5945 |
"/ "/ get the colors grey value [0 .. 1] |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5946 |
"/ grey := greyValues at:(pixel + 1). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5947 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5948 |
"/ "/ adjust error |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5949 |
"/ xE := x + 2. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5950 |
"/ grey := (grey + (errorArray at:xE)). |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5951 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5952 |
"/ byte := byte bitShift:1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5953 |
"/ grey > (127*1024) ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5954 |
"/ byte := byte bitOr:1. "/ white |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5955 |
"/ e := grey - (255*1024) |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5956 |
"/ ] ifFalse:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5957 |
"/ e := grey "/ black |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5958 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5959 |
"/ e ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5960 |
"/ eD := e. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5961 |
"/ eI := e // 16. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5962 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5963 |
"/ eR := eI * 7. "/ 7/16 to right |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5964 |
"/ eRB := eI * 1. "/ 1/16 to right below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5965 |
"/ eB := eI * 5. "/ 5/16 to below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5966 |
"/ eLB := eD - eR - eRB - eB. "/ 3/16 to left below |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5967 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5968 |
"/ xN := xE + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5969 |
"/ eR ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5970 |
"/ errorArray at:xN put:(errorArray at:xN) + eR. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5971 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5972 |
"/ eRB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5973 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eRB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5974 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5975 |
"/ eB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5976 |
"/ nextErrorArray at:xE put:(nextErrorArray at:xE) + eB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5977 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5978 |
"/ eLB ~= 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5979 |
"/ xN := xE - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5980 |
"/ nextErrorArray at:xN put:(nextErrorArray at:xN) + eLB. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5981 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5982 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5983 |
"/ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5984 |
"/ bitCnt := bitCnt - 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5985 |
"/ bitCnt == 0 ifTrue:[ |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5986 |
"/ monoBits at:dstIndex put:byte. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5987 |
"/ dstIndex := dstIndex + 1. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5988 |
"/ byte := 0. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5989 |
"/ bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5990 |
"/ ]. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5991 |
0 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5992 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5993 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5994 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5995 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5996 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
5997 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5998 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
5999 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6000 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6001 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6002 |
] ifFalse:[ |
1167 | 6003 |
'Image [info]: slow floydSteinberg dither ..' infoPrintCR. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6004 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6005 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6006 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6007 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6008 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6009 |
errorArray := nextErrorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6010 |
nextErrorArray := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6011 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6012 |
nextErrorArray atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6013 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6014 |
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
|
6015 |
|eI "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6016 |
xE "{ Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6017 |
xN "{ Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6018 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6019 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6020 |
grey := (clr brightness * 255). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6021 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6022 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6023 |
xE := x + 2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6024 |
grey := (grey + (errorArray at:xE)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6025 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6026 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6027 |
grey > 127 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6028 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6029 |
e := grey - 255 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6030 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6031 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6032 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6033 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6034 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6035 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6036 |
eI := e // 16. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6037 |
eR := eI * 7. "/ 7/16 to right |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6038 |
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
|
6039 |
eB := eI * 5. "/ 5/16 to below |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6040 |
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
|
6041 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6042 |
xN := xE + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6043 |
eR ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6044 |
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
|
6045 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6046 |
eRB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6047 |
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
|
6048 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6049 |
eB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6050 |
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
|
6051 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6052 |
eLB ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6053 |
xN := xE - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6054 |
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
|
6055 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6056 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6057 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6058 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6059 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6060 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6061 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6062 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6063 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6064 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6065 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6066 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6067 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6068 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6069 |
monoBits at:dstIndex put:byte. |
828
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
6070 |
bitCnt := 8. |
e5cc03d2c673
integerized floydSteinberg code
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
6071 |
byte := 0. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6072 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6073 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6074 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6075 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6076 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6077 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6078 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6079 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6080 |
"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
|
6081 |
"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
|
6082 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6083 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6084 |
nearestPaintDepth8BitsColors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6085 |
"return a nearest paint bitmap from the receiver picture, |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6086 |
which must be a depth-8 image. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6087 |
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
|
6088 |
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
|
6089 |
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
|
6090 |
colors assigned to aDevice, such as the preallocated colors of the |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6091 |
Color class." |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6092 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6093 |
|pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6094 |
fixR "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6095 |
fixG "{Class: SmallInteger }" |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6096 |
fixB "{Class: SmallInteger }" |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6097 |
fixGfixB |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6098 |
r "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6099 |
g "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6100 |
b "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6101 |
idx "{Class: SmallInteger }" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6102 |
idMap lastColor |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6103 |
clr| |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6104 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6105 |
self depth ~~ 8 ifTrue:[^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6106 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6107 |
fixR := nRed. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6108 |
fixR == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6109 |
fixG := nGreen. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6110 |
fixG == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6111 |
fixB := nBlue. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6112 |
fixB == 0 ifTrue:[ ^ nil]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6113 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6114 |
"/ simple check |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6115 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6116 |
self error:'invalid color array passed'. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6117 |
^ nil |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6118 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6119 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6120 |
"/ |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6121 |
"/ collect colorIds |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6122 |
"/ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6123 |
photometric == #palette ifTrue:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6124 |
lastColor := colorMap size - 1 |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6125 |
] ifFalse:[ |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6126 |
lastColor := 255. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6127 |
]. |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6128 |
fixGfixB := fixG * fixB. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6129 |
|
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6130 |
idMap := ByteArray uninitializedNew:256. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6131 |
|
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6132 |
0 to:lastColor do:[:pix | |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6133 |
clr := self colorFromValue:pix. |
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6134 |
r := clr redByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6135 |
g := clr greenByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6136 |
b := clr blueByte. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6137 |
idx := ((r * (fixR-1) + 128) // 255) * fixGfixB. |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6138 |
idx := idx + (((g * (fixG-1) + 128) // 255) * fixB). |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6139 |
idx := idx + ((b * (fixB-1) + 128) // 255). |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6140 |
idMap at:(pix+1) put:(fixColors at:(idx+1)) colorId. |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6141 |
]. |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6142 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6143 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6144 |
|
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6145 |
"/ translate |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6146 |
|
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6147 |
bytes expandPixels:8 "xlate only" |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6148 |
width:width |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6149 |
height:height |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6150 |
into:pseudoBits |
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6151 |
mapping:idMap. |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6152 |
|
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6153 |
^ pseudoBits |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6154 |
|
884
d7cc8a20505b
oops - nearest paint color conversion can be done much faster
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
6155 |
"Modified: 18.6.1996 / 09:18:09 / cg" |
879
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6156 |
! |
2adf7645e7e6
added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents:
878
diff
changeset
|
6157 |
|
903
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6158 |
nfloydSteinbergDitheredDepth8BitsColors:colors |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6159 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6160 |
which must be a depth-8 image. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6161 |
This method expects an array of colors to be used for dithering |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6162 |
(which need not be a colorCubes colors)." |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6163 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6164 |
|pseudoBits |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6165 |
rgbBytes |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6166 |
ditherRGBBytes ditherColors |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6167 |
w "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6168 |
h "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6169 |
index "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6170 |
numR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6171 |
numG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6172 |
numB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6173 |
bitsR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6174 |
bitsG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6175 |
bitsB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6176 |
maxBits "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6177 |
maskR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6178 |
maskG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6179 |
maskB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6180 |
shR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6181 |
shG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6182 |
shB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6183 |
ditherIds failed map lastColor colorsByDistance qScramble |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6184 |
clrLookup lookupPos cube nCube |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6185 |
dR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6186 |
dG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6187 |
dB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6188 |
iR "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6189 |
iRG "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6190 |
iRGB "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6191 |
clr |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6192 |
rI "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6193 |
gI "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6194 |
bI "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6195 |
maxIDX "{Class: SmallInteger }" |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6196 |
subCubeColorCollection |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6197 |
error |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6198 |
dl "{Class: SmallInteger }"| |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6199 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6200 |
self depth ~~ 8 ifTrue:[^ nil]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6201 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6202 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6203 |
"/ collect color components as integer values (for integer arithmetic) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6204 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6205 |
rgbBytes := ByteArray uninitializedNew:256 * 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6206 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6207 |
photometric == #palette ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6208 |
lastColor := colorMap size - 1 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6209 |
] ifFalse:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6210 |
lastColor := 255. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6211 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6212 |
index := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6213 |
0 to:lastColor do:[:pix | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6214 |
clr := self colorFromValue:pix. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6215 |
rgbBytes at:index put:(clr redByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6216 |
rgbBytes at:index+1 put:(clr greenByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6217 |
rgbBytes at:index+2 put:(clr blueByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6218 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6219 |
index := index + 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6220 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6221 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6222 |
"/ collect valid ditherColors ... |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6223 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6224 |
ditherColors := colors select:[:clr | clr notNil]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6225 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6226 |
"/ collect ditherColor components |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6227 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6228 |
lastColor := ditherColors size. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6229 |
ditherIds := ByteArray uninitializedNew:lastColor. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6230 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6231 |
index := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6232 |
1 to:lastColor do:[:pix | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6233 |
clr := ditherColors at:pix. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6234 |
ditherRGBBytes at:index put:(clr redByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6235 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6236 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6237 |
ditherIds at:pix put:clr colorId. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6238 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6239 |
index := index + 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6240 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6241 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6242 |
"/ place the ditherColor positions into a color cube |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6243 |
bitsR := 5. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6244 |
bitsG := 6. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6245 |
bitsB := 4. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6246 |
maxBits := 6. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6247 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6248 |
"/ bitsR := 4. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6249 |
"/ bitsG := 4. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6250 |
"/ bitsB := 3. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6251 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6252 |
numR := 1 bitShift:bitsR. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6253 |
numG := 1 bitShift:bitsG. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6254 |
numB := 1 bitShift:bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6255 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6256 |
maskR := (numR-1) bitShift:(bitsG + bitsB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6257 |
maskG := (numG-1) bitShift:bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6258 |
maskB := numB-1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6259 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6260 |
shR := -16+bitsR+bitsG+bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6261 |
shG := -16+bitsG+bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6262 |
shB := -16+bitsB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6263 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6264 |
maxIDX := numR*numG*numB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6265 |
cube := Array new:maxIDX. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6266 |
1 to:lastColor do:[:clrIdx | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6267 |
clr := ditherColors at:clrIdx. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6268 |
rI := clr scaledRed. rI := (rI bitShift:shR) bitAnd:maskR. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6269 |
gI := clr scaledGreen. gI := (gI bitShift:shG) bitAnd:maskG. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6270 |
bI := clr scaledBlue. bI := (bI bitShift:shB) bitAnd:maskB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6271 |
index := rI + gI + bI + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6272 |
subCubeColorCollection := cube at:index. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6273 |
subCubeColorCollection isNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6274 |
subCubeColorCollection := OrderedCollection new. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6275 |
cube at:index put:subCubeColorCollection. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6276 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6277 |
subCubeColorCollection add:(clrIdx - 1). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6278 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6279 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6280 |
shR := 1 bitShift:(bitsG+bitsB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6281 |
shG := 1 bitShift:(bitsB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6282 |
shB := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6283 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6284 |
1 to:maxIDX do:[:i | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6285 |
subCubeColorCollection := cube at:i. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6286 |
subCubeColorCollection notNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6287 |
cube at:i put:(subCubeColorCollection asByteArray) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6288 |
] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6289 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6290 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6291 |
"/ nCube := cube copy. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6292 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6293 |
"/ cube keysAndValuesDo:[:i :indices | |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6294 |
"/ indices notNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6295 |
"/ nCube at:i put:(indices asByteArray) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6296 |
"/ ] ifFalse:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6297 |
"/ "/ find nearest color |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6298 |
"/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6299 |
"/ dl := 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6300 |
"/ [dl < maxBits] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6301 |
"/ dR := dl negated. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6302 |
"/ [dR <= dl] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6303 |
"/ iR := i + (dR * shR). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6304 |
"/ (iR > 0 and:[iR < maxIDX]) ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6305 |
"/ dG := dl negated. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6306 |
"/ [dG < dl] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6307 |
"/ iRG := iR + (dG * shG). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6308 |
"/ (iRG > 0 and:[iRG < maxIDX]) ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6309 |
"/ dB := dl negated. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6310 |
"/ [dB < dl] whileTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6311 |
"/ iRGB := iRG + dB. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6312 |
"/ (iRG > 0 and:[iRG < maxIDX]) ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6313 |
"/ (cube at:iRGB) notNil ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6314 |
"/ nCube at:i put:(cube at:iRGB). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6315 |
"/ dB := dG := dR := dl := 999. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6316 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6317 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6318 |
"/ dB := dB + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6319 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6320 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6321 |
"/ dG := dG + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6322 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6323 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6324 |
"/ dR := dR + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6325 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6326 |
"/ dl := dl + 1. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6327 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6328 |
"/ ] |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6329 |
"/ ]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6330 |
"/self halt. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6331 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6332 |
"/ now, cube contains collections of colors which are |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6333 |
"/ positioned in a subCube; quickly accessed by a lookup |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6334 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6335 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6336 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6337 |
w := width. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6338 |
h := height. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6339 |
error := ByteArray new:(w+2)*3*2. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6340 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6341 |
%{ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6342 |
#define BITSR 5 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6343 |
#define BITSG 6 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6344 |
#define BITSB 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6345 |
#define MAXBITS 6 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6346 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6347 |
#define xBITSR 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6348 |
#define xBITSG 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6349 |
#define xBITSB 3 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6350 |
#define xMAXBITS 4 |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6351 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6352 |
#define NR 32 /* (1<<BITSR) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6353 |
#define NG 64 /* (1<<BITSG) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6354 |
#define NB 16 /* (1<<BITSB) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6355 |
#define MAXRGB 64 /* (1<<MAXBITS) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6356 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6357 |
#define SHR (BITSG+BITSB) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6358 |
#define SHG BITSB |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6359 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6360 |
#define REMEMBER_SEARCH |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6361 |
#define xNO_FLOYD_STEINBERG |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6362 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6363 |
int __x, __y; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6364 |
int __eR, __eG, __eB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6365 |
unsigned char *srcP, *dstP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6366 |
unsigned char *rgbP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6367 |
unsigned char *idP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6368 |
unsigned char *dp; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6369 |
short *errP, *eP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6370 |
int __fR, __fG, __fB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6371 |
int idx; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6372 |
int __w = __intVal(w); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6373 |
int __h = __intVal(h); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6374 |
int __nColors = __intVal(lastColor); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6375 |
int __wR = -1, __wG, __wB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6376 |
OBJ *__cube; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6377 |
OBJ subCubeColors; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6378 |
int cubeIndex, cubeIndex2; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6379 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6380 |
if (__isByteArray(__INST(bytes)) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6381 |
&& __isByteArray(pseudoBits) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6382 |
&& __isByteArray(rgbBytes) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6383 |
&& __isByteArray(ditherRGBBytes) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6384 |
&& __isByteArray(ditherIds) |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6385 |
&& __isByteArray(error)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6386 |
failed = false; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6387 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6388 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6389 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6390 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6391 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6392 |
errP = (short *) __ByteArrayInstPtr(error)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6393 |
__cube = __ArrayInstPtr(cube)->a_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6394 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6395 |
eP = errP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6396 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6397 |
for (__y=__h; __y>0; __y--) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6398 |
eP = &(errP[3]); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6399 |
__eR = eP[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6400 |
__eG = eP[1]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6401 |
__eB = eP[2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6402 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6403 |
for (__x=__w; __x>0; __x--) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6404 |
int __want; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6405 |
int pix; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6406 |
int __wantR, __wantG, __wantB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6407 |
int idx; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6408 |
int tR, tG, tB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6409 |
int nR, nG, nB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6410 |
int __dR, __dG, __dB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6411 |
int minDelta, bestIdx; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6412 |
int __iR, __iG, __iB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6413 |
int cR, cG, cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6414 |
int delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6415 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6416 |
pix = *srcP++; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6417 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6418 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6419 |
* wR, wG and wB is the wanted r/g/b value; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6420 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6421 |
idx = pix+pix+pix; /* pix * 3 */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6422 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6423 |
__wR = __wantR = rgbP[idx] + __eR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6424 |
__wG = __wantG = rgbP[idx+1] + __eG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6425 |
__wB = __wantB = rgbP[idx+2] + __eB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6426 |
if(__wR > 255) __wR = 255; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6427 |
else if (__wR < 0) __wR = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6428 |
if(__wG > 255) __wG = 255; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6429 |
else if (__wG < 0) __wG = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6430 |
if(__wB > 255) __wB = 255; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6431 |
else if (__wB < 0) __wB = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6432 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6433 |
__iR = __wR >> (8-BITSR); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6434 |
__iG = __wG >> (8-BITSG); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6435 |
__iB = __wB >> (8-BITSB); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6436 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6437 |
cubeIndex = (__iR<<SHR) + (__iG<<SHG) + __iB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6438 |
subCubeColors = __cube[cubeIndex]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6439 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6440 |
if (subCubeColors == nil) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6441 |
/* search around in spirals, for the first match */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6442 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6443 |
delta = 1; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6444 |
while (delta < MAXRGB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6445 |
/* check plane above */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6446 |
cR = __iR + delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6447 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6448 |
for (cG=__iG-delta; cG<=__iG+delta; cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6449 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6450 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6451 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6452 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6453 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6454 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6455 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6456 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6457 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6458 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6459 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6460 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6461 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6462 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6463 |
/* check plane below */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6464 |
cR = __iR - delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6465 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6466 |
for (cG=__iG-delta; cG<=__iG+delta; cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6467 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6468 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6469 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6470 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6471 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6472 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6473 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6474 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6475 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6476 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6477 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6478 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6479 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6480 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6481 |
/* check plane to the right */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6482 |
cG = __iG + delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6483 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6484 |
for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6485 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6486 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6487 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6488 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6489 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6490 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6491 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6492 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6493 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6494 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6495 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6496 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6497 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6498 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6499 |
/* check plane to the left */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6500 |
cG = __iG - delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6501 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6502 |
for (cR=__iR-delta+1; cR<=__iR+delta-1; cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6503 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6504 |
for (cB=__iB-delta; cB<=__iB+delta; cB++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6505 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6506 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6507 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6508 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6509 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6510 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6511 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6512 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6513 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6514 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6515 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6516 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6517 |
/* check plane at back */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6518 |
cB = __iB + delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6519 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6520 |
for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6521 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6522 |
for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6523 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6524 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6525 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6526 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6527 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6528 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6529 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6530 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6531 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6532 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6533 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6534 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6535 |
/* check plane at front */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6536 |
cB = __iB - delta; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6537 |
if ((unsigned)cB < NB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6538 |
for (cR=__iR-delta+1; cR<=(__iR+delta-1); cR++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6539 |
if ((unsigned)cR < NR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6540 |
for (cG=__iG-delta+1; cG<=(__iG+delta-1); cG++) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6541 |
if ((unsigned)cG < NG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6542 |
cubeIndex2 = (cR<<SHR) + (cG<<SHG) + cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6543 |
subCubeColors = __cube[cubeIndex2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6544 |
if (__isNonNilObject(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6545 |
goto found; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6546 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6547 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6548 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6549 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6550 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6551 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6552 |
delta = delta + 1; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6553 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6554 |
if (InterruptPending) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6555 |
int d_srcP = srcP - __ByteArrayInstPtr(_INST(bytes))->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6556 |
int d_dstP = dstP - __ByteArrayInstPtr(pseudoBits)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6557 |
int d_errP = errP - (short *) __ByteArrayInstPtr(error)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6558 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6559 |
__interrupt__(); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6560 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6561 |
srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element + d_srcP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6562 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element + d_dstP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6563 |
rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6564 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6565 |
errP = (short *) __ByteArrayInstPtr(error)->ba_element + d_errP; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6566 |
__cube = __ArrayInstPtr(cube)->a_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6567 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6568 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6569 |
/* cannot happen - will lead to a segmentation violation ... */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6570 |
subCubeColors = nil; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6571 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6572 |
found: |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6573 |
__iR = cR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6574 |
__iG = cG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6575 |
__iB = cB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6576 |
bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6577 |
#ifdef REMEMBER_SEARCH |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6578 |
__cube[cubeIndex] = __MKSMALLINT(bestIdx); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6579 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6580 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6581 |
#ifdef REMEMBER_SEARCH |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6582 |
if (__isSmallInteger(subCubeColors)) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6583 |
bestIdx = __intVal(subCubeColors); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6584 |
} else |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6585 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6586 |
{ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6587 |
bestIdx = __ByteArrayInstPtr(subCubeColors)->ba_element[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6588 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6589 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6590 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6591 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6592 |
* ok, now, we have found a collection of nearby |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6593 |
* colors in subCubeColors. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6594 |
* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6595 |
* since the error is at most 1/16 (i.e. roughly 6%), |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6596 |
* dont care for searching the best - simply take the |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6597 |
* first color found there. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6598 |
* (statistic reduces the error to even a smaller value). |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6599 |
* There is no real problem due to that error, since |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6600 |
* it will be diffused anyway ... |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6601 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6602 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6603 |
#ifndef NO_FLOYD_STEINBERG |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6604 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6605 |
* fetch that colors r/g/b components |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6606 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6607 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6608 |
dp += bestIdx * 3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6609 |
__dR = dp[0]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6610 |
__dG = dp[1]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6611 |
__dB = dp[2]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6612 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6613 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6614 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6615 |
printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n", |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6616 |
__wantR, __wantG, __wantB, |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6617 |
__wR, __wG, __wB, |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6618 |
__dR, __dG, __dB); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6619 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6620 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6621 |
* store the corresponding dither colors colorId |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6622 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6623 |
*dstP++ = idP[bestIdx]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6624 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6625 |
#ifndef NO_FLOYD_STEINBERG |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6626 |
/* |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6627 |
* the new error & distribute the error |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6628 |
*/ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6629 |
__eR = __wantR - __dR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6630 |
if (__eR) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6631 |
tR = __eR >> 4; /* 16th of error */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6632 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6633 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6634 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6635 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6636 |
__eR = nR; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6637 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6638 |
__eR = eP[3]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6639 |
eP[0] = eP[-3] = eP[3] = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6640 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6641 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6642 |
__eG = __wantG - __dG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6643 |
if (__eG) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6644 |
tG = __eG >> 4; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6645 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6646 |
eP[1] = tG*5; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6647 |
eP[-2] = tG*3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6648 |
eP[4] = __eG - (tG*15); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6649 |
__eG = nG; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6650 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6651 |
__eG = eP[4]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6652 |
eP[1] = eP[-2] = eP[4] = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6653 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6654 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6655 |
__eB = __wantB - __dB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6656 |
if (__eB) { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6657 |
tB = __eB >> 4; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6658 |
nB = eP[5] + (tB * 7); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6659 |
eP[2] = tB*5; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6660 |
eP[-1] = tB*3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6661 |
eP[5] = __eB - (tB*15); |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6662 |
__eB = nB; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6663 |
} else { |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6664 |
__eB = eP[5]; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6665 |
eP[2] = eP[-1] = eP[5] = 0; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6666 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6667 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6668 |
eP += 3; |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6669 |
#endif |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6670 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6671 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6672 |
} |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6673 |
%}. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6674 |
failed ifTrue:[ |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6675 |
self primitiveFailed. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6676 |
^ nil |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6677 |
]. |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6678 |
|
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6679 |
^ pseudoBits |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6680 |
! |
fcb45024a286
experimental nfloydSteinberg....
Claus Gittinger <cg@exept.de>
parents:
901
diff
changeset
|
6681 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6682 |
orderedDitheredBitsDepth:depth |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6683 |
"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
|
6684 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6685 |
^ self |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6686 |
orderedDitheredBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6687 |
ditherWidth:8 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6688 |
depth:depth. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6689 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6690 |
"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
|
6691 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
6692 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6693 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6694 |
"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
|
6695 |
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
|
6696 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6697 |
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
|
6698 |
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
|
6699 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6700 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6701 |
greyLevels greyValues greyPixels greyErrors |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6702 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6703 |
nextDst |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6704 |
bytesPerOutRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6705 |
pixelsPerByte "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6706 |
outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6707 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6708 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6709 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6710 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6711 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6712 |
depth > 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6713 |
'IMAGE: unimplemented orderedDither conversion' errorPrintCR. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6714 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6715 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6716 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6717 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6718 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6719 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6720 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6721 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6722 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6723 |
greyLevels := 1 bitShift:depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6724 |
pixelsPerByte := 8 / depth. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6725 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6726 |
bytesPerOutRow := (w * depth + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6727 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6728 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6729 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6730 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6731 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6732 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6733 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6734 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6735 |
"/ 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
|
6736 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6737 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6738 |
greyValues := self greyMapForRange:(greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6739 |
greyPixels := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6740 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6741 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6742 |
v truncated]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6743 |
greyPixels := ByteArray withAll:greyPixels. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6744 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6745 |
greyErrors := greyValues collect:[:v | v isNil ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6746 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6747 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6748 |
((v - v truncated) * nDither) rounded |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6749 |
]]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6750 |
greyErrors := ByteArray withAll:greyErrors. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6751 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6752 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6753 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6754 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6755 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6756 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6757 |
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
|
6758 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6759 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6760 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6761 |
int __value = __intVal(value); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6762 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6763 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6764 |
int __pixel, __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6765 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6766 |
unsigned char *__greyPixels = __ByteArrayInstPtr(greyPixels)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6767 |
unsigned char *__greyErrors = __ByteArrayInstPtr(greyErrors)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6768 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6769 |
__pixel = __greyPixels[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6770 |
__grey = __greyErrors[__value]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6771 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6772 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6773 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6774 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6775 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6776 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6777 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6778 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6779 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6780 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6781 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6782 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6783 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6784 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6785 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6786 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6787 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6788 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6789 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6790 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6791 |
bitCnt = __MKSMALLINT(__bitCnt); |
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 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6794 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6795 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6796 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6797 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6798 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6799 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6800 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6801 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6802 |
] ifFalse:[ |
1167 | 6803 |
'Image [info]: slow ordered dither ..' infoPrintCR. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6804 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6805 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6806 |
nextDst := dstIndex + bytesPerOutRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6807 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6808 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6809 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6810 |
"/ this is the representaion independent (but slow) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6811 |
"/ 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
|
6812 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6813 |
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
|
6814 |
|dstClr grey dT pixel| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6815 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6816 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6817 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6818 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6819 |
"/ remap into [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6820 |
grey := grey * (greyLevels-1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6821 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6822 |
"/ get threshold pixel [0 .. greyLevels-1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6823 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6824 |
pixel := grey truncated. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6825 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6826 |
"/ compute the error [0..1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6827 |
grey := grey - pixel. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6828 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6829 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6830 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6831 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6832 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6833 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6834 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6835 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6836 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6837 |
int __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6838 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6839 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6840 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6841 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6842 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6843 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6844 |
__pixel = __intVal(pixel); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6845 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6846 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6847 |
__pixel++; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6848 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6849 |
__byte = (__byte << __intVal(depth)) | __pixel; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6850 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6851 |
__bitCnt = __bitCnt - __intVal(depth); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6852 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6853 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6854 |
__ByteArrayInstPtr(outBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6855 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6856 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6857 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6858 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6859 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6860 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6861 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6862 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6863 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6864 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6865 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6866 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6867 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6868 |
outBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6869 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6870 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6871 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6872 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6873 |
^ outBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6874 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6875 |
|
831 | 6876 |
orderedDitheredMonochromeBits |
6877 |
"return the bitmap for a dithered monochrome bitmap from the image; |
|
6878 |
using a default ditherMatrix." |
|
6879 |
||
6880 |
^ self |
|
6881 |
orderedDitheredMonochromeBitsWithDitherMatrix:(self class orderedDitherMatrixOfSize:8) |
|
6882 |
ditherWidth:8 |
|
6883 |
||
6884 |
"Created: 11.6.1996 / 16:48:57 / cg" |
|
6885 |
! |
|
6886 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6887 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6888 |
"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
|
6889 |
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
|
6890 |
Works for any source depths / photometric, |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6891 |
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
|
6892 |
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
|
6893 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6894 |
|f last dH nDither |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6895 |
greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6896 |
dstIndex "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6897 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6898 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6899 |
monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6900 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6901 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6902 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6903 |
byte "{Class: SmallInteger }" | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6904 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6905 |
nDither := ditherMatrix size. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6906 |
dH := nDither / dW. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6907 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6908 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6909 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6910 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6911 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6912 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6913 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6914 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6915 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6916 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6917 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6918 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6919 |
self bitsPerPixel <= 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6920 |
"/ 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
|
6921 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6922 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6923 |
greyValues := self greyByteMapForRange:nDither. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6924 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6925 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6926 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6927 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6928 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6929 |
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
|
6930 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6931 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6932 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6933 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6934 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6935 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6936 |
int __grey; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6937 |
unsigned char *__greyValues = __ByteArrayInstPtr(greyValues)->ba_element; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6938 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6939 |
__grey = __greyValues[__intVal(value)]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6940 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6941 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6942 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6943 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6944 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6945 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6946 |
if (__grey > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6947 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6948 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6949 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6950 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6951 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6952 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6953 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6954 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6955 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6956 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6957 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6958 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6959 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6960 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6961 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6962 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6963 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6964 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6965 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6966 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6967 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6968 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6969 |
] ifFalse:[ |
1167 | 6970 |
'Image [info]: slow ordered dither ..' infoPrintCR. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6971 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6972 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6973 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6974 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6975 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6976 |
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
|
6977 |
|dstClr grey dT| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6978 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6979 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6980 |
grey := clr brightness. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6981 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6982 |
"/ map into dither space [0 .. nDither] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6983 |
grey := (grey * (nDither)) rounded. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6984 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6985 |
%{ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6986 |
int __dW = __intVal(dW); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6987 |
int __byte = __intVal(byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6988 |
int __dT; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6989 |
int __dstIdx; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6990 |
int __bitCnt = __intVal(bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6991 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6992 |
__dT = __ByteArrayInstPtr(ditherMatrix) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6993 |
->ba_element[__intVal(x) % __dW |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6994 |
+ (__intVal(y) % __intVal(dH)) * __dW]; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6995 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6996 |
__byte = __byte << 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6997 |
if (__intVal(grey) > __dT) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6998 |
__byte = __byte | 1; /* white */ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
6999 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7000 |
__bitCnt = __bitCnt - 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7001 |
if (__bitCnt == 0) { |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7002 |
__dstIdx = __intVal(dstIndex); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7003 |
__ByteArrayInstPtr(monoBits)->ba_element[__dstIdx-1] = __byte; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7004 |
__dstIdx = __dstIdx + 1; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7005 |
dstIndex = __MKSMALLINT(__dstIdx); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7006 |
__byte = 0; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7007 |
__bitCnt = 8; |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7008 |
} |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7009 |
byte = __MKSMALLINT(__byte); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7010 |
bitCnt = __MKSMALLINT(__bitCnt); |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7011 |
%}. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7012 |
0 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7013 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7014 |
"/ 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
|
7015 |
"/ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7016 |
"/ byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7017 |
"/ grey < dT ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7018 |
"/ byte := byte bitOr:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7019 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7020 |
"/ bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7021 |
"/ bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7022 |
"/ monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7023 |
"/ dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7024 |
"/ byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7025 |
"/ bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7026 |
"/ ]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7027 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7028 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7029 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7030 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7031 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7032 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7033 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7034 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7035 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7036 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7037 |
! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7038 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7039 |
stevensonArceDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7040 |
"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
|
7041 |
Works for any source depths / photometric" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7042 |
|
1063 | 7043 |
|dstIndex "{Class: SmallInteger }" |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7044 |
nextDst "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7045 |
bytesPerMonoRow "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7046 |
monoBits greyValues |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7047 |
errorArray |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7048 |
errorArray1 errorArray2 errorArray3 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7049 |
e t |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7050 |
w "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7051 |
h "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7052 |
bitCnt "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7053 |
byte "{Class: SmallInteger }" |
1063 | 7054 |
grey |
7055 |
xE "{Class: SmallInteger }" | |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7056 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7057 |
self depth > 12 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7058 |
^ self floydSteinbergDitheredMonochromeBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7059 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7060 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7061 |
w := width. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7062 |
h := height. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7063 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7064 |
bytesPerMonoRow := (w + 7) // 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7065 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7066 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7067 |
^ nil |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7068 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7069 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7070 |
errorArray := Array new:(w+6). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7071 |
errorArray1 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7072 |
errorArray2 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7073 |
errorArray3 := Array new:(w+6) withAll:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7074 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7075 |
dstIndex := 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7076 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7077 |
"/ 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
|
7078 |
"/ use table-value in loop |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7079 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7080 |
greyValues := self greyMapForRange:(255 * 1024). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7081 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7082 |
0 to:(h-1) do:[:y | |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7083 |
nextDst := dstIndex + bytesPerMonoRow. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7084 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7085 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7086 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7087 |
t := errorArray. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7088 |
errorArray := errorArray1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7089 |
errorArray1 := errorArray2. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7090 |
errorArray2 := errorArray3. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7091 |
errorArray3 := t. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7092 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7093 |
errorArray3 atAllPut:0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7094 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7095 |
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
|
7096 |
|eP eD| |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7097 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7098 |
"/ get the colors grey value [0 .. 1] |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7099 |
grey := greyValues at:(pixel + 1). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7100 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7101 |
"/ adjust error |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7102 |
xE := x + 3 + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7103 |
grey := (grey + (errorArray at:xE)). |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7104 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7105 |
byte := byte bitShift:1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7106 |
grey > (127 * 1024) ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7107 |
byte := byte bitOr:1. "/ white |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7108 |
e := grey - (255 * 1024) |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7109 |
] ifFalse:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7110 |
e := grey "/ black |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7111 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7112 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7113 |
e ~= 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7114 |
"/ distribute the error: |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7115 |
"/ XX 32 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7116 |
"/ 12 26 30 16 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7117 |
"/ 12 26 12 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7118 |
"/ 5 12 12 5 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7119 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7120 |
eD := e. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7121 |
e := e // 200. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7122 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7123 |
eP := e * 32. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7124 |
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
|
7125 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7126 |
eP := e * 30. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7127 |
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
|
7128 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7129 |
eP := e * 16. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7130 |
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
|
7131 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7132 |
eP := e * 26. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7133 |
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
|
7134 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7135 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7136 |
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
|
7137 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7138 |
eP := e * 12. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7139 |
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
|
7140 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7141 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7142 |
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
|
7143 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7144 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7145 |
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
|
7146 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7147 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7148 |
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
|
7149 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7150 |
eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7151 |
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
|
7152 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7153 |
eP := e * 5. eD := eD - eP. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7154 |
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
|
7155 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7156 |
eP := eD. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7157 |
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
|
7158 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7159 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7160 |
bitCnt := bitCnt - 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7161 |
bitCnt == 0 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7162 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7163 |
dstIndex := dstIndex + 1. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7164 |
byte := 0. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7165 |
bitCnt := 8. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7166 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7167 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7168 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7169 |
bitCnt ~~ 8 ifTrue:[ |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7170 |
byte := byte bitShift:bitCnt. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7171 |
monoBits at:dstIndex put:byte. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7172 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7173 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7174 |
dstIndex := nextDst. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7175 |
]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7176 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7177 |
^ monoBits |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7178 |
|
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7179 |
"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
|
7180 |
"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
|
7181 |
! ! |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
7182 |
|
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7183 |
!Image methodsFor:'drawing'! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7184 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7185 |
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
|
7186 |
|pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7187 |
xI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7188 |
yI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7189 |
wI "{ Class: SmallInteger }" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7190 |
hI "{ Class: SmallInteger }"| |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7191 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7192 |
pixel := self valueFromColor:aColor. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7193 |
xI := x. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7194 |
yI := y. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7195 |
wI := w. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7196 |
hI := h. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7197 |
yI to:yI+hI-1 do:[:yRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7198 |
xI to:xI+wI-1 do:[:xRun | |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7199 |
self atX:xRun y:yRun putValue:pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7200 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7201 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7202 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7203 |
"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
|
7204 |
"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
|
7205 |
! ! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
7206 |
|
283 | 7207 |
!Image methodsFor:'enumerating'! |
7208 |
||
7209 |
atY:y from:x1 to:x2 do:aBlock |
|
7210 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
7211 |
The block is passed the color at each pixel. |
|
7212 |
The code here provides a generic and slow implementation, and |
|
7213 |
should be redefined in concrete subclasses, to avoid some processing |
|
7214 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
7215 |
and also the color allocation)." |
|
7216 |
||
798 | 7217 |
self obsoleteMethodWarning:'use #colorsAtY:from:to:do:'. |
7218 |
self colorsAtY:y from:x1 to:x2 do:aBlock |
|
7219 |
||
7220 |
"Modified: 7.6.1996 / 19:13:30 / cg" |
|
7221 |
! |
|
7222 |
||
7223 |
colorsAtY:y from:x1 to:x2 do:aBlock |
|
7224 |
"perform aBlock for each pixel from x1 to x2 in row y. |
|
7225 |
The block is passed the color at each pixel. |
|
7226 |
The code here provides a generic and slow implementation, and |
|
7227 |
should be redefined in concrete subclasses, to avoid some processing |
|
7228 |
when going from pixel to pixel (i.e. the byte-index and mask computations |
|
7229 |
and also the color allocation)." |
|
7230 |
||
283 | 7231 |
|xStart "{Class: SmallInteger }" |
7232 |
xEnd "{Class: SmallInteger }"| |
|
7233 |
||
7234 |
xStart := x1. |
|
7235 |
xEnd := x2. |
|
7236 |
xStart to:xEnd do:[:xRun | |
|
798 | 7237 |
aBlock value:xRun value:(self atX:xRun y:y) |
283 | 7238 |
] |
798 | 7239 |
|
7240 |
"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
|
7241 |
"Modified: 10.6.1996 / 10:27:29 / cg" |
283 | 7242 |
! |
7243 |
||
7244 |
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
7245 |
"perform aBlock for each color in a rectangular area of the image. |
|
7246 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
7247 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
7248 |
The code here provides a generic and slow implementation, and |
|
7249 |
should be redefined in concrete subclasses, to avoid some processing |
|
7250 |
when going from pixel to pixel (i.e. the byte-index and mask computations, |
|
7251 |
and especially, the color allocations)." |
|
7252 |
||
940 | 7253 |
|yS "{Class: SmallInteger }" |
942 | 7254 |
yE "{Class: SmallInteger }" |
7255 |
yR| |
|
7256 |
||
7257 |
yS := yStart. |
|
7258 |
yE := yEnd. |
|
940 | 7259 |
|
7260 |
yS to:yE do:[:yRun | |
|
942 | 7261 |
yR := yRun. |
798 | 7262 |
self colorsAtY:yRun from:xStart to:xEnd do:[:xRun :color | |
942 | 7263 |
aBlock value:xRun value:yR value:color |
798 | 7264 |
] |
283 | 7265 |
] |
798 | 7266 |
|
940 | 7267 |
"Modified: 11.7.1996 / 19:50:47 / cg" |
283 | 7268 |
! |
7269 |
||
7270 |
valueAtY:y from:x1 to:x2 do:aBlock |
|
7271 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
798 | 7272 |
Obsolete - remains for backward compatibility." |
7273 |
||
7274 |
self obsoleteMethodWarning:'use #valuesAtY:from:to:do:'. |
|
7275 |
self valuesAtY:y from:x1 to:x2 do:aBlock |
|
7276 |
||
7277 |
"Modified: 7.6.1996 / 19:11:06 / cg" |
|
7278 |
! |
|
7279 |
||
7280 |
valuesAtY:y from:x1 to:x2 do:aBlock |
|
7281 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
|
283 | 7282 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
7283 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
7284 |
(see also Image>>atY:from:to:do:). |
|
7285 |
The code here provides a generic and slow implementation, and |
|
7286 |
should be redefined in concrete subclasses, to avoid some processing |
|
7287 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
7288 |
||
7289 |
|xStart "{Class: SmallInteger }" |
|
7290 |
xEnd "{Class: SmallInteger }"| |
|
7291 |
||
7292 |
xStart := x1. |
|
7293 |
xEnd := x2. |
|
7294 |
xStart to:xEnd do:[:xRun | |
|
692 | 7295 |
aBlock value:xRun value:(self valueAtX:xRun y:y) |
283 | 7296 |
] |
692 | 7297 |
|
7298 |
"Modified: 17.5.1996 / 12:03:59 / cg" |
|
798 | 7299 |
"Created: 7.6.1996 / 19:09:51 / cg" |
283 | 7300 |
! |
7301 |
||
7302 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
7303 |
"perform aBlock for each pixelValue in a rectangular area of the image. |
|
7304 |
Notice, that x and y coordinates start at 0@0 for the upper left corner. |
|
7305 |
The block is passed the x and y coordinates and pixelValue at each pixel. |
|
7306 |
The code here provides a generic and slow implementation, and |
|
7307 |
should be redefined in concrete subclasses, to avoid some processing |
|
7308 |
when going from pixel to pixel (i.e. the byte-index and mask computations)." |
|
7309 |
||
7310 |
|xS "{Class: SmallInteger }" |
|
7311 |
xE "{Class: SmallInteger }"| |
|
7312 |
||
7313 |
xS := xStart. |
|
7314 |
xE := xEnd. |
|
7315 |
yStart to:yEnd do:[:yRun | |
|
798 | 7316 |
self valuesAtY:yRun from:xStart to:xEnd do:[:xRun :pixel | |
7317 |
aBlock value:xRun value:yRun value:pixel |
|
7318 |
] |
|
283 | 7319 |
] |
798 | 7320 |
|
7321 |
"Modified: 7.6.1996 / 19:09:29 / cg" |
|
0 | 7322 |
! ! |
7323 |
||
7324 |
!Image methodsFor:'image manipulations'! |
|
7325 |
||
1570 | 7326 |
applyPixelValuesTo:pixelFunctionBlock into:newImage |
7327 |
"helper for withPixelFunctionAppliedToValues: |
|
7328 |
enumerate pixelValues and evaluate the block for each. |
|
7329 |
To be redefined by subclasses for better performance." |
|
7330 |
||
7331 |
|w "{Class: SmallInteger }" |
|
7332 |
h "{Class: SmallInteger }"| |
|
7333 |
||
7334 |
w := width - 1. |
|
7335 |
h := height - 1. |
|
7336 |
||
7337 |
0 to:h do:[:y | |
|
7338 |
0 to:w do:[:x | |
|
7339 |
newImage atX:x y:y putValue:(pixelFunctionBlock |
|
7340 |
value:self |
|
7341 |
value:(self valueAtX:x y:y) |
|
7342 |
value:x |
|
7343 |
value:y) |
|
7344 |
] |
|
7345 |
]. |
|
7346 |
||
7347 |
"Created: 10.4.1997 / 16:26:17 / cg" |
|
7348 |
"Modified: 10.4.1997 / 16:30:28 / cg" |
|
7349 |
! |
|
7350 |
||
283 | 7351 |
colorMapProcessing:aBlock |
7352 |
"a helper for all kinds of colormap manipulations. |
|
592 | 7353 |
The argument, aBlock is called for every colormap entry, |
7354 |
and the returned value will replace the original entry in the map. |
|
283 | 7355 |
This will fail for non-palette images. |
592 | 7356 |
See examples in Image>>copyWithColorMapProcessing:" |
283 | 7357 |
|
7358 |
|nColors "{ Class: SmallInteger }"| |
|
7359 |
||
7360 |
colorMap isNil ifTrue:[ |
|
592 | 7361 |
^ self error:'image has no colormap' |
283 | 7362 |
]. |
7363 |
||
7364 |
nColors := colorMap size. |
|
7365 |
1 to:nColors do:[:index | |
|
592 | 7366 |
|clr| |
7367 |
||
7368 |
clr := colorMap at:index. |
|
7369 |
clr notNil ifTrue:[ |
|
7370 |
colorMap at:index put:(aBlock value:clr) |
|
7371 |
] |
|
283 | 7372 |
] |
592 | 7373 |
|
7374 |
"Modified: 23.4.1996 / 11:13:55 / cg" |
|
283 | 7375 |
! |
7376 |
||
89 | 7377 |
copyWithColorMapProcessing:aBlock |
81 | 7378 |
"a helper to create & return new images based on the receiver with |
89 | 7379 |
some colorMap processing. The receiver is copied, and the copied images |
7380 |
colormap is modified by replacing entries with the result of the processing block, |
|
7381 |
which is called with the original color values. The block is supposed to return |
|
7382 |
a color." |
|
81 | 7383 |
|
7384 |
|newImage| |
|
7385 |
||
7386 |
newImage := self copy. |
|
7387 |
newImage colorMap isNil ifTrue:[ |
|
7388 |
self error:'no colormap in image'. |
|
7389 |
^ nil |
|
7390 |
]. |
|
7391 |
||
7392 |
" |
|
7393 |
the code below manipulates the colormap. |
|
7394 |
For non-palette images, special code is required |
|
7395 |
" |
|
89 | 7396 |
newImage colorMapProcessing:aBlock. |
81 | 7397 |
^ newImage |
7398 |
||
7399 |
" |
|
7400 |
leave red component only: |
|
7401 |
||
7402 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 7403 |
copyWithColorMapProcessing:[:clr | Color red:(clr red) green:0 blue:0] |
81 | 7404 |
" |
89 | 7405 |
|
81 | 7406 |
" |
7407 |
make it reddish: |
|
7408 |
||
7409 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 7410 |
copyWithColorMapProcessing:[:clr | Color red:((clr red * 2) min:100) green:clr green blue:clr blue] |
81 | 7411 |
" |
89 | 7412 |
|
81 | 7413 |
" |
7414 |
invert: |
|
7415 |
||
7416 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 7417 |
copyWithColorMapProcessing:[:clr | Color red:(100 - clr red) green:(100 - clr green) blue:(100 - clr green)] |
81 | 7418 |
" |
89 | 7419 |
|
81 | 7420 |
" |
7421 |
lighter: |
|
7422 |
||
7423 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 7424 |
copyWithColorMapProcessing:[:clr | |r g b| |
7425 |
r := clr red. g := clr green. b := clr blue. |
|
7426 |
Color red:(r + (100-r//2)) |
|
7427 |
green:(g + (100-g//2)) |
|
7428 |
blue:(b + (100-b//2))] |
|
81 | 7429 |
" |
89 | 7430 |
|
81 | 7431 |
" |
7432 |
darker: |
|
7433 |
||
7434 |
(Image fromFile:'bitmaps/claus.gif') |
|
89 | 7435 |
copyWithColorMapProcessing:[:clr | Color red:(clr red//2) green:(clr green // 2) blue:(clr blue // 2)] |
81 | 7436 |
" |
7437 |
! |
|
7438 |
||
283 | 7439 |
darkened |
7440 |
"return a new image which is slightly darker than the receiver. |
|
7441 |
The receiver must be a palette image (currently). |
|
592 | 7442 |
CAVEAT: Need an argument, which specifies by how much it should be darker." |
283 | 7443 |
|
7444 |
^ self |
|
1349 | 7445 |
copyWithColorMapProcessing:[:clr | clr darkened] |
283 | 7446 |
|
7447 |
" |
|
7448 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
7449 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
7450 |
" |
|
592 | 7451 |
|
7452 |
"Modified: 23.4.1996 / 11:14:34 / cg" |
|
283 | 7453 |
! |
7454 |
||
7455 |
flipHorizontal |
|
7456 |
"inplace horizontal flip" |
|
7457 |
||
7458 |
|w "{Class: SmallInteger }" |
|
7459 |
h "{Class: SmallInteger }" |
|
7460 |
c2 "{Class: SmallInteger }" |
|
7461 |
value | |
|
7462 |
||
7463 |
w := width - 1. |
|
7464 |
h := height - 1. |
|
7465 |
||
7466 |
0 to:h do:[:row | |
|
1386 | 7467 |
c2 := w. |
7468 |
0 to:(w // 2) do:[:col | |
|
7469 |
value := self valueAtX:col y:row. |
|
7470 |
self atX:col y:row putValue:(self valueAtX:c2 y:row). |
|
7471 |
self atX:c2 y:row putValue:value. |
|
7472 |
c2 := c2 - 1. |
|
7473 |
] |
|
7474 |
]. |
|
7475 |
mask notNil ifTrue:[ |
|
7476 |
mask flipHorizontal |
|
81 | 7477 |
]. |
283 | 7478 |
"flush device info" |
7479 |
self restored |
|
1386 | 7480 |
|
7481 |
"Modified: 27.2.1997 / 13:08:21 / cg" |
|
283 | 7482 |
! |
7483 |
||
7484 |
flipVertical |
|
7485 |
"inplace vertical flip" |
|
7486 |
||
7487 |
|h "{Class: SmallInteger }" |
|
7488 |
bytesPerRow "{Class: SmallInteger }" |
|
7489 |
buffer |
|
7490 |
indexLow "{Class: SmallInteger }" |
|
7491 |
indexHi "{Class: SmallInteger }"| |
|
7492 |
||
7493 |
bytesPerRow := self bytesPerRow. |
|
7494 |
buffer := ByteArray new:bytesPerRow. |
|
7495 |
||
7496 |
h := height - 1. |
|
7497 |
||
7498 |
indexLow := 1. |
|
7499 |
indexHi := bytesPerRow * h + 1. |
|
7500 |
||
7501 |
0 to:(h // 2) do:[:row | |
|
1386 | 7502 |
buffer replaceFrom:1 to:bytesPerRow with:bytes startingAt:indexLow. |
7503 |
bytes replaceFrom:indexLow to:(indexLow + bytesPerRow - 1) with:bytes startingAt:indexHi. |
|
7504 |
bytes replaceFrom:indexHi to:(indexHi + bytesPerRow - 1) with:buffer startingAt:1. |
|
7505 |
indexLow := indexLow + bytesPerRow. |
|
7506 |
indexHi := indexHi - bytesPerRow. |
|
7507 |
]. |
|
7508 |
mask notNil ifTrue:[ |
|
7509 |
mask flipVertical |
|
283 | 7510 |
]. |
7511 |
"flush device info" |
|
7512 |
self restored |
|
1386 | 7513 |
|
7514 |
"Modified: 27.2.1997 / 13:04:10 / cg" |
|
283 | 7515 |
! |
7516 |
||
7517 |
hardMagnifiedBy:scalePoint |
|
7518 |
"return a new image magnified by scalePoint, aPoint. |
|
7519 |
This is the general magnification method, handling non-integral values. |
|
7520 |
It is slower than the integral magnification method." |
|
7521 |
||
7522 |
|mX |
|
7523 |
mY |
|
7524 |
newWidth "{ Class: SmallInteger }" |
|
7525 |
newHeight "{ Class: SmallInteger }" |
|
7526 |
w "{ Class: SmallInteger }" |
|
7527 |
h "{ Class: SmallInteger }" |
|
906 | 7528 |
newImage newBits bitsPerPixel newBytesPerRow newMask |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7529 |
value |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7530 |
srcRow| |
283 | 7531 |
|
7532 |
mX := scalePoint x. |
|
7533 |
mY := scalePoint y. |
|
7534 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
7535 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
7536 |
||
7537 |
newWidth := (width * mX) truncated. |
|
7538 |
newHeight := (height * mY) truncated. |
|
7539 |
||
7540 |
bitsPerPixel := self depth. |
|
7541 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
7542 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
7543 |
||
906 | 7544 |
mask notNil ifTrue:[ |
7545 |
newMask := (mask magnifiedBy:scalePoint) |
|
7546 |
]. |
|
7547 |
||
283 | 7548 |
newImage := self species new. |
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7549 |
newImage |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7550 |
width:newWidth |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7551 |
height:newHeight |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7552 |
photometric:photometric |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7553 |
samplesPerPixel:samplesPerPixel |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7554 |
bitsPerSample:bitsPerSample |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7555 |
colorMap:colorMap copy |
906 | 7556 |
bits:newBits |
7557 |
mask:newMask. |
|
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7558 |
|
283 | 7559 |
"walk over destination image fetching pixels from source image" |
7560 |
||
7561 |
w := newWidth - 1. |
|
7562 |
h := newHeight - 1. |
|
7563 |
||
7564 |
0 to:h do:[:row | |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7565 |
srcRow := (row // mY). |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7566 |
0 to:w do:[:col | |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7567 |
value := self valueAtX:(col // mX) y:srcRow. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7568 |
newImage atX:col y:row putValue:value. |
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7569 |
] |
283 | 7570 |
]. |
7571 |
||
7572 |
^ newImage |
|
7573 |
||
7574 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
|
888
69447418e2b1
better algorithm when dithering palette images
Claus Gittinger <cg@exept.de>
parents:
884
diff
changeset
|
7575 |
|
906 | 7576 |
"Modified: 27.6.1996 / 17:46:05 / cg" |
283 | 7577 |
! |
7578 |
||
7579 |
hardRotated:degrees |
|
592 | 7580 |
"raise an error - rotation by arbitrary angles is not yet implemented" |
7581 |
||
283 | 7582 |
self error:'not yet implemented' |
592 | 7583 |
|
7584 |
"Modified: 23.4.1996 / 11:15:33 / cg" |
|
81 | 7585 |
! |
7586 |
||
54 | 7587 |
lightened |
89 | 7588 |
"return a new image which is slightly brighter than the receiver. |
7589 |
The receiver must be a palette image (currently). |
|
592 | 7590 |
CAVEAT: Need an argument, which specifies by how much it should be lighter." |
54 | 7591 |
|
81 | 7592 |
^ self |
1349 | 7593 |
copyWithColorMapProcessing:[:clr | clr lightened] |
81 | 7594 |
|
7595 |
" |
|
7596 |
(Image fromFile:'bitmaps/claus.gif') inspect |
|
7597 |
(Image fromFile:'bitmaps/claus.gif') lightened inspect |
|
7598 |
(Image fromFile:'bitmaps/claus.gif') darkened inspect |
|
7599 |
(Image fromFile:'bitmaps/claus.gif') darkened darkened inspect |
|
7600 |
" |
|
592 | 7601 |
|
7602 |
"Modified: 23.4.1996 / 11:14:41 / cg" |
|
54 | 7603 |
! |
7604 |
||
134 | 7605 |
magnifiedBy:scale |
81 | 7606 |
"return a new image magnified by scalePoint, aPoint. |
72 | 7607 |
If non-integral magnify is asked for, pass the work on to 'hardMagnifyBy:' |
7608 |
while simple (integral) magnifications are handled here." |
|
0 | 7609 |
|
81 | 7610 |
|scalePoint mX mY |
46 | 7611 |
magX "{ Class: SmallInteger }" "new version of stc can find this out itself..." |
7612 |
magY "{ Class: SmallInteger }" |
|
7613 |
srcOffset "{ Class: SmallInteger }" |
|
7614 |
dstOffset "{ Class: SmallInteger }" |
|
7615 |
w "{ Class: SmallInteger }" |
|
7616 |
h "{ Class: SmallInteger }" |
|
7617 |
first |
|
906 | 7618 |
newWidth newHeight newImage newBits newMask |
81 | 7619 |
bitsPerPixel newBytesPerRow oldBytesPerRow| |
0 | 7620 |
|
81 | 7621 |
scalePoint := scale asPoint. |
7622 |
mX := scalePoint asPoint x. |
|
7623 |
mY := scalePoint asPoint y. |
|
46 | 7624 |
((mX <= 0) or:[mY <= 0]) ifTrue:[^ nil]. |
0 | 7625 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
7626 |
||
12 | 7627 |
((mX isMemberOf:SmallInteger) and:[mY isMemberOf:SmallInteger]) ifFalse:[ |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7628 |
^ self hardMagnifiedBy:scalePoint |
0 | 7629 |
]. |
7630 |
||
2 | 7631 |
bitsPerPixel := self depth. |
0 | 7632 |
oldBytesPerRow := ((width * bitsPerPixel) + 7) // 8. |
7633 |
||
46 | 7634 |
w := width. |
7635 |
h := height. |
|
7636 |
magX := mX. |
|
7637 |
magY := mY. |
|
7638 |
||
7639 |
newWidth := w * mX. |
|
7640 |
newHeight := h * mY. |
|
0 | 7641 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
7642 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * newHeight). |
|
7643 |
||
906 | 7644 |
mask notNil ifTrue:[ |
7645 |
newMask := (mask magnifiedBy:scalePoint) |
|
7646 |
]. |
|
7647 |
||
0 | 7648 |
newImage := self species new. |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7649 |
newImage |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7650 |
width:newWidth |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7651 |
height:newHeight |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7652 |
photometric:photometric |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7653 |
samplesPerPixel:samplesPerPixel |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7654 |
bitsPerSample:bitsPerSample |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7655 |
colorMap:colorMap copy |
906 | 7656 |
bits:newBits |
7657 |
mask:newMask. |
|
0 | 7658 |
|
7659 |
mX = 1 ifTrue:[ |
|
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7660 |
"expand rows only" |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7661 |
srcOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7662 |
dstOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7663 |
|
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7664 |
1 to:h do:[:row | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7665 |
1 to:mY do:[:i | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7666 |
newBits replaceFrom:dstOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7667 |
to:(dstOffset + oldBytesPerRow - 1) |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7668 |
with:bytes |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7669 |
startingAt:srcOffset. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7670 |
dstOffset := dstOffset + newBytesPerRow |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7671 |
]. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7672 |
srcOffset := srcOffset + oldBytesPerRow. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7673 |
]. |
0 | 7674 |
] ifFalse:[ |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7675 |
"expand cols" |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7676 |
(mX > 1) ifTrue:[ |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7677 |
dstOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7678 |
srcOffset := 1. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7679 |
1 to:h do:[:row | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7680 |
self magnifyRowFrom:bytes |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7681 |
offset:srcOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7682 |
into:newBits |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7683 |
offset:dstOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7684 |
factor:mX. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7685 |
|
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7686 |
first := dstOffset. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7687 |
dstOffset := dstOffset + newBytesPerRow. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7688 |
" and copy for row expansion " |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7689 |
2 to:mY do:[:i | |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7690 |
newBits replaceFrom:dstOffset |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7691 |
to:(dstOffset + newBytesPerRow - 1) |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7692 |
with:newBits |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7693 |
startingAt:first. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7694 |
dstOffset := dstOffset + newBytesPerRow |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7695 |
]. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7696 |
srcOffset := srcOffset + oldBytesPerRow. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7697 |
]. |
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7698 |
] |
0 | 7699 |
]. |
7700 |
^ newImage |
|
7701 |
||
134 | 7702 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:1@2)" |
905
228d503775d9
everywhere you go: always magnify the mask with you ...
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
7703 |
|
906 | 7704 |
"Modified: 27.6.1996 / 17:46:28 / cg" |
2 | 7705 |
! |
7706 |
||
154 | 7707 |
magnifiedPreservingRatioTo:anExtent |
7708 |
"return a new image magnified to fit into anExtent, |
|
7709 |
preserving the receivers width/height ratio. |
|
7710 |
(i.e. not distorting the image). |
|
7711 |
See also #magnifiedTo: and #magnifiedBy:" |
|
7712 |
||
7713 |
|rX rY| |
|
7714 |
||
7715 |
rX := anExtent x / self width. |
|
7716 |
rY := anExtent y / self height. |
|
7717 |
^ self magnifiedBy:(rX min:rY) |
|
7718 |
||
7719 |
" |
|
7720 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
7721 |
||
7722 |
in contrast to: |
|
7723 |
||
7724 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
|
7725 |
" |
|
7726 |
! |
|
7727 |
||
134 | 7728 |
magnifiedTo:anExtent |
154 | 7729 |
"return a new image magnified to have the size specified by extent. |
7730 |
This may distort the image if the arguments ratio is not the images ratio. |
|
7731 |
See also #magnifiedPreservingRatioTo: and #magnifiedBy:" |
|
89 | 7732 |
|
134 | 7733 |
^ self magnifiedBy:(anExtent / self extent) |
89 | 7734 |
|
7735 |
" |
|
134 | 7736 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedTo:100@100) |
154 | 7737 |
|
7738 |
in contrast to: |
|
7739 |
||
7740 |
((Image fromFile:'bitmaps/garfield.gif') magnifiedPreservingRatioTo:100@100) |
|
89 | 7741 |
" |
7742 |
! |
|
7743 |
||
12 | 7744 |
rotated:degrees |
7745 |
"return a new image from the old one, by rotating the image |
|
46 | 7746 |
degrees clockwise. |
592 | 7747 |
CAVEAT: Currently, only rotation by a multiple of 90 degrees is implemented." |
12 | 7748 |
|
46 | 7749 |
|w "{Class: SmallInteger }" |
7750 |
h "{Class: SmallInteger }" |
|
12 | 7751 |
c2 "{Class: SmallInteger }" |
692 | 7752 |
r2 "{Class: SmallInteger }" |
7753 |
nW "{Class: SmallInteger }" |
|
7754 |
nH "{Class: SmallInteger }" |
|
24 | 7755 |
newImage newBits newBytesPerRow d| |
12 | 7756 |
|
7757 |
d := degrees. |
|
7758 |
[d < 0] whileTrue:[d := d + 360]. |
|
7759 |
d >= 360 ifTrue:[d := d \\ 360]. |
|
46 | 7760 |
d := d truncated. |
7761 |
d == 0 ifTrue:[^ self]. |
|
7762 |
((d ~~ 90) and:[(d ~~ 270) and:[d ~~ 180]]) ifTrue:[ |
|
592 | 7763 |
^ self hardRotated:d |
12 | 7764 |
]. |
7765 |
||
692 | 7766 |
d == 180 ifTrue:[ |
7767 |
nW := width. |
|
7768 |
nH := height. |
|
7769 |
] ifFalse:[ |
|
7770 |
nW := height. |
|
7771 |
nH := width. |
|
7772 |
]. |
|
7773 |
||
7774 |
newBytesPerRow := ((nW * self depth) + 7) // 8. |
|
7775 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * nH). |
|
12 | 7776 |
|
7777 |
newImage := self species new. |
|
7778 |
newImage bits:newBits. |
|
692 | 7779 |
newImage width:nW. |
7780 |
newImage height:nH. |
|
12 | 7781 |
newImage photometric:photometric. |
7782 |
newImage samplesPerPixel:samplesPerPixel. |
|
7783 |
newImage bitsPerSample:bitsPerSample. |
|
7784 |
newImage colorMap:colorMap copy. |
|
7785 |
||
7786 |
w := width - 1. |
|
7787 |
h := height - 1. |
|
7788 |
||
7789 |
d == 90 ifTrue:[ |
|
592 | 7790 |
0 to:h do:[:row | |
7791 |
c2 := h-row. |
|
798 | 7792 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 7793 |
newImage atX:c2 y:col putValue:pixel. |
592 | 7794 |
] |
692 | 7795 |
"/ 0 to:w do:[:col | |
7796 |
"/ newImage atX:c2 y:col putValue:(self valueAtX:col y:row). |
|
7797 |
"/ ] |
|
592 | 7798 |
] |
12 | 7799 |
]. |
46 | 7800 |
d == 180 ifTrue:[ |
592 | 7801 |
0 to:h do:[:row | |
692 | 7802 |
r2 := h - row. |
798 | 7803 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 7804 |
newImage atX:(w-col) y:r2 putValue:pixel. |
592 | 7805 |
] |
692 | 7806 |
"/ 0 to:w do:[:col | |
7807 |
"/ newImage atX:(w-col) y:r2 putValue:(self valueAtX:col y:row). |
|
7808 |
"/ ] |
|
592 | 7809 |
] |
46 | 7810 |
]. |
12 | 7811 |
d == 270 ifTrue:[ |
592 | 7812 |
0 to:h do:[:row | |
798 | 7813 |
self valuesAtY:row from:0 to:w do:[:col :pixel | |
692 | 7814 |
newImage atX:row y:(w-col) putValue:pixel. |
592 | 7815 |
] |
692 | 7816 |
"/ 0 to:w do:[:col | |
7817 |
"/ newImage atX:row y:(w-col) putValue:(self valueAtX:col y:row). |
|
7818 |
"/ ] |
|
592 | 7819 |
] |
12 | 7820 |
]. |
7821 |
^ newImage |
|
592 | 7822 |
|
692 | 7823 |
" |
7824 |
|i| |
|
7825 |
||
7826 |
i := Image fromFile:'claus.gif'. |
|
7827 |
i inspect. |
|
7828 |
(i rotated:90) inspect. |
|
7829 |
(i rotated:180) inspect. |
|
7830 |
(i rotated:270) inspect. |
|
7831 |
" |
|
7832 |
||
798 | 7833 |
"Modified: 7.6.1996 / 19:09:22 / cg" |
692 | 7834 |
! |
7835 |
||
7836 |
withPixelFunctionApplied:pixelFunctionBlock |
|
7837 |
"return a new image from the old one, by applying a pixel processor |
|
1509 | 7838 |
on the pixel colors. |
692 | 7839 |
(read `Behond photography, by Gerard J. Holzmann; |
7840 |
ISBM 0-13-074410-7) |
|
7841 |
See blurred / oilPointed as examples ...)" |
|
7842 |
||
7843 |
|w "{Class: SmallInteger }" |
|
7844 |
h "{Class: SmallInteger }" |
|
1063 | 7845 |
newImage newBits newBytesPerRow| |
692 | 7846 |
|
7847 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
7848 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
7849 |
||
7850 |
newImage := self species new. |
|
7851 |
newImage bits:newBits. |
|
7852 |
newImage width:width. |
|
7853 |
newImage height:height. |
|
7854 |
newImage photometric:photometric. |
|
7855 |
newImage samplesPerPixel:samplesPerPixel. |
|
7856 |
newImage bitsPerSample:bitsPerSample. |
|
7857 |
newImage colorMap:colorMap copy. |
|
7858 |
||
7859 |
w := width - 1. |
|
7860 |
h := height - 1. |
|
7861 |
||
7862 |
0 to:h do:[:y | |
|
7863 |
0 to:w do:[:x | |
|
7864 |
newImage atX:x y:y put:(pixelFunctionBlock |
|
7865 |
value:self |
|
1570 | 7866 |
value:(self atX:x y:y) |
692 | 7867 |
value:x |
7868 |
value:y) |
|
7869 |
] |
|
7870 |
]. |
|
7871 |
^ newImage |
|
7872 |
||
7873 |
" |
|
1570 | 7874 |
|i black| |
692 | 7875 |
|
1509 | 7876 |
i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
692 | 7877 |
i inspect. |
1570 | 7878 |
|
7879 |
black := Color black. |
|
7880 |
(i withPixelFunctionApplied:[:oldImage :oldColor :x :y | |
|
692 | 7881 |
((x between:100 and:200) |
7882 |
and:[y between:100 and:200]) ifTrue:[ |
|
1570 | 7883 |
oldColor |
692 | 7884 |
] ifFalse:[ |
1570 | 7885 |
black. |
692 | 7886 |
] |
7887 |
]) inspect. |
|
7888 |
" |
|
7889 |
||
1570 | 7890 |
"Modified: 10.4.1997 / 16:35:10 / cg" |
1509 | 7891 |
! |
7892 |
||
7893 |
withPixelFunctionAppliedToValues:pixelFunctionBlock |
|
7894 |
"return a new image from the old one, by applying a pixel processor |
|
7895 |
on the pixel values. |
|
7896 |
(read `Behond photography, by Gerard J. Holzmann; |
|
7897 |
ISBM 0-13-074410-7) |
|
7898 |
See blurred / oilPointed as examples ...)" |
|
7899 |
||
1570 | 7900 |
|newImage newBits newBytesPerRow| |
1509 | 7901 |
|
7902 |
newBytesPerRow := ((width * self depth) + 7) // 8. |
|
7903 |
newBits := ByteArray uninitializedNew:(newBytesPerRow * height). |
|
7904 |
||
7905 |
newImage := self species new. |
|
7906 |
newImage bits:newBits. |
|
7907 |
newImage width:width. |
|
7908 |
newImage height:height. |
|
7909 |
newImage photometric:photometric. |
|
7910 |
newImage samplesPerPixel:samplesPerPixel. |
|
7911 |
newImage bitsPerSample:bitsPerSample. |
|
7912 |
newImage colorMap:colorMap copy. |
|
7913 |
||
1570 | 7914 |
self applyPixelValuesTo:pixelFunctionBlock into:newImage. |
1509 | 7915 |
^ newImage |
7916 |
||
7917 |
"oil painting effect: |
|
7918 |
||
7919 |
|i w h| |
|
7920 |
||
7921 |
i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
|
7922 |
i inspect. |
|
7923 |
w := i width - 1. |
|
7924 |
h := i height - 1. |
|
1570 | 7925 |
(i withPixelFunctionAppliedToValues:[:oldImage :oldPixel :x :y | |
7926 |
|b p max xMin xMax yMin yMax| |
|
7927 |
||
7928 |
b := Bag identityNew:10. |
|
7929 |
xMin := x-3 max:0. |
|
7930 |
xMax := x+3 min:w. |
|
7931 |
yMin := y-3 max:0. |
|
7932 |
yMax := y+3 min:h. |
|
7933 |
xMin to:xMax do:[:tx| |
|
7934 |
yMin to:yMax do:[:ty| |
|
1509 | 7935 |
b add:(oldImage valueAtX:tx y:ty) |
7936 |
] |
|
7937 |
]. |
|
7938 |
max := 0. |
|
7939 |
b contents keysAndValuesDo:[:pixel :n | |
|
7940 |
n > max ifTrue:[ |
|
7941 |
p := pixel. |
|
7942 |
max := n |
|
7943 |
] |
|
7944 |
]. |
|
7945 |
p |
|
7946 |
]) inspect. |
|
7947 |
" |
|
7948 |
||
7949 |
"fisheye effect: |
|
7950 |
||
1570 | 7951 |
|i w h w2 h2 R white| |
1509 | 7952 |
|
7953 |
i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
|
7954 |
i inspect. |
|
7955 |
w := i width - 1. |
|
7956 |
h := i height - 1. |
|
7957 |
w2 := w // 2. |
|
7958 |
h2 := h // 2. |
|
1510 | 7959 |
R := w2. |
1570 | 7960 |
white := i valueFromColor:Color white. |
7961 |
(i withPixelFunctionAppliedToValues:[:oldImage :oldPixel :x :y | |
|
1509 | 7962 |
|p r a nR nP nX nY| |
7963 |
||
7964 |
p := (x-w2)@(y-h2). |
|
7965 |
r := p r. |
|
7966 |
a := p theta. |
|
7967 |
nR := r * r / R. |
|
7968 |
nP := Point r:nR theta:a. |
|
7969 |
nX := ((nP x+w2) rounded max:0) min:w. |
|
7970 |
nY := ((nP y+h2) rounded max:0) min:h. |
|
1570 | 7971 |
(nX > w or:[nX < 0]) ifTrue:[ |
7972 |
white |
|
7973 |
] ifFalse:[ |
|
7974 |
(nY > h or:[nY < 0]) ifTrue:[ |
|
7975 |
white |
|
7976 |
] ifFalse:[ |
|
7977 |
oldImage valueAtX:nX y:nY |
|
7978 |
] |
|
7979 |
] |
|
1509 | 7980 |
]) inspect. |
7981 |
" |
|
1510 | 7982 |
"fisheye effect: |
7983 |
||
7984 |
|i w h w2 h2 R white| |
|
7985 |
||
7986 |
i := Image fromFile:'bitmaps/gifImages/claus.gif'. |
|
7987 |
i inspect. |
|
7988 |
w := i width - 1. |
|
7989 |
h := i height - 1. |
|
7990 |
w2 := w // 2. |
|
7991 |
h2 := h // 2. |
|
7992 |
R := w2. |
|
7993 |
white := i valueFromColor:Color white. |
|
1570 | 7994 |
(i withPixelFunctionAppliedToValues:[:oldImage :oldPixel :x :y | |
1510 | 7995 |
|p r a nR nP nX nY| |
7996 |
||
7997 |
p := (x-w2)@(y-h2). |
|
7998 |
r := p r. |
|
7999 |
a := p theta. |
|
8000 |
nR := r * r / R. |
|
8001 |
nP := Point r:nR theta:a. |
|
8002 |
nX := (nP x+w2) rounded. |
|
8003 |
nY := (nP y+h2) rounded. |
|
8004 |
(nX > w or:[nX < 0]) ifTrue:[ |
|
8005 |
white |
|
8006 |
] ifFalse:[ |
|
8007 |
(nY > h or:[nY < 0]) ifTrue:[ |
|
8008 |
white |
|
8009 |
] ifFalse:[ |
|
8010 |
oldImage valueAtX:nX y:nY |
|
8011 |
] |
|
8012 |
] |
|
8013 |
]) inspect. |
|
8014 |
" |
|
1509 | 8015 |
|
8016 |
"Created: 1.4.1997 / 23:22:11 / cg" |
|
1570 | 8017 |
"Modified: 10.4.1997 / 16:42:05 / cg" |
283 | 8018 |
! ! |
8019 |
||
8020 |
!Image methodsFor:'inspecting'! |
|
8021 |
||
8022 |
inspectorClass |
|
8023 |
"redefined to launch an ImageInspector |
|
8024 |
(instead of the default InspectorView)." |
|
8025 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8026 |
(width notNil and:[height notNil]) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8027 |
^ ImageInspectorView |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8028 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8029 |
^ super inspectorClass |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8030 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8031 |
"Modified: 10.6.1996 / 18:23:55 / cg" |
283 | 8032 |
! ! |
8033 |
||
8034 |
!Image methodsFor:'instance release'! |
|
8035 |
||
8036 |
disposed |
|
8037 |
"some Image has been collected - nothing to do" |
|
12 | 8038 |
! |
8039 |
||
1230
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8040 |
quickRelease |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8041 |
"release device resources" |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8042 |
|
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8043 |
device := nil. |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8044 |
deviceForm := nil. |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8045 |
monoDeviceForm := nil. |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8046 |
fullColorDeviceForm := nil. |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8047 |
|
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8048 |
"Modified: 16.1.1997 / 19:33:01 / cg" |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8049 |
! |
279016623d5a
resource release on display shutDown
Claus Gittinger <cg@exept.de>
parents:
1175
diff
changeset
|
8050 |
|
283 | 8051 |
release |
8052 |
"release device resources" |
|
8053 |
||
8054 |
device := nil. |
|
8055 |
deviceForm := nil. |
|
8056 |
monoDeviceForm := nil. |
|
8057 |
fullColorDeviceForm := nil. |
|
901 | 8058 |
mask notNil ifTrue:[ |
8059 |
mask release. |
|
8060 |
]. |
|
8061 |
Lobby unregister:self. |
|
8062 |
||
8063 |
"Modified: 21.6.1996 / 19:08:19 / cg" |
|
46 | 8064 |
! |
8065 |
||
283 | 8066 |
restored |
8067 |
"flush device specifics after a snapin or binary restore" |
|
8068 |
||
8069 |
self release |
|
8070 |
! ! |
|
8071 |
||
592 | 8072 |
!Image methodsFor:'obsolete'! |
8073 |
||
8074 |
magnifyBy:scale |
|
8075 |
"obsolete: has been renamed to magnifiedBy: for ST-80 compatibility |
|
8076 |
and name consistency ..." |
|
8077 |
||
8078 |
self obsoleteMethodWarning. |
|
8079 |
^ self magnifiedBy:scale |
|
8080 |
! ! |
|
8081 |
||
283 | 8082 |
!Image methodsFor:'pixel copying'! |
8083 |
||
8084 |
copyFrom:anImage x:srcX y:srcY toX:dstX y:dstY width:w height:h |
|
1248 | 8085 |
"replace a rectangular area by pixels from another image. |
283 | 8086 |
WARNING: |
1248 | 8087 |
|
8088 |
This implementation is a very slow fallback general algorithm |
|
8089 |
(the loop over the source pixels is very slow). |
|
8090 |
If this method is used heavily, you may want to redefine it in |
|
8091 |
concrete subclasses for the common case of of copying from an Image |
|
8092 |
with the same depth & palette. |
|
8093 |
If you do heavy image processing, specialized versions are even req'd |
|
8094 |
for other cases, rewriting the inner loops as inline C-code." |
|
283 | 8095 |
|
8096 |
|dX dY| |
|
8097 |
||
8098 |
dX := srcX-dstX. |
|
8099 |
dY := srcY-dstY. |
|
1248 | 8100 |
|
283 | 8101 |
((photometric == anImage photometric) |
8102 |
and:[self bitsPerPixel == anImage bitsPerPixel |
|
8103 |
and:[colorMap = anImage colorMap]]) ifTrue:[ |
|
1248 | 8104 |
"/ can loop over values |
8105 |
anImage valuesFromX:srcX y:srcY |
|
8106 |
toX:srcX+w-1 y:srcY+h-1 |
|
8107 |
do:[:x :y :pixelValue | |
|
8108 |
self atX:x-dX y:y-dY putValue:pixelValue. |
|
8109 |
] |
|
283 | 8110 |
] ifFalse:[ |
1248 | 8111 |
"/ must loop over colors - horribly slow |
8112 |
anImage colorsFromX:srcX y:srcY |
|
8113 |
toX:srcX+w-1 y:srcY+h-1 |
|
8114 |
do:[:x :y :clr | |
|
8115 |
self atX:x-dX y:y-dY put:clr. |
|
8116 |
] |
|
283 | 8117 |
] |
8118 |
||
8119 |
" |
|
8120 |
|i1 i8 i4| |
|
8121 |
||
8122 |
i8 := Image fromFile:'bitmaps/garfield.gif'. |
|
8123 |
i8 inspect. |
|
8124 |
i1 := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
8125 |
i1 inspect. |
|
8126 |
||
8127 |
i4 := Depth4Image fromImage:i8. |
|
8128 |
i4 copyFrom:i1 x:0 y:0 toX:20 y:20 width:30 height:30. |
|
8129 |
i4 inspect. |
|
8130 |
" |
|
8131 |
||
8132 |
"Created: 20.9.1995 / 10:14:01 / claus" |
|
8133 |
"Modified: 20.9.1995 / 10:25:31 / claus" |
|
1248 | 8134 |
"Modified: 18.1.1997 / 17:22:45 / cg" |
283 | 8135 |
! |
8136 |
||
8137 |
subImageIn:aRectangle |
|
8138 |
"create and return a new image consisting of a subArea of myself" |
|
8139 |
||
8140 |
^ self class fromSubImage:self in:aRectangle |
|
8141 |
||
8142 |
" |
|
8143 |
|i| |
|
8144 |
||
8145 |
i := Image fromFile:'bitmaps/garfield.gif'. |
|
8146 |
i inspect. |
|
8147 |
(i subImageIn:(300@160 corner:340@200)) inspect |
|
8148 |
" |
|
8149 |
||
8150 |
"Created: 20.9.1995 / 01:24:20 / claus" |
|
8151 |
! ! |
|
8152 |
||
8153 |
!Image methodsFor:'printing & storing'! |
|
8154 |
||
8155 |
storeOn:aStream |
|
592 | 8156 |
"append a printed representation of the receiver to aStream, |
8157 |
from which a copy of it can be reconstructed." |
|
8158 |
||
283 | 8159 |
aStream nextPutAll:'(' , self class name , ' new)'. |
8160 |
aStream nextPutAll:' width: '. width storeOn:aStream. |
|
8161 |
aStream nextPutAll:'; height: '. height storeOn:aStream. |
|
8162 |
aStream nextPutAll:'; photometric:('. photometric storeOn:aStream. |
|
8163 |
aStream nextPutAll:'); bitsPerSample:('. bitsPerSample storeOn:aStream. |
|
8164 |
aStream nextPutAll:'); samplesPerPixel:('. samplesPerPixel storeOn:aStream. |
|
8165 |
aStream nextPutAll:'); bits:('. bytes storeOn:aStream. aStream nextPutAll:') '. |
|
8166 |
colorMap notNil ifTrue:[ |
|
592 | 8167 |
aStream nextPutAll:'; colorMap:('. |
8168 |
colorMap storeOn:aStream. |
|
8169 |
aStream nextPutAll:')'. |
|
283 | 8170 |
]. |
8171 |
aStream nextPutAll:'; yourself' |
|
592 | 8172 |
|
8173 |
"Modified: 23.4.1996 / 11:18:05 / cg" |
|
0 | 8174 |
! ! |
8175 |
||
8176 |
!Image methodsFor:'private'! |
|
8177 |
||
193 | 8178 |
bestSupportedImageFormatFor:aDevice |
8179 |
"scan through the image formats as supported by aDevice, |
|
8180 |
and return the best to use when the receiver is to be represented |
|
8181 |
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
|
8182 |
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
|
8183 |
|
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
8184 |
|bestDeviceDepth bestDeviceBitsPerPixel bestInfo maxInfo myDepth maxDepth maxBitsPerPixel | |
193 | 8185 |
|
8186 |
myDepth := self bitsPerPixel. |
|
8187 |
maxBitsPerPixel := 0. |
|
8188 |
||
8189 |
aDevice supportedImageFormats do:[:entry | |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8190 |
|deviceImageDepth deviceImageBitsPerPixel| |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8191 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8192 |
deviceImageDepth := entry at:#depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8193 |
deviceImageBitsPerPixel := entry at:#bitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8194 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8195 |
deviceImageBitsPerPixel > maxBitsPerPixel ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8196 |
maxInfo := entry. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
8197 |
"/ maxBitsPerPixel := deviceImageBitsPerPixel. |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
8198 |
"/ maxDepth := deviceImageDepth. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8199 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8200 |
|
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8201 |
deviceImageDepth >= myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8202 |
deviceImageDepth == myDepth ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8203 |
"/ take the better one ... |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8204 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8205 |
or:[(bestDeviceBitsPerPixel ~~ bestDeviceDepth) |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8206 |
and:[deviceImageDepth == deviceImageBitsPerPixel]]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8207 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8208 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8209 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8210 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8211 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8212 |
"/ take the next-larger depth |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8213 |
(bestDeviceDepth isNil |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8214 |
or:[deviceImageBitsPerPixel < bestDeviceBitsPerPixel]) ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8215 |
bestInfo := entry. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8216 |
bestDeviceDepth := deviceImageDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8217 |
bestDeviceBitsPerPixel := deviceImageBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8218 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8219 |
] |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8220 |
]. |
193 | 8221 |
]. |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8222 |
|
193 | 8223 |
bestDeviceDepth isNil ifTrue:[ |
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8224 |
maxBitsPerPixel == 0 ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8225 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8226 |
"/ oops - nothing appropriate |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8227 |
"/ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8228 |
maxInfo notNil ifTrue:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8229 |
^ maxInfo |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8230 |
]. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8231 |
bestDeviceDepth := bestDeviceBitsPerPixel := aDevice depth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8232 |
bestInfo := IdentityDictionary new. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8233 |
bestInfo at:#depth put:bestDeviceDepth. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8234 |
bestInfo at:#bitsPerPixel put:bestDeviceBitsPerPixel. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8235 |
bestInfo at:#padding put:32. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8236 |
] ifFalse:[ |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8237 |
bestInfo := maxInfo. |
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8238 |
] |
193 | 8239 |
]. |
235
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
8240 |
^ bestInfo |
579f3f804a46
padding info in supportedFormats
Claus Gittinger <cg@exept.de>
parents:
230
diff
changeset
|
8241 |
|
851
c9511f8945ce
fixed bug in bestSupportedImageFormat (with 15-bit trueColor servers)
Claus Gittinger <cg@exept.de>
parents:
841
diff
changeset
|
8242 |
"Modified: 14.6.1996 / 14:46:40 / cg" |
283 | 8243 |
! |
8244 |
||
8245 |
colormapFromImage:anImage |
|
8246 |
"setup the receivers colormap from another image. |
|
8247 |
Color precision may be lost, if conversion is from a higher depth |
|
8248 |
image. This does not convert any pixel values; it is non-public helper |
|
8249 |
for fromImage:/fromSubImake:" |
|
8250 |
||
8251 |
samplesPerPixel == 3 ifTrue:[ |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8252 |
photometric := #rgb |
283 | 8253 |
] ifFalse:[ |
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8254 |
photometric := anImage photometric. |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8255 |
photometric == #palette ifTrue:[ |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8256 |
colorMap := anImage colorMap copy. |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8257 |
" |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8258 |
must compress the colormap, if source image has higher depth |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8259 |
than myself. |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8260 |
" |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8261 |
anImage bitsPerPixel > self bitsPerPixel ifTrue:[ |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8262 |
" |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8263 |
get used colors are extracted into our colorMap |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8264 |
(the at-put below will set the pixelValue according the |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8265 |
new colorIndex |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8266 |
" |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8267 |
colorMap := anImage usedColors asArray. |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8268 |
colorMap size > (1 bitShift:self bitsPerPixel) ifTrue:[ |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8269 |
'Image [warning]: possibly too many colors in image' errorPrintCR |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8270 |
] |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8271 |
] |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8272 |
] |
283 | 8273 |
]. |
8274 |
||
8275 |
"Created: 20.9.1995 / 00:58:42 / claus" |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8276 |
"Modified: 10.1.1997 / 17:52:21 / cg" |
283 | 8277 |
! |
8278 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8279 |
greyByteMapForRange:range |
798 | 8280 |
"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
|
8281 |
in the range 0..range. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8282 |
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
|
8283 |
The values are rounded towards the nearest pixel." |
798 | 8284 |
|
1403 | 8285 |
|d clr val greyMap r |
8286 |
n "{ Class: SmallInteger }"| |
|
808 | 8287 |
|
8288 |
r := range. |
|
8289 |
r == 256 ifTrue:[ |
|
8290 |
r := 255 |
|
798 | 8291 |
]. |
8292 |
||
8293 |
photometric == #palette ifTrue:[ |
|
808 | 8294 |
n := colorMap size. |
8295 |
greyMap := ByteArray new:n. |
|
8296 |
||
8297 |
1 to:n do:[:i | |
|
1403 | 8298 |
(clr := colorMap at:i) isNil ifTrue:[ |
8299 |
"/ an unused color |
|
8300 |
val := 0. |
|
8301 |
] ifFalse:[ |
|
8302 |
val := (r * clr brightness) rounded |
|
8303 |
]. |
|
8304 |
greyMap at:i put:val |
|
798 | 8305 |
]. |
8306 |
] ifFalse:[ |
|
808 | 8307 |
d := self bitsPerPixel. |
8308 |
n := 1 bitShift:d. |
|
8309 |
n >= 4096 ifTrue:[ |
|
8310 |
self error:'size not supported - too large'. |
|
8311 |
^ nil |
|
8312 |
]. |
|
8313 |
greyMap := ByteArray new:n. |
|
8314 |
||
8315 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8316 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8317 |
1 to:n do:[:i | |
808 | 8318 |
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
|
8319 |
]. |
798 | 8320 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8321 |
1 to:n do:[:i | |
808 | 8322 |
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
|
8323 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8324 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8325 |
"/ we are done |
798 | 8326 |
] ifFalse:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8327 |
photometric == #whiteIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8328 |
greyMap reverse |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8329 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8330 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8331 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8332 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8333 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8334 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8335 |
]. |
808 | 8336 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8337 |
^ greyMap |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8338 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8339 |
" |
808 | 8340 |
Depth8Image new greyByteMapForRange:256 |
8341 |
||
8342 |
Depth8Image new greyByteMapForRange:64 |
|
8343 |
Depth4Image new greyByteMapForRange:64 |
|
8344 |
||
8345 |
Depth4Image new greyByteMapForRange:1 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8346 |
" |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8347 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8348 |
"Created: 8.6.1996 / 08:34:14 / cg" |
1403 | 8349 |
"Modified: 1.3.1997 / 17:24:45 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8350 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8351 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8352 |
greyMapForRange:range |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8353 |
"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
|
8354 |
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
|
8355 |
|
1403 | 8356 |
|d r clr val |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8357 |
n "{Class: SmallInteger }" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8358 |
greyArray| |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8359 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8360 |
d := self bitsPerPixel. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8361 |
n := 1 bitShift:d. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8362 |
n >= 4096 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8363 |
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
|
8364 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8365 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8366 |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8367 |
greyArray := Array new:n. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8368 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8369 |
photometric == #palette ifTrue:[ |
1403 | 8370 |
n := colorMap size. |
8371 |
1 to:n do:[:i | |
|
8372 |
(clr := colorMap at:i) isNil ifTrue:[ |
|
8373 |
"/ an unused color |
|
8374 |
val := 0. |
|
8375 |
] ifFalse:[ |
|
8376 |
val := range * clr brightness |
|
8377 |
]. |
|
8378 |
greyArray at:i put:val |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8379 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8380 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8381 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8382 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8383 |
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
|
8384 |
] |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8385 |
] ifFalse:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8386 |
r := range asFloat. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8387 |
1 to:n do:[:i | |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8388 |
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
|
8389 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8390 |
photometric == #blackIs0 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8391 |
"/ we are done |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8392 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8393 |
photometric == #whiteIs0 ifTrue:[ |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8394 |
greyArray reverse |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8395 |
] ifFalse:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8396 |
self error:'invalid format'. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8397 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8398 |
] |
798 | 8399 |
] |
8400 |
] |
|
8401 |
]. |
|
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8402 |
^ greyArray |
798 | 8403 |
|
8404 |
" |
|
8405 |
Depth8Image new greyMapForRange:64 |
|
8406 |
Depth4Image new greyMapForRange:64 |
|
8407 |
||
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8408 |
Depth16Image new greyMapForRange:1 |
798 | 8409 |
Depth4Image new greyMapForRange:1 |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8410 |
Depth2Image new greyMapForRange:1 |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8411 |
" |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8412 |
|
1403 | 8413 |
"Modified: 1.3.1997 / 15:48:49 / cg" |
798 | 8414 |
! |
8415 |
||
283 | 8416 |
magnifyRowFrom:srcBytes offset:srcStart pixels:oldPixels |
8417 |
into:dstBytes offset:dstStart factor:mX |
|
8418 |
||
8419 |
"magnify a single pixel row - can only magnify by integer factors, |
|
8420 |
can only magnify 1,2,4,8 and 24 bit-per-pixel images. But this is done fast." |
|
8421 |
||
8422 |
^ self subclassResponsibility |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8423 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8424 |
|
816 | 8425 |
makeDeviceGrayPixmapOn:aDevice depth:depth fromArray:bits |
8426 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
8427 |
pixels interpreted as greyValues, 0 is black, |
|
8428 |
create a device form for it" |
|
8429 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8430 |
|f| |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8431 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8432 |
f := Form width:width height:height depth:depth on:aDevice. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8433 |
f isNil ifTrue:[^ nil]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8434 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8435 |
f bits:bits. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8436 |
f initGC. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8437 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8438 |
(aDevice blackpixel ~~ 0) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8439 |
"/ have to invert bits |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8440 |
f function:#copyInverted |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8441 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8442 |
aDevice drawBits:bits depth:depth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8443 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8444 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8445 |
into:(f id) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8446 |
x:0 y:0 |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8447 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8448 |
with:(f gcId). |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8449 |
^ f |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8450 |
|
816 | 8451 |
"Created: 10.6.1996 / 20:10:31 / cg" |
8452 |
! |
|
8453 |
||
8454 |
makeDeviceMonochromeBitmapOn:aDevice fromArray:monoBits |
|
8455 |
"given the bits of a monochrome bitmap, 8-bit padded and |
|
8456 |
0-bits as black, create a device form for it" |
|
8457 |
||
8458 |
monoBits invert. |
|
8459 |
^ (Form width:width height:height fromArray:monoBits on:aDevice) |
|
8460 |
colorMap:(Array with:Color black with:Color white). |
|
8461 |
||
8462 |
"Created: 10.6.1996 / 20:18:09 / cg" |
|
8463 |
"Modified: 10.6.1996 / 20:31:24 / cg" |
|
8464 |
! |
|
8465 |
||
8466 |
makeDevicePixmapOn:aDevice depth:depth fromArray:bits |
|
8467 |
"given the bits of a grey/color bitmap, 8-bit padded and |
|
8468 |
pixels interpreted as in the devices colormap, |
|
8469 |
create a device form for it" |
|
8470 |
||
8471 |
|f| |
|
8472 |
||
8473 |
f := Form width:width height:height depth:depth on:aDevice. |
|
8474 |
f isNil ifTrue:[^ nil]. |
|
8475 |
||
8476 |
f bits:bits. |
|
8477 |
f initGC. |
|
8478 |
||
8479 |
aDevice drawBits:bits depth:depth |
|
8480 |
width:width height:height |
|
8481 |
x:0 y:0 |
|
8482 |
into:(f id) |
|
8483 |
x:0 y:0 |
|
8484 |
width:width height:height |
|
8485 |
with:(f gcId). |
|
8486 |
^ f |
|
8487 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
8488 |
"Created: 10.6.1996 / 17:56:08 / cg" |
816 | 8489 |
"Modified: 10.6.1996 / 20:11:27 / cg" |
2 | 8490 |
! ! |
0 | 8491 |
|
283 | 8492 |
!Image methodsFor:'queries'! |
8493 |
||
8494 |
averageColor |
|
8495 |
"return the average color of the image. |
|
8496 |
This usually only makes sense for textures and patterns |
|
8497 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
8498 |
Notice, that for the above purpose, it is usually ok to process |
|
8499 |
a subImage - i.e. use Image>>averageColorIn: on a smaller rectangle" |
|
8500 |
||
8501 |
^ self averageColorIn:(0@0 corner:(width-1)@(height-1)) |
|
8502 |
! |
|
8503 |
||
8504 |
averageColorIn:aRectangle |
|
8505 |
"return the images average color in an area. |
|
8506 |
The implementation below is slow - so you may want to |
|
8507 |
create tuned versions for DepthXImage if you plan to do |
|
8508 |
heavy image processing ... |
|
8509 |
(also, creating tuned versions of the enumeration messages helps a lot)" |
|
8510 |
||
8511 |
|x0 "{ Class:SmallInteger }" |
|
8512 |
y0 "{ Class:SmallInteger }" |
|
8513 |
x1 "{ Class:SmallInteger }" |
|
8514 |
y1 "{ Class:SmallInteger }" |
|
8515 |
sumRed sumGreen sumBlue n| |
|
8516 |
||
8517 |
sumRed := sumGreen := sumBlue := 0. |
|
8518 |
y0 := aRectangle top. |
|
8519 |
y1 := aRectangle bottom. |
|
8520 |
x0 := aRectangle left. |
|
8521 |
x1 := aRectangle right. |
|
8522 |
||
8523 |
self colorsFromX:x0 y:y0 toX:x1 y:y1 do:[:x :y :colorAtXY | |
|
8524 |
sumRed := sumRed + colorAtXY red. |
|
8525 |
sumGreen := sumGreen + colorAtXY green. |
|
8526 |
sumBlue := sumBlue + colorAtXY blue. |
|
8527 |
]. |
|
8528 |
n := (x1 - x0 + 1) * (y1 - y0 + 1). |
|
8529 |
^ Color red:(sumRed / n) green:(sumGreen / n) blue:(sumBlue / n) |
|
8530 |
! |
|
8531 |
||
8532 |
bitsPerPixel |
|
8533 |
"return the number of bits per pixel" |
|
8534 |
||
8535 |
^ (bitsPerSample inject:0 into:[:sum :i | sum + i]) |
|
8536 |
! |
|
8537 |
||
8538 |
bitsPerRow |
|
8539 |
"return the number of bits in one scanline of the image" |
|
8540 |
||
8541 |
^ width * (self bitsPerPixel). |
|
8542 |
! |
|
8543 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8544 |
blueBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8545 |
"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
|
8546 |
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
|
8547 |
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
|
8548 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8549 |
|blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8550 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8551 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8552 |
"/ 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
|
8553 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8554 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8555 |
blueBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8556 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8557 |
^ pixel bitAnd:(1 bitShift:blueBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8558 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8559 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8560 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8561 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8562 |
"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
|
8563 |
"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
|
8564 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8565 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8566 |
blueComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8567 |
"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
|
8568 |
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
|
8569 |
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
|
8570 |
|
854 | 8571 |
|blueBits "{ Class: SmallInteger }" |
8572 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8573 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8574 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8575 |
"/ 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
|
8576 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8577 |
blueBits := bitsPerSample at:3. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8578 |
blueBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8579 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8580 |
s := (1 bitShift:blueBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8581 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8582 |
^ 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
|
8583 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8584 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8585 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8586 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8587 |
"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
|
8588 |
"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
|
8589 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8590 |
|
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8591 |
bounds |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8592 |
"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
|
8593 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8594 |
^ 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
|
8595 |
|
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8596 |
"Created: 13.5.1996 / 10:27:06 / cg" |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8597 |
! |
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8598 |
|
283 | 8599 |
brightness |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8600 |
"return the (average) brightness of the image. |
283 | 8601 |
This usually only makes sense for textures and patterns |
8602 |
(i.e. to compute shadow & light colors for viewBackgrounds). |
|
8603 |
Notice, that for the above purpose, only a subimage is inspected here" |
|
8604 |
||
8605 |
^ (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
|
8606 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8607 |
"Modified: 8.6.1996 / 08:46:46 / cg" |
283 | 8608 |
! |
8609 |
||
8610 |
bytesPerRow |
|
8611 |
"return the number of bytes in one scanline of the image" |
|
8612 |
||
8613 |
|bitsPerRow bytesPerRow| |
|
8614 |
||
8615 |
bitsPerRow := width * (self bitsPerPixel). |
|
8616 |
bytesPerRow := bitsPerRow // 8. |
|
8617 |
((bitsPerRow \\ 8) ~~ 0) ifTrue:[ |
|
8618 |
bytesPerRow := bytesPerRow + 1 |
|
8619 |
]. |
|
8620 |
^ bytesPerRow |
|
8621 |
! |
|
8622 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8623 |
colorFromValue:pixelValue |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8624 |
"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
|
8625 |
Pixel values start with 0." |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8626 |
|
1289 | 8627 |
|p maxPixel r g b| |
8628 |
||
8629 |
p := photometric. |
|
8630 |
p isNil ifTrue:[ |
|
8631 |
colorMap notNil ifTrue:[ |
|
8632 |
p := #palette |
|
8633 |
] ifFalse:[ |
|
8634 |
"/ 'Image [warning]: no photometric - assume greyscale' infoPrintCR |
|
8635 |
p := #blackIs0 |
|
8636 |
] |
|
8637 |
]. |
|
8638 |
||
8639 |
p == #blackIs0 ifTrue:[ |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8640 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8641 |
^ Color gray:(pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8642 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8643 |
|
1289 | 8644 |
p == #whiteIs0 ifTrue:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8645 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8646 |
^ Color gray:100 - (pixelValue * (100 / maxPixel)). |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8647 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8648 |
|
1289 | 8649 |
p == #palette ifTrue:[ |
838
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
8650 |
pixelValue >= colorMap size ifTrue:[ |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
8651 |
^ Color black |
751f38db7453
handle invalid values in #colorFromValue:
Claus Gittinger <cg@exept.de>
parents:
837
diff
changeset
|
8652 |
]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8653 |
^ colorMap at:(pixelValue + 1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8654 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8655 |
|
1289 | 8656 |
p == #rgb ifTrue:[ |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8657 |
r := self redComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8658 |
g := self greenComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8659 |
b := self blueComponentOf:pixelValue. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8660 |
^ 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
|
8661 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8662 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8663 |
self error:'invalid photometric' |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8664 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8665 |
"Created: 8.6.1996 / 08:46:18 / cg" |
1289 | 8666 |
"Modified: 28.1.1997 / 12:05:22 / cg" |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8667 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8668 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8669 |
greenBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8670 |
"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
|
8671 |
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
|
8672 |
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
|
8673 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8674 |
|blueBits greenBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8675 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8676 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8677 |
"/ 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
|
8678 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8679 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8680 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8681 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8682 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8683 |
^ (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
|
8684 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8685 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8686 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8687 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8688 |
"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
|
8689 |
"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
|
8690 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8691 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8692 |
greenComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8693 |
"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
|
8694 |
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
|
8695 |
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
|
8696 |
|
854 | 8697 |
|greenBits "{ Class: SmallInteger }" |
8698 |
blueBits "{ Class: SmallInteger }" |
|
8699 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8700 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8701 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8702 |
"/ 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
|
8703 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8704 |
greenBits := bitsPerSample at:2. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8705 |
greenBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8706 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8707 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8708 |
s := (1 bitShift:greenBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8709 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8710 |
^ 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
|
8711 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8712 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8713 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8714 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8715 |
"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
|
8716 |
"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
|
8717 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8718 |
|
674 | 8719 |
heightOn:aGC |
8720 |
"return my height, if displayed on aGC; |
|
8721 |
since my height is independent of the device (the number of pixels), |
|
8722 |
return the pixel-height" |
|
8723 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8724 |
^ height |
674 | 8725 |
|
8726 |
"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
|
8727 |
"Modified: 13.5.1996 / 10:26:36 / cg" |
674 | 8728 |
! |
8729 |
||
283 | 8730 |
isImage |
8731 |
"return true, if the receiver is some kind of image; |
|
8732 |
true is returned here - the method is redefined from Object." |
|
8733 |
||
8734 |
^ true |
|
8735 |
! |
|
8736 |
||
8737 |
isImageOrForm |
|
8738 |
"return true, if the receiver is some kind of image or form; |
|
8739 |
true is returned here - the method is redefined from Object." |
|
8740 |
||
8741 |
^ true |
|
8742 |
! |
|
8743 |
||
1433 | 8744 |
pixelArraySpecies |
8745 |
"return the kind of pixel-value container in rowAt:/rowAt:put: methods" |
|
8746 |
||
8747 |
depth > 8 ifTrue:[ |
|
8748 |
^ Array |
|
8749 |
]. |
|
8750 |
^ ByteArray |
|
8751 |
||
8752 |
"Created: 6.3.1997 / 15:24:05 / cg" |
|
8753 |
! |
|
8754 |
||
940 | 8755 |
realColorMap |
8756 |
"return a collection usable as a real colormap of the image. |
|
8757 |
For palette images, this is the internal colormap; |
|
8758 |
for other photometrics (which do not have a real colormap), synthesize one. |
|
8759 |
This is different from #colorMap, which returns nil for non palette images." |
|
8760 |
||
8761 |
|d nEntries "{ Class: SmallInteger }" |
|
8762 |
colorArray| |
|
8763 |
||
8764 |
photometric == #palette ifTrue:[ |
|
8765 |
^ colorMap asArray |
|
8766 |
]. |
|
8767 |
||
8768 |
d := self depth. |
|
8769 |
d > 12 ifTrue:[ |
|
8770 |
self error:'deep palette images not supported'. |
|
8771 |
^ nil. |
|
8772 |
]. |
|
8773 |
||
8774 |
nEntries := 1 bitShift:d. |
|
8775 |
||
8776 |
colorArray := Array new:nEntries. |
|
8777 |
1 to:nEntries do:[:idx | |
|
8778 |
colorArray at:idx put:(self colorFromValue:(idx-1)). |
|
8779 |
]. |
|
8780 |
||
8781 |
^ colorArray |
|
8782 |
||
8783 |
"Created: 11.7.1996 / 20:20:35 / cg" |
|
8784 |
"Modified: 11.7.1996 / 20:49:21 / cg" |
|
8785 |
! |
|
8786 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8787 |
redBitsOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8788 |
"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
|
8789 |
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
|
8790 |
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
|
8791 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8792 |
|redBits greenBits blueBits| |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8793 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8794 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8795 |
"/ 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
|
8796 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8797 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8798 |
redBits == 0 ifTrue:[^ 0]. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8799 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8800 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8801 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8802 |
^ (pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8803 |
bitAnd:(1 bitShift:redBits)-1 |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8804 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8805 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8806 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8807 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8808 |
"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
|
8809 |
"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
|
8810 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8811 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8812 |
redComponentOf:pixel |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8813 |
"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
|
8814 |
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
|
8815 |
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
|
8816 |
|
854 | 8817 |
|redBits "{ Class: SmallInteger }" |
8818 |
greenBits "{ Class: SmallInteger }" |
|
8819 |
blueBits "{ Class: SmallInteger }" |
|
8820 |
s "{ Class: SmallInteger }"| |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8821 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8822 |
samplesPerPixel >= 3 ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8823 |
"/ 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
|
8824 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8825 |
redBits := bitsPerSample at:1. |
809
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8826 |
redBits == 0 ifTrue:[^ 0]. |
f66955a8200e
more dithering (multi-plane & monochrome floyd-steinberg)
Claus Gittinger <cg@exept.de>
parents:
808
diff
changeset
|
8827 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8828 |
greenBits := bitsPerSample at:2. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8829 |
blueBits := bitsPerSample at:3. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8830 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8831 |
s := (1 bitShift:redBits) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8832 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8833 |
^ 100.0 / s * |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8834 |
((pixel bitShift:(greenBits + blueBits) negated) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8835 |
bitAnd:(1 bitShift:redBits)-1) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8836 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8837 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8838 |
self subclassResponsibility |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8839 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8840 |
"Created: 8.6.1996 / 08:45:30 / cg" |
854 | 8841 |
"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
|
8842 |
! |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8843 |
|
283 | 8844 |
usedColors |
8845 |
"return a collection of colors used in the receiver." |
|
8846 |
||
8847 |
|usedValues max| |
|
8848 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8849 |
photometric == #rgb ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8850 |
"/ 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
|
8851 |
"/ 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
|
8852 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8853 |
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
|
8854 |
^ nil |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8855 |
]. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8856 |
|
283 | 8857 |
usedValues := self usedValues asArray. |
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8858 |
photometric == #palette ifTrue:[ |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8859 |
^ usedValues collect:[:val | (colorMap at:val+1)] |
283 | 8860 |
]. |
8861 |
||
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8862 |
"/ (photometric == #blackIs0 or:[photometric == #whiteIs0]) |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8863 |
|
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8864 |
max := (1 bitShift:self depth) - 1. |
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8865 |
^ usedValues collect:[:val | (Color gray:(100 * val / max ))] |
283 | 8866 |
|
8867 |
" |
|
8868 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
8869 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
8870 |
(Image fromFile:'ttt.tiff') usedColors |
|
8871 |
" |
|
746 | 8872 |
|
804
f1921926e324
better multiplane dither; support #rgb; specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
800
diff
changeset
|
8873 |
"Modified: 8.6.1996 / 09:04:56 / cg" |
283 | 8874 |
! |
8875 |
||
8876 |
usedValues |
|
8877 |
"return a collection of color values used in the receiver. |
|
8878 |
Notice, that the interpretation of the pixels depends on the photometric |
|
8879 |
of the image. |
|
8880 |
This is a general and therefore slow implementation; subclasses |
|
8881 |
may want to redefine this method for more performance." |
|
8882 |
||
8883 |
|set| |
|
8884 |
||
8885 |
set := IdentitySet new. |
|
8886 |
self valuesFromX:0 y:0 toX:(self width-1) y:(self height-1) do:[:x :y :pixel | |
|
8887 |
set add:pixel |
|
8888 |
]. |
|
8889 |
^ set |
|
8890 |
||
8891 |
" |
|
8892 |
(Image fromFile:'bitmaps/garfield.gif') usedValues |
|
8893 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedValues |
|
8894 |
(Image fromFile:'ttt.tiff') usedValues |
|
8895 |
" |
|
674 | 8896 |
! |
8897 |
||
861
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8898 |
valueFromColor:color |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8899 |
"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
|
8900 |
Non-representable colors return nil." |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8901 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8902 |
|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
|
8903 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8904 |
photometric == #whiteIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8905 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8906 |
^ maxPixel - (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8907 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8908 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8909 |
photometric == #blackIs0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8910 |
maxPixel := (1 bitShift:self bitsPerPixel) - 1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8911 |
^ (color brightness * maxPixel) rounded. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8912 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8913 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8914 |
photometric == #palette ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8915 |
pixel := colorMap indexOf:color. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8916 |
pixel == 0 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8917 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8918 |
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
|
8919 |
" |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8920 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8921 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8922 |
^ pixel - 1 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8923 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8924 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8925 |
photometric == #rgb ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8926 |
samplesPerPixel >= 3 ifTrue:[ |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8927 |
redBits := bitsPerSample at:1. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8928 |
greenBits := bitsPerSample at:2. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8929 |
blueBits := bitsPerSample at:3. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8930 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8931 |
"/ map r/g/b to 0..255 |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8932 |
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
|
8933 |
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
|
8934 |
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
|
8935 |
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
|
8936 |
^ pixel |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8937 |
] |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8938 |
]. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8939 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8940 |
self error:'format not supported'. |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8941 |
^ nil |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8942 |
|
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8943 |
"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
|
8944 |
! |
5d897dbd681a
oops - leftover halt removed; added fill & valueFromColor.
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
8945 |
|
674 | 8946 |
widthOn:aGC |
8947 |
"return my width, if displayed on aGC; |
|
8948 |
since my width is independent of the device (the number of pixels), |
|
8949 |
return the pixel-width" |
|
8950 |
||
680
a905d02dcb82
added #bounds (for VisualComponent protocol compatibility)
Claus Gittinger <cg@exept.de>
parents:
674
diff
changeset
|
8951 |
^ width |
674 | 8952 |
|
8953 |
"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
|
8954 |
"Modified: 13.5.1996 / 10:26:42 / cg" |
283 | 8955 |
! ! |
8956 |
||
8957 |
!Image methodsFor:'saving on file'! |
|
8958 |
||
8959 |
saveOn:aFileName |
|
8960 |
"save the image in a aFileName. The suffix of the filename |
|
8961 |
controls the format. Currently, not all formats may be supported |
|
1573 | 8962 |
(see ImageReader subclasses implementing save:onFile:). |
8963 |
May raise a signal, if the image cannot be written by the |
|
8964 |
reader." |
|
283 | 8965 |
|
1307 | 8966 |
|suffix readerClass| |
8967 |
||
8968 |
"/ |
|
8969 |
"/ from the extension, get the imageReader class |
|
8970 |
"/ (which should know how to write images as well) |
|
8971 |
"/ |
|
8972 |
suffix := aFileName asFilename suffix. |
|
8973 |
readerClass := FileFormats at:suffix ifAbsent:nil. |
|
8974 |
readerClass notNil ifTrue:[ |
|
8975 |
^ self saveOn:aFileName using:readerClass |
|
8976 |
]. |
|
8977 |
||
8978 |
"/ |
|
8979 |
"/ no known extension - could ask user for the format here. |
|
8980 |
"/ currently default to tiff format. |
|
8981 |
"/ |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8982 |
'Image [warning]: unknown extension - cannot figure out format - using tiff' errorPrintCR. |
1307 | 8983 |
|
283 | 8984 |
^ self saveOn:aFileName using:TIFFReader |
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
8985 |
|
1385
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8986 |
" |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8987 |
|image| |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8988 |
|
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8989 |
image := Image fromFile:'bitmaps/RCube.tiff'. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8990 |
image saveOn:'myImage.tiff'. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8991 |
image saveOn:'myImage.xbm'. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8992 |
image saveOn:'myImage.xpm'. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8993 |
image saveOn:'myImage.xwd'. |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8994 |
" |
461b3901950e
more signals to be raised if anything happens during
Claus Gittinger <cg@exept.de>
parents:
1374
diff
changeset
|
8995 |
|
1573 | 8996 |
"Modified: 10.4.1997 / 17:38:35 / cg" |
89 | 8997 |
! |
8998 |
||
283 | 8999 |
saveOn:aFileName using:readerClass |
1573 | 9000 |
"save the receiver using the representation class. |
9001 |
May raise a signal, if the image cannot be written by the |
|
9002 |
reader." |
|
283 | 9003 |
|
1307 | 9004 |
^ readerClass save:self onFile:aFileName |
283 | 9005 |
|
9006 |
" |
|
1573 | 9007 |
|anImage| |
9008 |
||
9009 |
anImage := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
|
9010 |
anImage saveOn:'myImage.tiff' using:TIFFReader. |
|
9011 |
anImage saveOn:'myImage.xbm' using:XBMReader. |
|
9012 |
anImage saveOn:'myImage.xpm' using:XPMReader. |
|
9013 |
anImage saveOn:'myImage.gif' using:GIFReader. |
|
9014 |
" |
|
9015 |
||
9016 |
"Modified: 10.4.1997 / 17:38:24 / cg" |
|
0 | 9017 |
! ! |
283 | 9018 |
|
9019 |
!Image methodsFor:'screen capture'! |
|
9020 |
||
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9021 |
from:aDrawable in:aRectangle |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9022 |
"read an image from aDrawable. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9023 |
This may be a device Form, a view or the rootView. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9024 |
If its a view or rootView, it must be completely visible (or have |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9025 |
the backingStore option turned on). Otherwise, only the clipped contents |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9026 |
is returned. This is a common helper for form-to-image conversion, |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9027 |
and to read hardcopy images from the screen." |
283 | 9028 |
|
9029 |
|depth visType |
|
9030 |
x "{ Class: SmallInteger }" |
|
9031 |
y "{ Class: SmallInteger }" |
|
9032 |
w "{ Class: SmallInteger }" |
|
9033 |
h "{ Class: SmallInteger }" |
|
9034 |
dstIndex "{ Class: SmallInteger }" |
|
9035 |
srcIndex "{ Class: SmallInteger }" |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9036 |
srcRow "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9037 |
dstRow "{ Class: SmallInteger }" |
283 | 9038 |
inData tmpData usedPixels mapSize |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9039 |
map bitsPerPixel bytesPerLine byteOrder spaceBitsPerPixel |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9040 |
info bitsPerPixelIn bytesPerLineIn |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9041 |
maskR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9042 |
maskG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9043 |
maskB "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9044 |
shR "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9045 |
shG "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9046 |
shB "{ Class: SmallInteger }" |
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
9047 |
shR2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
9048 |
shG2 "{ Class: SmallInteger }" |
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
9049 |
shB2 "{ Class: SmallInteger }" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9050 |
r "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9051 |
g "{ Class: SmallInteger }" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9052 |
b "{ Class: SmallInteger }" |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9053 |
word device| |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9054 |
|
927
c4bc2a7ff733
use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents:
924
diff
changeset
|
9055 |
device := aDrawable graphicsDevice. |
283 | 9056 |
|
936 | 9057 |
(aDrawable isForm and:[aDrawable depth == 1]) ifTrue:[ |
9058 |
"/ a monochrome bitmap ? |
|
9059 |
visType := #StaticGray. |
|
9060 |
depth := 1. |
|
9061 |
] ifFalse:[ |
|
9062 |
" |
|
9063 |
get some attributes of the display device |
|
9064 |
" |
|
9065 |
visType := device visualType. |
|
9066 |
depth := device depth. |
|
9067 |
]. |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9068 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9069 |
"/ kludge for 15bit XFree server |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9070 |
depth == 15 ifTrue:[ |
518 | 9071 |
depth := 16 |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9072 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9073 |
|
283 | 9074 |
(visType == #StaticGray) ifTrue:[ |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9075 |
(device blackpixel == 0) ifTrue:[ |
518 | 9076 |
photometric := #blackIs0 |
9077 |
] ifFalse:[ |
|
9078 |
photometric := #whiteIs0 |
|
9079 |
]. |
|
9080 |
samplesPerPixel := 1. |
|
9081 |
bitsPerPixel := depth. |
|
9082 |
bitsPerSample := Array with:bitsPerPixel. |
|
283 | 9083 |
] ifFalse:[ |
518 | 9084 |
((visType == #PseudoColor) or:[(visType == #StaticColor) or:[visType == #GrayScale]]) ifTrue:[ |
9085 |
photometric := #palette. |
|
9086 |
samplesPerPixel := 1. |
|
9087 |
bitsPerPixel := depth. |
|
9088 |
bitsPerSample := Array with:bitsPerPixel. |
|
9089 |
] ifFalse:[ |
|
9090 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
9091 |
photometric := #rgb. |
|
9092 |
samplesPerPixel := 3. |
|
401
f163a93a0987
grab image as 24bit rgb on 15/16bit trueColor servers
Claus Gittinger <cg@exept.de>
parents:
399
diff
changeset
|
9093 |
"/ bitsPerPixel := depth. |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9094 |
"/ bitsPerSample := Array with:device bitsRed |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9095 |
"/ with:device bitsGreen |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9096 |
"/ with:device bitsBlue |
518 | 9097 |
bitsPerPixel := 24. |
9098 |
bitsPerSample := #(8 8 8). |
|
9099 |
] ifFalse:[ |
|
9100 |
self error:'screen visual not supported'. |
|
9101 |
^ nil |
|
9102 |
] |
|
9103 |
] |
|
283 | 9104 |
]. |
9105 |
||
9106 |
" |
|
9107 |
dont know yet, how the display pads; assume worst case, |
|
9108 |
offering enough space for 32 bit padding |
|
9109 |
" |
|
9110 |
w := width := aRectangle width. |
|
9111 |
h := height := aRectangle height. |
|
9112 |
x := aRectangle left. |
|
9113 |
y := aRectangle top. |
|
9114 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9115 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9116 |
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
|
9117 |
(its too late when info is present ...) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9118 |
" |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9119 |
spaceBitsPerPixel := bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9120 |
(bitsPerPixel > 8) ifTrue:[ |
518 | 9121 |
spaceBitsPerPixel := 16. |
9122 |
(bitsPerPixel > 16) ifTrue:[ |
|
9123 |
spaceBitsPerPixel := 32. |
|
9124 |
(bitsPerPixel > 32) ifTrue:[ |
|
9125 |
spaceBitsPerPixel := bitsPerPixel. |
|
9126 |
] |
|
9127 |
] |
|
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9128 |
]. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9129 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9130 |
bytesPerLine := (w * spaceBitsPerPixel + 31) // 32 * 4. |
283 | 9131 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
9132 |
||
9133 |
" |
|
9134 |
get the pixels |
|
9135 |
" |
|
1459
84e80b355553
splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents:
1446
diff
changeset
|
9136 |
aDrawable isForm ifTrue:[ |
1461
6d8b022bfcd8
renamed getBitsFrom to getBitsFromId
Claus Gittinger <cg@exept.de>
parents:
1459
diff
changeset
|
9137 |
info := device getBitsFromPixmapId:aDrawable id x:x y:y width:w height:h into:inData. |
1459
84e80b355553
splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents:
1446
diff
changeset
|
9138 |
] ifFalse:[ |
1461
6d8b022bfcd8
renamed getBitsFrom to getBitsFromId
Claus Gittinger <cg@exept.de>
parents:
1459
diff
changeset
|
9139 |
info := device getBitsFromViewId:aDrawable id x:x y:y width:w height:h into:inData. |
1459
84e80b355553
splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents:
1446
diff
changeset
|
9140 |
]. |
283 | 9141 |
|
9142 |
" |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
9143 |
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
|
9144 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9145 |
byteOrder := info at:#byteOrder. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9146 |
bitsPerPixelIn := info at:#bitsPerPixel. |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9147 |
byteOrder ~~ #msbFirst ifTrue:[ |
518 | 9148 |
bitsPerPixelIn == 16 ifTrue:[ |
9149 |
"/ must swap bytes |
|
9150 |
inData swapBytes |
|
9151 |
] ifFalse:[ |
|
9152 |
bitsPerPixelIn == 32 ifTrue:[ |
|
9153 |
"/ must swap longs |
|
9154 |
inData swapLongs |
|
9155 |
] |
|
9156 |
] |
|
396
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
9157 |
]. |
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
9158 |
|
d088e672be8a
handle screen image grabbing with depth 16/24 and different byteOrder
Claus Gittinger <cg@exept.de>
parents:
394
diff
changeset
|
9159 |
" |
283 | 9160 |
check, if the devices padding is different .. |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9161 |
or if the bitsPerPixels are different |
283 | 9162 |
" |
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9163 |
bytesPerLineIn := (info at:#bytesPerLine). "what I got" |
283 | 9164 |
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
|
9165 |
|
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9166 |
((bytesPerLine ~~ bytesPerLineIn) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9167 |
or:[bitsPerPixelIn ~~ bitsPerPixel]) ifTrue:[ |
518 | 9168 |
tmpData := inData. |
9169 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
9170 |
||
9171 |
srcRow := 1. |
|
9172 |
dstRow := 1. |
|
9173 |
||
9174 |
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[ |
|
9175 |
"/ for now, only 32 -> 24 is supported |
|
9176 |
||
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9177 |
maskR := (1 bitShift:device bitsRed) - 1. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9178 |
maskG := (1 bitShift:device bitsGreen) - 1. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9179 |
maskB := (1 bitShift:device bitsBlue) - 1. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9180 |
shR := device shiftRed negated. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9181 |
shG := device shiftGreen negated. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9182 |
shB := device shiftBlue negated. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9183 |
shR2 := (8 - device bitsRed). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9184 |
shG2 := (8 - device bitsGreen). |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9185 |
shB2 := (8 - device bitsBlue). |
518 | 9186 |
|
9187 |
((bitsPerPixelIn == 32) and:[bitsPerPixel == 24]) ifTrue:[ |
|
9188 |
"/ 'reformatting 32->24...' printNL. |
|
9189 |
1 to:h do:[:hi | |
|
9190 |
srcIndex := srcRow. |
|
9191 |
dstIndex := dstRow. |
|
9192 |
||
9193 |
1 to:w do:[:wi | |
|
9194 |
word := tmpData doubleWordAt:srcIndex MSB:true. |
|
9195 |
r := (word bitShift:shR) bitAnd:maskR. |
|
9196 |
g := (word bitShift:shG) bitAnd:maskG. |
|
9197 |
b := (word bitShift:shB) bitAnd:maskB. |
|
9198 |
||
9199 |
inData at:dstIndex put:r. |
|
9200 |
inData at:dstIndex+1 put:g. |
|
9201 |
inData at:dstIndex+2 put:b. |
|
9202 |
srcIndex := srcIndex + 4. |
|
9203 |
dstIndex := dstIndex + 3. |
|
9204 |
]. |
|
9205 |
dstRow := dstRow + bytesPerLine. |
|
9206 |
srcRow := srcRow + bytesPerLineIn |
|
9207 |
] |
|
9208 |
] ifFalse:[ |
|
9209 |
((bitsPerPixelIn == 16) and:[bitsPerPixel == 24]) ifTrue:[ |
|
9210 |
"/ 'reformatting 16->24...' printNL. |
|
9211 |
1 to:h do:[:hi | |
|
9212 |
srcIndex := srcRow. |
|
9213 |
dstIndex := dstRow. |
|
9214 |
||
9215 |
1 to:w do:[:wi | |
|
9216 |
word := tmpData wordAt:srcIndex MSB:true. |
|
9217 |
r := (word bitShift:shR) bitAnd:maskR. |
|
9218 |
g := (word bitShift:shG) bitAnd:maskG. |
|
9219 |
b := (word bitShift:shB) bitAnd:maskB. |
|
9220 |
||
9221 |
inData at:dstIndex put:(r bitShift:shR2). |
|
9222 |
inData at:dstIndex+1 put:(g bitShift:shG2). |
|
9223 |
inData at:dstIndex+2 put:(b bitShift:shB2). |
|
9224 |
srcIndex := srcIndex + 2. |
|
9225 |
dstIndex := dstIndex + 3. |
|
9226 |
]. |
|
9227 |
dstRow := dstRow + bytesPerLine. |
|
9228 |
srcRow := srcRow + bytesPerLineIn |
|
9229 |
] |
|
9230 |
] ifFalse:[ |
|
1175
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
9231 |
('Image [warning]: unsupported depth combination: ' , bitsPerPixelIn printString , ' -> ' , |
5595569cfbd3
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1170
diff
changeset
|
9232 |
bitsPerPixel printString) errorPrintCR. |
518 | 9233 |
^ nil |
9234 |
] |
|
9235 |
]. |
|
9236 |
] ifFalse:[ |
|
9237 |
" |
|
9238 |
repad in the buffer |
|
9239 |
" |
|
9240 |
1 to:h do:[:hi | |
|
9241 |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1) |
|
9242 |
with:tmpData startingAt:srcRow. |
|
9243 |
dstRow := dstRow + bytesPerLine. |
|
9244 |
srcRow := srcRow + bytesPerLineIn |
|
9245 |
] |
|
9246 |
] |
|
283 | 9247 |
] ifFalse:[ |
518 | 9248 |
(bytesPerLine * height) ~~ inData size ifTrue:[ |
9249 |
tmpData := inData. |
|
9250 |
inData := ByteArray uninitializedNew:(bytesPerLine * height). |
|
9251 |
inData replaceFrom:1 to:bytesPerLine * height with:tmpData startingAt:1 |
|
9252 |
] |
|
283 | 9253 |
]. |
9254 |
bytes := inData. |
|
9255 |
||
9256 |
"info printNL." |
|
9257 |
||
399
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9258 |
((visType == #StaticGray) |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9259 |
or:[visType == #TrueColor |
0b6e43843204
handle 24 truecolor displays in fromScreen
Claus Gittinger <cg@exept.de>
parents:
396
diff
changeset
|
9260 |
or:[visType == #DirectColor]]) ifTrue:[ |
518 | 9261 |
" |
9262 |
were done, the pixel values are the rgb/grey values |
|
9263 |
" |
|
283 | 9264 |
] ifFalse:[ |
518 | 9265 |
" |
9266 |
what we have now are the color numbers - still need the r/g/b values. |
|
9267 |
find out, which colors are in the picture |
|
9268 |
" |
|
9269 |
usedPixels := inData usedValues. |
|
9270 |
mapSize := usedPixels max + 1. |
|
9271 |
||
9272 |
"get the palette" |
|
9273 |
map := Array new:mapSize. |
|
9274 |
usedPixels do:[:colorIndex | |
|
9275 |
|i| |
|
9276 |
||
9277 |
i := colorIndex + 1. |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9278 |
device getRGBFrom:colorIndex into:[:r :g :b | |
518 | 9279 |
map at:i put:(Color red:r green:g blue:b) |
9280 |
] |
|
9281 |
]. |
|
9282 |
colorMap := map. |
|
283 | 9283 |
]. |
9284 |
||
1459
84e80b355553
splitted getBitsFrom into getBitsFromPixmap
Claus Gittinger <cg@exept.de>
parents:
1446
diff
changeset
|
9285 |
"Modified: 19.3.1997 / 13:45:01 / cg" |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9286 |
! |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9287 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9288 |
fromScreen:aRectangle |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9289 |
"read an image from the display screen. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9290 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9291 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9292 |
(use #fromScreen:on:grab: with a false grabArg then)." |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9293 |
|
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9294 |
^ self |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9295 |
fromScreen:aRectangle |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9296 |
on:Screen current |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9297 |
grab:true |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9298 |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9299 |
"Modified: 26.3.1997 / 10:43:34 / cg" |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9300 |
! |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9301 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9302 |
fromScreen:aRectangle on:aDevice |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9303 |
"read an image from aDevices display screen. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9304 |
Since I have no other displays, only the MonoChrome, StaticGrey |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9305 |
and PseudoColor cases have been tested ... |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9306 |
(especially True- and DirectColor may be wrong). |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9307 |
Late note: 24bit rgb now also works. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9308 |
WARNING: this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9309 |
it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9310 |
(use #fromScreen:on:grab: with a false grabArg then)." |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9311 |
|
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9312 |
^ self |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9313 |
fromScreen:aRectangle |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9314 |
on:aDevice |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9315 |
grab:true |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9316 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9317 |
" |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9318 |
(Image new) fromScreen:((0 @ 0) corner:(100 @ 100)) on:Display |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9319 |
(Image new) fromScreen:((0 @ 0) corner:(500 @ 500)) on:Display |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9320 |
" |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9321 |
|
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9322 |
"Modified: 26.3.1997 / 10:43:48 / cg" |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9323 |
! |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9324 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9325 |
fromScreen:aRectangle on:aDevice grab:doGrab |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9326 |
"read an image from aDevices display screen. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9327 |
If the doGrab argument is true, the display |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9328 |
is grabbed (i.e. blocked for others) and a camera cursor is |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9329 |
shown while the readout is done. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9330 |
Since I have no other displays, only the MonoChrome, StaticGrey |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9331 |
and PseudoColor cases have been tested ... |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9332 |
(especially True- and DirectColor may be wrong). |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9333 |
Late note: 24bit rgb now also works. |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9334 |
WARNING: with doGrab true, this temporarily grabs the display |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9335 |
and it may not work from within a buttonMotion |
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9336 |
(use with a false grabArg then)." |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9337 |
|
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9338 |
|curs cid rootView| |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9339 |
|
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9340 |
doGrab ifTrue:[ |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9341 |
curs := Cursor sourceForm:(Image fromFile:'bitmaps/Camera.xbm') |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9342 |
maskForm:(Image fromFile:'bitmaps/Camera_m.xbm') |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9343 |
hotSpot:16@16. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9344 |
curs notNil ifTrue:[ |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9345 |
cid := (curs on:aDevice) id |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9346 |
]. |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9347 |
]. |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9348 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9349 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9350 |
actually have to grabServer ... but thats not yet available |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9351 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9352 |
rootView := aDevice rootView. |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9353 |
doGrab ifTrue:[ |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9354 |
aDevice setActivePointerGrab:rootView. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9355 |
aDevice grabPointerIn:rootView id |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9356 |
withCursor:cid |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9357 |
pointerMode:#async |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9358 |
keyboardMode:#sync |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9359 |
confineTo:nil. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9360 |
]. |
924
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9361 |
|
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9362 |
" |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9363 |
get the pixels |
d6d5d427b176
fixed conversion from deep device forms
Claus Gittinger <cg@exept.de>
parents:
916
diff
changeset
|
9364 |
" |
1487
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9365 |
[ |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9366 |
self from:rootView in:aRectangle. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9367 |
] valueNowOrOnUnwindDo:[ |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9368 |
doGrab ifTrue:[ |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9369 |
aDevice ungrabPointer. |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9370 |
] |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9371 |
] |
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9372 |
|
1d8efd4d85c3
allow screen capture without a grab
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
9373 |
"Created: 26.3.1997 / 10:36:30 / cg" |
1488
436e5944129b
comments warning about grab & buttonMotion
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
9374 |
"Modified: 26.3.1997 / 10:44:45 / cg" |
936 | 9375 |
! |
9376 |
||
9377 |
photometricFromScreen:aDevice |
|
9378 |
"read aDevices display photometric and set my colormap for it. |
|
9379 |
This must be used after an images bits have been read from the screen |
|
9380 |
or from an offScreen bitmap, for correct pixel interpretation." |
|
9381 |
||
9382 |
|depth visType bitsPerPixel| |
|
9383 |
||
9384 |
" |
|
9385 |
get some attributes of the display device |
|
9386 |
" |
|
9387 |
visType := aDevice visualType. |
|
9388 |
depth := aDevice depth. |
|
9389 |
||
9390 |
"/ kludge for 15bit XFree server |
|
9391 |
depth == 15 ifTrue:[ |
|
9392 |
depth := 16 |
|
9393 |
]. |
|
9394 |
||
9395 |
(visType == #StaticGray) ifTrue:[ |
|
9396 |
(aDevice blackpixel == 0) ifTrue:[ |
|
9397 |
photometric := #blackIs0 |
|
9398 |
] ifFalse:[ |
|
9399 |
photometric := #whiteIs0 |
|
9400 |
]. |
|
9401 |
samplesPerPixel := 1. |
|
9402 |
bitsPerPixel := depth. |
|
9403 |
bitsPerSample := Array with:bitsPerPixel. |
|
9404 |
" |
|
9405 |
were done, the pixel values are the grey values |
|
9406 |
" |
|
9407 |
^ self |
|
9408 |
]. |
|
9409 |
||
9410 |
((visType == #TrueColor) or:[visType == #DirectColor]) ifTrue:[ |
|
9411 |
photometric := #rgb. |
|
9412 |
samplesPerPixel := 3. |
|
9413 |
||
9414 |
"/ for now - only support 24bit TrueColor |
|
9415 |
depth ~~ 24 ifTrue:[ |
|
9416 |
'IMAGE: unsupported display depth' errorPrintCR. |
|
9417 |
]. |
|
9418 |
"/ bitsPerPixel := depth. |
|
9419 |
"/ bitsPerSample := Array with:aDevice bitsRed |
|
9420 |
"/ with:aDevice bitsGreen |
|
9421 |
"/ with:aDevice bitsBlue |
|
9422 |
bitsPerPixel := 24. |
|
9423 |
bitsPerSample := #(8 8 8). |
|
9424 |
" |
|
9425 |
were done, the pixel values are the rgb values |
|
9426 |
" |
|
9427 |
^ self |
|
9428 |
]. |
|
9429 |
||
9430 |
((visType ~~ #PseudoColor) |
|
9431 |
and:[(visType ~~ #StaticColor) |
|
9432 |
and:[visType ~~ #GrayScale]]) ifTrue:[ |
|
9433 |
self error:'screen visual not supported'. |
|
9434 |
^ nil |
|
9435 |
]. |
|
9436 |
||
9437 |
photometric := #palette. |
|
9438 |
samplesPerPixel := 1. |
|
9439 |
bitsPerPixel := depth. |
|
9440 |
bitsPerSample := Array with:bitsPerPixel. |
|
9441 |
||
9442 |
" |
|
9443 |
still need the pixels r/g/b values ... |
|
9444 |
" |
|
9445 |
colorMap := aDevice colorMap |
|
9446 |
||
9447 |
"Modified: 11.7.1996 / 11:11:34 / cg" |
|
283 | 9448 |
! ! |
9449 |
||
1086
269243c32f69
added displayOpaque, for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
9450 |
!Image class methodsFor:'documentation'! |
283 | 9451 |
|
9452 |
version |
|
1573 | 9453 |
^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.164 1997-04-10 15:45:37 cg Exp $' |
650 | 9454 |
! ! |
283 | 9455 |
Image initialize! |