author | Claus Gittinger <cg@exept.de> |
Tue, 29 Apr 2003 20:49:19 +0200 | |
changeset 3867 | 2a620c958987 |
parent 3866 | c01473a90934 |
child 3868 | e47cf114c824 |
permissions | -rw-r--r-- |
3 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 3 |
All Rights Reserved |
3 | 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 |
" |
|
1 | 12 |
|
3263 | 13 |
"{ Package: 'stx:libview' }" |
14 |
||
1 | 15 |
Image subclass:#Depth1Image |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
16 |
instanceVariableNames:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
17 |
classVariableNames:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
18 |
poolDictionaries:'' |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
19 |
category:'Graphics-Images' |
1 | 20 |
! |
21 |
||
46 | 22 |
!Depth1Image class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 27 |
All Rights Reserved |
3 | 28 |
|
46 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
3 | 37 |
|
46 | 38 |
documentation |
39 |
" |
|
40 |
this class represents bilevel (1 bit / pixel) images. |
|
81 | 41 |
It mainly consists of methods which are already implemented in Image, |
42 |
but reimplemented here for more performance. If you plan to do heavy |
|
43 |
image processing on bilevel images, you may want to add more |
|
44 |
specialized methods here. |
|
611 | 45 |
|
798 | 46 |
#blackIs0 / #whiteIs0 and #palette formats are supported here. |
47 |
||
611 | 48 |
[author:] |
49 |
Claus Gittinger |
|
50 |
||
51 |
[see also:] |
|
52 |
Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image |
|
53 |
ImageReader |
|
46 | 54 |
" |
55 |
! ! |
|
3 | 56 |
|
89 | 57 |
!Depth1Image class methodsFor:'queries'! |
58 |
||
59 |
imageDepth |
|
579 | 60 |
"return the depth of images represented by instances of |
61 |
this class - here we return 1" |
|
62 |
||
89 | 63 |
^ 1 |
579 | 64 |
|
65 |
"Modified: 20.4.1996 / 23:40:06 / cg" |
|
89 | 66 |
! ! |
67 |
||
3263 | 68 |
!Depth1Image methodsFor:'accessing-pixels'! |
1 | 69 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
70 |
pixelAtX:x y:y |
279 | 71 |
"retrieve a pixelValue at x/y; return a number. |
72 |
The interpretation of the returned value depends on the photometric |
|
73 |
and the colormap. See also Image>>atX:y:) |
|
74 |
Pixels start at 0@0 for upper left pixel, end at |
|
75 |
(width-1)@(height-1) for lower right pixel" |
|
76 |
||
3842 | 77 |
|index "{Class: SmallInteger}" |
279 | 78 |
byte "{Class: SmallInteger}" |
79 |
mask "{Class: SmallInteger}"| |
|
80 |
||
81 |
%{ /* NOCONTEXT */ |
|
82 |
||
83 |
OBJ b = _INST(bytes); |
|
84 |
OBJ w = _INST(width); |
|
1 | 85 |
|
3842 | 86 |
if (__bothSmallInteger(x, y) && __isSmallInteger(w)) { |
87 |
if (__isByteArray(b)) { |
|
88 |
int _w = __intVal(w); |
|
89 |
int _y = __intVal(y); |
|
90 |
int _x = __intVal(x); |
|
91 |
unsigned _byte; |
|
92 |
int _idx; |
|
279 | 93 |
|
3842 | 94 |
_idx = ((_w + 7) >> 3) * _y + (_x >> 3); |
95 |
if ((unsigned)_idx < __byteArraySize(b)) { |
|
96 |
_byte = __ByteArrayInstPtr(b)->ba_element[_idx]; |
|
97 |
RETURN( (_byte & (0x80 >> (_x & 7))) ? __MKSMALLINT(1) : __MKSMALLINT(0) ); |
|
98 |
} |
|
1635
2941772ea31d
added bounds check to #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
99 |
} |
279 | 100 |
} |
101 |
%}. |
|
102 |
||
3842 | 103 |
"/ the code below is only evaluated if the bytes-collection is |
104 |
"/ not a ByteArray, or the arguments are not integers |
|
105 |
||
106 |
index := (self bytesPerRow * y) + 1 + (x // 8). |
|
279 | 107 |
|
3842 | 108 |
"left pixel is in high bit" |
109 |
byte := bytes at:index. |
|
110 |
mask := 1 bitShift:(7 - (x \\ 8)). |
|
111 |
(byte bitAnd:mask) == 0 ifTrue:[^ 0]. |
|
112 |
^ 1 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
113 |
! |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
114 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
115 |
pixelAtX:x y:y put:aPixelValue |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
116 |
"set a pixels value at x/y to aPixelValue. |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
117 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
118 |
x = width-1, y=height-1 for lower right pixel" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
119 |
|
3842 | 120 |
|index "{Class: SmallInteger}" |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
121 |
byte "{Class: SmallInteger}" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
122 |
mask "{Class: SmallInteger}"| |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
123 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
124 |
%{ /* NOCONTEXT */ |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
125 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
126 |
OBJ b = _INST(bytes); |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
127 |
OBJ w = _INST(width); |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
128 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
129 |
if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) { |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
130 |
int _w = __intVal(w); |
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
131 |
int _y = __intVal(y); |
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
132 |
int _x = __intVal(x); |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
133 |
int _idx; |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
134 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
135 |
_idx = ((_w + 7) >> 3) * _y + (_x >> 3); |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
136 |
if ((unsigned)_idx < __byteArraySize(b)) { |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
137 |
if (aPixelValue == __MKSMALLINT(0)) { |
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1655
diff
changeset
|
138 |
__ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7)); |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
139 |
} else { |
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1655
diff
changeset
|
140 |
__ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7)); |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
141 |
} |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
142 |
RETURN( self ); |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
143 |
} |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
144 |
} |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
145 |
%}. |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
146 |
"fall back code for nonByteArray or nonInteger arguments" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
147 |
|
3842 | 148 |
index := (self bytesPerRow * y) + 1 + (x // 8). |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
149 |
|
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
150 |
"left pixel is in high bit" |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
151 |
byte := bytes at:index. |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
152 |
mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1). |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
153 |
aPixelValue == 0 ifTrue:[ |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
154 |
byte := byte bitAnd:(mask bitInvert) |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
155 |
] ifFalse:[ |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
156 |
byte := byte bitOr:mask |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
157 |
]. |
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
158 |
bytes at:index put:byte |
279 | 159 |
! ! |
160 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
161 |
!Depth1Image methodsFor:'converting'! |
279 | 162 |
|
853 | 163 |
asFormOn:aDevice |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
164 |
"convert a monochrome image to a device form" |
279 | 165 |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
166 |
^ self anyImageAsFormOn:aDevice |
853 | 167 |
! |
168 |
||
169 |
greyImageAsFormOn:aDevice |
|
170 |
"convert a greyscale image to a device form" |
|
171 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
172 |
^ self anyImageAsFormOn:aDevice |
279 | 173 |
! |
174 |
||
175 |
greyImageAsMonoFormOn:aDevice |
|
176 |
"convert to a monochrome form - thats easy" |
|
177 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
178 |
^ self anyImageAsFormOn:aDevice |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
179 |
! |
279 | 180 |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
181 |
paletteImageAsMonoFormOn:aDevice |
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
182 |
"convert a palette image to a b&w monochrome device form" |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
183 |
|
810 | 184 |
|f c0 c1| |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
185 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
186 |
f := Form width:width height:height fromArray:self bits on:aDevice. |
810 | 187 |
c0 := self colorFromValue:0. |
188 |
c1 := self colorFromValue:1. |
|
189 |
c0 brightness > 0.5 ifTrue:[ |
|
190 |
c0 := Color white |
|
191 |
] ifFalse:[ |
|
192 |
c0 := Color black. |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
193 |
]. |
810 | 194 |
c1 brightness > 0.5 ifTrue:[ |
195 |
c1 := Color white |
|
196 |
] ifFalse:[ |
|
197 |
c1 := Color black. |
|
198 |
]. |
|
199 |
f colorMap:(Array with:c0 with:c1). |
|
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
200 |
^ f |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
201 |
|
1655
eec658000092
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1635
diff
changeset
|
202 |
"Modified: 24.4.1997 / 17:51:54 / cg" |
427
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
203 |
! |
746424fba14f
added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents:
337
diff
changeset
|
204 |
|
279 | 205 |
paletteImageAsTrueColorFormOn:aDevice |
206 |
"since all devices must support monochrome images, and |
|
207 |
a 2-entry colormap is implemented by ST/X's drawForm methods, |
|
208 |
we can do this on all color devices as a palette image." |
|
209 |
||
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
210 |
^ self anyImageAsFormOn:aDevice |
810 | 211 |
|
212 |
" |
|
213 |
|i| |
|
214 |
||
215 |
i := Depth1Image |
|
216 |
width:4 |
|
217 |
height:4 |
|
218 |
fromArray:#[ 2r00000000 |
|
219 |
2r11110000 |
|
220 |
2r01010000 |
|
221 |
2r10100000 ]. |
|
222 |
i photometric:#rgb. |
|
223 |
i samplesPerPixel:3. |
|
224 |
i bitsPerSample:#(1 0 0). |
|
225 |
||
226 |
i := i magnifiedBy:30. |
|
227 |
i inspect. |
|
228 |
" |
|
229 |
||
853 | 230 |
"Modified: 14.6.1996 / 15:21:37 / cg" |
81 | 231 |
! ! |
232 |
||
89 | 233 |
!Depth1Image methodsFor:'enumerating'! |
81 | 234 |
|
798 | 235 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1 | 236 |
"perform aBlock for each pixel from x1 to x2 in row y. |
237 |
The block is passed the color at each pixel. |
|
238 |
This method allows slighly faster processing of an |
|
239 |
image than using atX:y:, since some processing can be |
|
240 |
avoided when going from pixel to pixel. However, for |
|
241 |
real image processing, specialized methods should be written." |
|
242 |
||
243 |
|srcIndex "{ Class: SmallInteger }" |
|
244 |
byte "{ Class: SmallInteger }" |
|
245 |
mask "{ Class: SmallInteger }" |
|
246 |
x1 "{ Class: SmallInteger }" |
|
247 |
x2 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
248 |
color0 color1 |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
249 |
bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
250 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
251 |
bytes := self bits. |
1 | 252 |
|
253 |
x1 := xLow. |
|
254 |
x2 := xHigh. |
|
255 |
srcIndex := (self bytesPerRow * y) + 1. |
|
256 |
||
257 |
"left pixel is in high bit" |
|
258 |
||
2226 | 259 |
color0 := self colorFromValue:0. |
260 |
color1 := self colorFromValue:1. |
|
1 | 261 |
|
262 |
srcIndex := srcIndex + (x1 // 8). |
|
12 | 263 |
mask := #[2r10000000 |
798 | 264 |
2r01000000 |
265 |
2r00100000 |
|
266 |
2r00010000 |
|
267 |
2r00001000 |
|
268 |
2r00000100 |
|
269 |
2r00000010 |
|
270 |
2r00000001] at:((x1 \\ 8) + 1). |
|
1 | 271 |
|
798 | 272 |
byte := bytes at:srcIndex. |
1 | 273 |
x1 to:x2 do:[:x | |
798 | 274 |
(byte bitAnd:mask) == 0 ifTrue:[ |
275 |
aBlock value:x value:color0 |
|
276 |
] ifFalse:[ |
|
277 |
aBlock value:x value:color1 |
|
278 |
]. |
|
1 | 279 |
|
798 | 280 |
mask := mask bitShift:-1. |
281 |
mask == 0 ifTrue:[ |
|
282 |
mask := 2r10000000. |
|
283 |
srcIndex := srcIndex + 1. |
|
806 | 284 |
x < x2 ifTrue:[ |
798 | 285 |
byte := bytes at:srcIndex. |
286 |
] |
|
287 |
] |
|
1 | 288 |
] |
798 | 289 |
|
290 |
"Created: 7.6.1996 / 19:12:26 / cg" |
|
810 | 291 |
"Modified: 10.6.1996 / 10:33:06 / cg" |
46 | 292 |
! |
293 |
||
798 | 294 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
279 | 295 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
296 |
The block is passed the color at each pixel. |
|
297 |
This method allows slighly faster processing of an |
|
298 |
image than using atX:y:, since some processing can be |
|
299 |
avoided when going from pixel to pixel. However, for |
|
300 |
real image processing, specialized methods should be written." |
|
1 | 301 |
|
279 | 302 |
|srcIndex "{ Class: SmallInteger }" |
303 |
byte "{ Class: SmallInteger }" |
|
304 |
mask "{ Class: SmallInteger }" |
|
305 |
x1 "{ Class: SmallInteger }" |
|
306 |
x2 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
307 |
bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
308 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
309 |
bytes := self bits. |
82 | 310 |
|
279 | 311 |
"this method needs more tuning, if used heavily |
312 |
(fetch 8 bits at once, unroll the loop over these 8 pixels)" |
|
82 | 313 |
|
279 | 314 |
x1 := xLow. |
315 |
x2 := xHigh. |
|
316 |
srcIndex := (self bytesPerRow * y) + 1. |
|
317 |
||
318 |
"left pixel is in high bit" |
|
82 | 319 |
|
279 | 320 |
srcIndex := srcIndex + (x1 // 8). |
321 |
mask := #[2r10000000 |
|
798 | 322 |
2r01000000 |
323 |
2r00100000 |
|
324 |
2r00010000 |
|
325 |
2r00001000 |
|
326 |
2r00000100 |
|
327 |
2r00000010 |
|
328 |
2r00000001] at:((x1 \\ 8) + 1). |
|
193 | 329 |
|
798 | 330 |
byte := bytes at:srcIndex. |
279 | 331 |
x1 to:x2 do:[:x | |
798 | 332 |
(byte bitAnd:mask) == 0 ifTrue:[ |
333 |
aBlock value:x value:0 |
|
334 |
] ifFalse:[ |
|
335 |
aBlock value:x value:1 |
|
336 |
]. |
|
193 | 337 |
|
798 | 338 |
mask := mask bitShift:-1. |
339 |
mask == 0 ifTrue:[ |
|
340 |
mask := 2r10000000. |
|
341 |
srcIndex := srcIndex + 1. |
|
806 | 342 |
x < x2 ifTrue:[ |
798 | 343 |
byte := bytes at:srcIndex. |
344 |
] |
|
345 |
] |
|
279 | 346 |
] |
798 | 347 |
|
348 |
"Created: 7.6.1996 / 19:09:38 / cg" |
|
806 | 349 |
"Modified: 8.6.1996 / 13:36:37 / cg" |
82 | 350 |
! ! |
351 |
||
1 | 352 |
!Depth1Image methodsFor:'magnification'! |
353 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
354 |
hardMagnifiedBy:scalePoint |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
355 |
"return a new image magnified by scalePoint, aPoint. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
356 |
This is the general magnification method, handling non-integral values. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
357 |
It is slower than the integral magnification method." |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
358 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
359 |
|mX |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
360 |
mY |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
361 |
newWidth "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
362 |
newHeight "{ Class: SmallInteger }" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
363 |
newImage newBits bitsPerPixel newBytesPerRow |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
364 |
newMask |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
365 |
bytes| |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
366 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
367 |
bytes := self bits. |
2988 | 368 |
bytes isNil ifTrue:[ |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
369 |
self error:'cannot magnify image without bits'. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
370 |
^ self |
2988 | 371 |
]. |
372 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
373 |
mX := scalePoint x. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
374 |
mY := scalePoint y. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
375 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
376 |
newWidth := (width * mX) truncated. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
377 |
newHeight := (height * mY) truncated. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
378 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
379 |
bitsPerPixel := self depth. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
380 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
381 |
newBits := ByteArray new:(newBytesPerRow * newHeight). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
382 |
|
1577 | 383 |
mask notNil ifTrue:[ |
384 |
newMask := (mask magnifiedBy:scalePoint) |
|
385 |
]. |
|
386 |
||
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
387 |
newImage := self species new. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
388 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
389 |
newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
390 |
width:newWidth |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
391 |
height:newHeight |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
392 |
photometric:photometric |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
393 |
samplesPerPixel:samplesPerPixel |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
394 |
bitsPerSample:bitsPerSample |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
395 |
colorMap:colorMap copy |
1577 | 396 |
bits:newBits |
397 |
mask:newMask. |
|
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
398 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
399 |
"walk over destination image fetching pixels from source image" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
400 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
401 |
mX := mX asFloat. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
402 |
mY := mY asFloat. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
403 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
404 |
%{ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
405 |
{ |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
406 |
OBJ b1 = bytes; |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
407 |
int _w1 = __intVal(__INST(width)); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
408 |
int _y1, _y2; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
409 |
OBJ b2 = newBits; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
410 |
int _w2 = __intVal(newWidth); |
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
411 |
int _h2 = __intVal(newHeight); |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
412 |
int _x2, _x1; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
413 |
int _idx2; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
414 |
unsigned _byte; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
415 |
double _mY = __floatVal(mY); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
416 |
double _mX = __floatVal(mX); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
417 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
418 |
for (_y2 = 0; _y2 < _h2; _y2++) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
419 |
_y1 = (int)( (double)_y2 / _mY); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
420 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
421 |
for (_x2 = 0; _x2 < _w2; _x2++) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
422 |
_x1 = (int)( (double)_x2 / _mX); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
423 |
|
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1655
diff
changeset
|
424 |
_byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)]; |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
425 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
426 |
if ((_byte & (0x80 >> (_x1 % 8)))) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
427 |
_idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8); |
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1655
diff
changeset
|
428 |
__ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8)); |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
429 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
430 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
431 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
432 |
} |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
433 |
%}. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
434 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
435 |
"/ w := newWidth - 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
436 |
"/ h := newHeight - 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
437 |
"/ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
438 |
"/ 0 to:h do:[:row | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
439 |
"/ dstRow := row. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
440 |
"/ srcRow := (row // mY). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
441 |
"/ 0 to:w do:[:col | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
442 |
"/ |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
443 |
"/ dstCol := col. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
444 |
"/ srcCol := col // mX. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
445 |
"/ value := self valueAtX:(col // mX) y:srcRow. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
446 |
"/ newImage atX:col y:row putValue:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
447 |
"/ ] |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
448 |
"/ ]. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
449 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
450 |
^ newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
451 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
452 |
"((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
453 |
|
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
454 |
"Created: 18.6.1996 / 16:04:26 / cg" |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
455 |
! |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
862
diff
changeset
|
456 |
|
1 | 457 |
magnifyRowFrom:srcBytes offset:srcStart |
2179 | 458 |
into:dstBytes offset:dstStart factor:mX |
1 | 459 |
|
81 | 460 |
"magnify a single pixel row - can only magnify by integer factors. |
461 |
This method has been specially tuned for magnification by 2 and 4." |
|
1 | 462 |
|
463 |
%{ |
|
464 |
unsigned char *srcP, *dstP; |
|
465 |
int _mag; |
|
466 |
REGISTER int i; |
|
467 |
REGISTER unsigned char _byte; |
|
468 |
int _pixels, bpr; |
|
469 |
REGISTER int outcnt, bits, bit, mask, incnt; |
|
470 |
int shift; |
|
471 |
unsigned char byte1, byte2, byte3, byte4; |
|
97 | 472 |
OBJ w = _INST(width); |
1 | 473 |
|
474 |
/* helper for monochrome magnification by 2 */ |
|
475 |
static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f, |
|
2179 | 476 |
0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff}; |
1 | 477 |
|
97 | 478 |
if (__bothSmallInteger(srcStart, dstStart) |
479 |
&& __bothSmallInteger(w, mX) |
|
35 | 480 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
2179 | 481 |
_mag = __intVal(mX); |
482 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
|
483 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
|
484 |
_pixels = __intVal(w); |
|
1 | 485 |
|
2179 | 486 |
switch (_mag) { |
487 |
case 1: |
|
488 |
break; |
|
1 | 489 |
|
2179 | 490 |
case 2: |
491 |
/* tuned for this common case */ |
|
3842 | 492 |
while (_pixels > 4) { |
493 |
_byte = *srcP++; |
|
494 |
*dstP++ = mag1[ _byte >> 4 ]; |
|
495 |
*dstP++ = mag1[ _byte & 0x0F ]; |
|
496 |
_pixels -= 8; |
|
497 |
} |
|
2179 | 498 |
while (_pixels > 0) { |
499 |
_byte = *srcP++; |
|
500 |
*dstP++ = mag1[ _byte >> 4 ]; |
|
501 |
_pixels -= 8; |
|
502 |
} |
|
503 |
break; |
|
1 | 504 |
|
2179 | 505 |
case 4: |
506 |
/* tuned for this common case */ |
|
3842 | 507 |
while (_pixels > 6) { |
508 |
_byte = *srcP++; |
|
509 |
byte1 = mag1[_byte >> 4]; |
|
510 |
byte2 = mag1[byte1 & 0xF]; |
|
511 |
byte1 = mag1[byte1 >> 4]; |
|
512 |
byte3 = mag1[ _byte & 0x0F ]; |
|
513 |
byte4 = mag1[byte3 & 0xF]; |
|
514 |
byte3 = mag1[byte3 >> 4]; |
|
515 |
||
516 |
*dstP++ = byte1; |
|
517 |
*dstP++ = byte2; |
|
518 |
*dstP++ = byte3; |
|
519 |
*dstP++ = byte4; |
|
520 |
_pixels -= 8; |
|
521 |
} |
|
2179 | 522 |
while (_pixels > 0) { |
523 |
_byte = *srcP++; |
|
524 |
byte1 = mag1[_byte >> 4]; |
|
525 |
byte2 = mag1[byte1 & 0xF]; |
|
526 |
byte1 = mag1[byte1 >> 4]; |
|
3842 | 527 |
byte3 = mag1[_byte & 0x0F ]; |
2179 | 528 |
byte4 = mag1[byte3 & 0xF]; |
529 |
byte3 = mag1[byte3 >> 4]; |
|
1 | 530 |
|
2179 | 531 |
*dstP++ = byte1; |
532 |
if (_pixels > 2) { |
|
533 |
*dstP++ = byte2; |
|
534 |
if (_pixels > 4) { |
|
535 |
*dstP++ = byte3; |
|
536 |
if (_pixels > 6) { |
|
537 |
*dstP++ = byte4; |
|
538 |
} |
|
539 |
} |
|
540 |
} |
|
541 |
_pixels -= 8; |
|
542 |
} |
|
543 |
break; |
|
1 | 544 |
|
2179 | 545 |
default: |
546 |
bits = 0, incnt = 0, outcnt = 0; |
|
547 |
mask = 0x80; |
|
548 |
_byte = *srcP++; |
|
549 |
while (_pixels--) { |
|
550 |
if (_byte & mask) |
|
551 |
bit = 1; |
|
552 |
else |
|
553 |
bit = 0; |
|
554 |
incnt++; |
|
555 |
if (incnt == 8) { |
|
556 |
incnt = 0; |
|
557 |
mask = 0x80; |
|
558 |
_byte = *srcP++; |
|
559 |
} else { |
|
560 |
mask >>= 1; |
|
561 |
} |
|
1 | 562 |
|
2179 | 563 |
for (i=_mag; i>0; i--) { |
564 |
bits = (bits << 1) | bit; |
|
565 |
outcnt++; |
|
566 |
if (outcnt == 8) { |
|
567 |
*dstP++ = bits; |
|
568 |
bits = 0; |
|
569 |
outcnt = 0; |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
if (outcnt) { |
|
574 |
*dstP = bits << (8-outcnt); |
|
575 |
} |
|
576 |
break; |
|
577 |
} |
|
578 |
RETURN (self); |
|
1 | 579 |
} |
81 | 580 |
%}. |
3842 | 581 |
super |
582 |
magnifyRowFrom:srcBytes offset:srcStart |
|
583 |
into:dstBytes offset:dstStart factor:mX |
|
1 | 584 |
! ! |
279 | 585 |
|
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
586 |
!Depth1Image methodsFor:'private'! |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
587 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
588 |
anyImageAsFormOn:aDevice |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
589 |
"convert a monochrome image to a device form" |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
590 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
591 |
|f color0 color1| |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
592 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
593 |
((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm]. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
594 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
595 |
color0 := (self colorFromValue:0) exactOn:aDevice. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
596 |
color1 := (self colorFromValue:1) exactOn:aDevice. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
597 |
(color0 notNil and:[(color0 isOnDevice:aDevice) |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
598 |
and:[color1 notNil and:[color1 isOnDevice:aDevice]]]) ifFalse:[ |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
599 |
"could not allocate colors, do it the hard way ..." |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
600 |
^ self paletteImageAsFormOn:aDevice. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
601 |
]. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
602 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
603 |
"all colors are available, this is easy now" |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
604 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
605 |
f := Form width:width height:height fromArray:self bits on:aDevice. |
3599
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
606 |
f notNil ifTrue:[ |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
607 |
f colorMap:(Array with:color0 with:color1). |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
608 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
609 |
"/ remember deviceForm |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
610 |
|
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
611 |
(device isNil or:[deviceForm isNil]) ifTrue:[ |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
612 |
device := aDevice. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
613 |
deviceForm := f. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
614 |
maskedPixelsAre0 := nil. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
615 |
] |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
616 |
]. |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
617 |
^ f |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
618 |
! ! |
bb5474dfa1c8
Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents:
3569
diff
changeset
|
619 |
|
279 | 620 |
!Depth1Image methodsFor:'queries'! |
621 |
||
622 |
bitsPerPixel |
|
623 |
"return the number of bits per pixel" |
|
624 |
||
625 |
^ 1 |
|
626 |
! |
|
627 |
||
628 |
bitsPerRow |
|
629 |
"return the number of bits in one scanline of the image" |
|
630 |
||
631 |
^ width |
|
632 |
! |
|
633 |
||
634 |
bytesPerRow |
|
635 |
"return the number of bytes in one scanline of the image" |
|
636 |
||
637 |
|nbytes| |
|
638 |
||
639 |
nbytes := width // 8. |
|
640 |
((width \\ 8) ~~ 0) ifTrue:[ |
|
641 |
^ nbytes + 1 |
|
642 |
]. |
|
643 |
^ nbytes |
|
644 |
! |
|
645 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
646 |
colorFromValue:colorValue |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
647 |
"given a pixel value, return the corresponding color. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
648 |
Pixel values start with 0." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
649 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
650 |
photometric == #blackIs0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
651 |
(colorValue == 0) ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
652 |
^ Color black |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
653 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
654 |
^ Color white |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
655 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
656 |
photometric == #whiteIs0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
657 |
(colorValue == 0) ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
658 |
^ Color white |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
659 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
660 |
^ Color black |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
661 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
662 |
photometric == #palette ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
663 |
^ colorMap at:(colorValue+1). |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
664 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
665 |
^ super colorFromValue:colorValue. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
666 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
667 |
|
279 | 668 |
usedColors |
669 |
"return a collection of colors used in the receiver. |
|
2201 | 670 |
For depth1 images, we return the colorMap here, assuming all |
671 |
pixels are used ... |
|
672 |
... which is not really true - it could be all-white or all-black" |
|
279 | 673 |
|
3867 | 674 |
(photometric == #whiteIs0 or:[photometric == #blackIs0]) ifTrue:[ |
675 |
^ Array |
|
676 |
with:(Color black) |
|
677 |
with:(Color white). |
|
279 | 678 |
]. |
3867 | 679 |
photometric == #palette ifTrue:[ |
680 |
^ colorMap |
|
681 |
]. |
|
682 |
^ super usedColors |
|
279 | 683 |
|
684 |
" |
|
685 |
(Image fromFile:'bitmaps/garfield.gif') usedColors |
|
686 |
(Image fromFile:'bitmaps/SBrowser.xbm') usedColors |
|
687 |
" |
|
2201 | 688 |
|
689 |
"Modified: / 28.7.1998 / 22:21:29 / cg" |
|
279 | 690 |
! |
691 |
||
692 |
usedValues |
|
693 |
"return a collection of color values used in the receiver. |
|
3274 | 694 |
For depth1 images, we assume both 1- and 0-pixels are present ... |
2201 | 695 |
... which is not really true - it could be all-white or all-black" |
279 | 696 |
|
697 |
^ #(0 1) |
|
2201 | 698 |
|
699 |
"Modified: / 28.7.1998 / 22:22:43 / cg" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
700 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
701 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
702 |
valueFromColor:aColor |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
703 |
"given a color, return the corresponding pixel value. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
704 |
Non-representable colors return nil." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
705 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
706 |
|clr0 clr1| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
707 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
708 |
photometric == #whiteIs0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
709 |
clr0 := Color white. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
710 |
clr1 := Color black. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
711 |
] ifFalse:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
712 |
photometric == #blackIs0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
713 |
clr0 := Color black. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
714 |
clr1 := Color white. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
715 |
] ifFalse:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
716 |
photometric ~~ #palette ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
717 |
^ super valueFromColor:aColor |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
718 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
719 |
clr0 := colorMap at:1. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
720 |
clr1 := colorMap at:2 ifAbsent:nil. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
721 |
] |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
722 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
723 |
aColor = clr0 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
724 |
^ 0. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
725 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
726 |
aColor = clr1 ifTrue:[ |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
727 |
^ 1 |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
728 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
729 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
730 |
" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
731 |
the color is not in the images colormap |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
732 |
" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
733 |
^ nil |
279 | 734 |
! ! |
735 |
||
736 |
!Depth1Image class methodsFor:'documentation'! |
|
737 |
||
738 |
version |
|
3867 | 739 |
^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.50 2003-04-29 18:49:14 cg Exp $' |
279 | 740 |
! ! |