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