author | tz |
Thu, 23 Jul 1998 16:30:28 +0200 | |
changeset 2178 | 3b151fc7450e |
parent 2044 | 9ea84b4ba249 |
child 2200 | 4e3c5b30b2c1 |
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 |
|
13 |
Image subclass:#Depth2Image |
|
579 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Images' |
|
1 | 18 |
! |
19 |
||
46 | 20 |
!Depth2Image class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 25 |
All Rights Reserved |
3 | 26 |
|
46 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
3 | 35 |
|
46 | 36 |
documentation |
37 |
" |
|
38 |
this class represents four-color (2 bit / pixel) images |
|
39 |
(as used mainly on the NeXT). |
|
40 |
It mainly consists of methods already implemented in Image, |
|
41 |
reimplemented here for more performance. |
|
611 | 42 |
|
798 | 43 |
#blackIs0 / #whiteIs0 and #palette formats are supported here. |
44 |
||
611 | 45 |
[author:] |
46 |
Claus Gittinger |
|
47 |
||
48 |
[see also:] |
|
49 |
Depth1Image Depth4Image Depth8Image Depth16Image Depth24Image |
|
50 |
ImageReader |
|
46 | 51 |
" |
52 |
! ! |
|
3 | 53 |
|
89 | 54 |
!Depth2Image class methodsFor:'queries'! |
55 |
||
56 |
imageDepth |
|
579 | 57 |
"return the depth of images represented by instances of |
58 |
this class - here we return 2" |
|
59 |
||
89 | 60 |
^ 2 |
579 | 61 |
|
62 |
"Modified: 20.4.1996 / 23:40:12 / cg" |
|
89 | 63 |
! ! |
64 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
65 |
!Depth2Image methodsFor:'accessing - pixels'! |
1 | 66 |
|
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
67 |
colorAtX:x y:y |
1 | 68 |
"retrieve a pixel at x/y; return a color. |
69 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
70 |
x = width-1, y=height-1 for lower right pixel" |
|
71 |
||
38 | 72 |
|lineIndex "{ Class: SmallInteger }" |
73 |
byte "{ Class: SmallInteger }" |
|
74 |
shift "{ Class: SmallInteger }" |
|
89 | 75 |
value "{ Class: SmallInteger }" |
154 | 76 |
p grey| |
1 | 77 |
|
78 |
lineIndex := (self bytesPerRow * y) + 1. |
|
79 |
||
80 |
"left pixel in high bits" |
|
81 |
byte := bytes at:(lineIndex + (x // 4)). |
|
154 | 82 |
|
1 | 83 |
shift := #(-6 -4 -2 0) at:((x \\ 4) + 1). |
84 |
value := (byte bitShift:shift) bitAnd:3. |
|
89 | 85 |
p := photometric. |
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
86 |
|
89 | 87 |
p == #whiteIs0 ifTrue:[ |
746 | 88 |
value := 3 - value. |
89 |
p := #blackIs0 |
|
1 | 90 |
]. |
154 | 91 |
p == #blackIs0 ifTrue:[ |
746 | 92 |
(value == 0) ifTrue:[ |
93 |
^ Color black |
|
94 |
]. |
|
95 |
(value == 3) ifTrue:[ |
|
96 |
^ Color white |
|
97 |
]. |
|
98 |
(value == 1) ifTrue:[ |
|
99 |
grey := 33 |
|
100 |
] ifFalse:[ |
|
101 |
grey := 67 |
|
102 |
]. |
|
103 |
^ Color gray:grey |
|
1 | 104 |
]. |
105 |
photometric ~~ #palette ifTrue:[ |
|
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
106 |
^ self colorFromValue:value |
1 | 107 |
]. |
89 | 108 |
^ colorMap at:(value+1). |
746 | 109 |
|
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
110 |
"Modified: 8.6.1996 / 10:52:38 / cg" |
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
111 |
"Created: 24.4.1997 / 17:33:41 / cg" |
1 | 112 |
! |
113 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
114 |
pixelAtX:x y:y |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
115 |
"retrieve a pixel at x/y; return a pixel value. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
116 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
117 |
x = width-1, y=height-1 for lower right pixel" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
118 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
119 |
|lineIndex "{ Class: SmallInteger }" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
120 |
byte "{ Class: SmallInteger }" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
121 |
shift "{ Class: SmallInteger }" | |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
122 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
123 |
lineIndex := (self bytesPerRow * y) + 1. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
124 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
125 |
"left pixel in high bits" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
126 |
byte := bytes at:(lineIndex + (x // 4)). |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
127 |
shift := #(-6 -4 -2 0) at:((x \\ 4) + 1). |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
128 |
^ (byte bitShift:shift) bitAnd:3. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
129 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
130 |
"Created: 24.4.1997 / 16:06:39 / cg" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
131 |
! |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
132 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
133 |
pixelAtX:x y:y put:aPixelValue |
1 | 134 |
"set the pixel at x/y to aPixelValue. |
135 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
136 |
x = width-1, y=height-1 for lower right pixel" |
|
137 |
||
38 | 138 |
|lineIndex "{ Class: SmallInteger }" |
139 |
index "{ Class: SmallInteger }" |
|
140 |
byte "{ Class: SmallInteger }" |
|
141 |
shift "{ Class: SmallInteger }" | |
|
1 | 142 |
|
143 |
lineIndex := (self bytesPerRow * y) + 1. |
|
144 |
||
145 |
"left pixel is in high bits" |
|
146 |
index := lineIndex + (x // 4). |
|
147 |
byte := bytes at:index. |
|
148 |
shift := #(6 4 2 0) at:((x \\ 4) + 1). |
|
149 |
byte := (byte bitAnd:(3 bitShift:shift) bitInvert) bitOr:(aPixelValue bitShift:shift). |
|
150 |
bytes at:index put:byte |
|
151 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
152 |
"Created: 24.4.1997 / 17:06:36 / cg" |
1 | 153 |
! ! |
154 |
||
810 | 155 |
!Depth2Image methodsFor:'dither helpers'! |
798 | 156 |
|
157 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
|
158 |
"return the dithered monochrome bits for the receiver image; |
|
159 |
with a constant ditherMatrix, this can be used for thresholding. |
|
160 |
Redefined to make use of knowing that pixels are 2-bit values." |
|
161 |
||
162 |
|f dH nDither |
|
163 |
greyMap monoBits |
|
164 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
165 |
bytesPerRow "{Class: SmallInteger }" |
|
166 |
w "{Class: SmallInteger }" |
|
167 |
h "{Class: SmallInteger }"| |
|
168 |
||
169 |
nDither := ditherMatrix size. |
|
170 |
dH := nDither / dW. |
|
171 |
||
172 |
w := width. |
|
173 |
h := height. |
|
174 |
||
175 |
bytesPerRow := self bytesPerRow. |
|
176 |
||
177 |
bytesPerMonoRow := w + 7 // 8. |
|
178 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
179 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
180 |
^ nil |
|
181 |
]. |
|
182 |
||
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
183 |
greyMap := self greyByteMapForRange:nDither. |
798 | 184 |
|
185 |
%{ |
|
186 |
int __dW = __intVal(dW); |
|
187 |
int __dH = __intVal(dH); |
|
188 |
int __byte; |
|
189 |
int __dT; |
|
190 |
int __dstIdx = 0; |
|
191 |
int __srcIdx = 0; |
|
192 |
int __bitCnt; |
|
193 |
int __inByte; |
|
194 |
int __grey; |
|
195 |
int __w = __intVal(w); |
|
196 |
int __h = __intVal(h); |
|
197 |
int __x; |
|
198 |
int __y; |
|
199 |
int __oX, __oY, __dY; |
|
200 |
int __nextDst; |
|
201 |
int __nextSrc; |
|
202 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
203 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
204 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1656
diff
changeset
|
205 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
808 | 206 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
798 | 207 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
208 |
unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
|
209 |
||
210 |
__oY = __dY = 0; |
|
211 |
for (__y=0; __y<__h; __y++) { |
|
212 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
|
213 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
214 |
||
215 |
__byte = 0; |
|
216 |
__bitCnt = 8; |
|
217 |
||
218 |
__oX = 0; |
|
219 |
||
220 |
for (__x=0; __x<__w; __x++) { |
|
221 |
if ((__x & 3) == 0) { |
|
222 |
__inByte = __bytes[__srcIdx]; /* 0..255 */ |
|
223 |
__srcIdx++; |
|
224 |
} else { |
|
225 |
__inByte = __inByte << 2; |
|
226 |
} |
|
227 |
__grey = (__inByte >> 6) & 3; |
|
228 |
||
229 |
__grey = __greyMap[__grey]; |
|
230 |
__dT = __ditherMatrix[__dY + __oX]; |
|
231 |
||
232 |
__oX++; |
|
233 |
if (__oX == __dW) __oX = 0; |
|
234 |
||
235 |
__byte = __byte << 1; |
|
236 |
if (__grey > __dT) { |
|
237 |
__byte = __byte | 1; /* white */ |
|
238 |
} |
|
239 |
||
240 |
__bitCnt--; |
|
241 |
if (__bitCnt == 0) { |
|
242 |
__monoBits[__dstIdx] = __byte; |
|
243 |
__dstIdx++; |
|
244 |
__byte = 0; |
|
245 |
__bitCnt = 8; |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
if (__bitCnt != 8) { |
|
250 |
__byte = __byte << __bitCnt; |
|
251 |
__monoBits[__dstIdx] = __byte; |
|
252 |
} |
|
253 |
||
254 |
__oY++; __dY += __dW; |
|
255 |
if (__oY == __dH) { |
|
256 |
__oY = 0; |
|
257 |
__dY = 0; |
|
258 |
} |
|
259 |
||
260 |
__srcIdx = __nextSrc; |
|
261 |
__dstIdx = __nextDst; |
|
262 |
} |
|
263 |
%}. |
|
264 |
||
265 |
^ monoBits |
|
266 |
||
267 |
||
268 |
! ! |
|
269 |
||
280 | 270 |
!Depth2Image methodsFor:'enumerating'! |
271 |
||
798 | 272 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
280 | 273 |
"perform aBlock for each pixel from x1 to x2 in row y. |
274 |
The block is passed the color at each pixel. |
|
275 |
This method allows slighly faster processing of an |
|
276 |
image than using atX:y:, since some processing can be |
|
277 |
avoided when going from pixel to pixel. However, for |
|
278 |
real image processing, specialized methods should be written." |
|
279 |
||
280 |
|srcIndex "{ Class: SmallInteger }" |
|
281 |
byte "{ Class: SmallInteger }" |
|
282 |
shift "{ Class: SmallInteger }" |
|
283 |
value "{ Class: SmallInteger }" |
|
284 |
x1 "{ Class: SmallInteger }" |
|
285 |
x2 "{ Class: SmallInteger }" |
|
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
286 |
color0 color1 color2 color3| |
280 | 287 |
|
288 |
photometric == #whiteIs0 ifTrue:[ |
|
746 | 289 |
color0 := Color white. |
290 |
color1 := Color gray:67. |
|
291 |
color2 := Color gray:33. |
|
292 |
color3 := Color black |
|
280 | 293 |
] ifFalse:[ |
746 | 294 |
photometric == #blackIs0 ifTrue:[ |
295 |
color0 := Color black. |
|
296 |
color1 := Color gray:33. |
|
297 |
color2 := Color gray:67. |
|
298 |
color3 := Color white |
|
299 |
] ifFalse:[ |
|
300 |
photometric == #palette ifTrue:[ |
|
301 |
color0 := colorMap at:1. |
|
302 |
color1 := colorMap at:2. |
|
303 |
color2 := colorMap at:3. |
|
304 |
color3 := colorMap at:4. |
|
305 |
] ifFalse:[ |
|
810 | 306 |
color0 := self colorFromValue:0. |
307 |
color1 := self colorFromValue:1. |
|
308 |
color2 := self colorFromValue:2. |
|
309 |
color3 := self colorFromValue:3. |
|
746 | 310 |
] |
311 |
] |
|
280 | 312 |
]. |
313 |
||
314 |
"left pixel in high bits" |
|
315 |
||
316 |
x1 := xLow. |
|
317 |
x2 := xHigh. |
|
318 |
||
319 |
srcIndex := (self bytesPerRow * y) + 1. |
|
320 |
srcIndex := srcIndex + (x1 // 4). |
|
321 |
shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1). |
|
322 |
||
798 | 323 |
byte := bytes at:srcIndex. |
280 | 324 |
x1 to:x2 do:[:x | |
746 | 325 |
value := (byte bitShift:shift) bitAnd:3. |
280 | 326 |
|
746 | 327 |
(value == 0) ifTrue:[ |
798 | 328 |
aBlock value:x value:color0 |
746 | 329 |
] ifFalse:[ |
330 |
(value == 1) ifTrue:[ |
|
798 | 331 |
aBlock value:x value:color1 |
746 | 332 |
] ifFalse:[ |
333 |
(value == 2) ifTrue:[ |
|
798 | 334 |
aBlock value:x value:color2 |
746 | 335 |
] ifFalse:[ |
798 | 336 |
aBlock value:x value:color3 |
746 | 337 |
] |
338 |
] |
|
339 |
]. |
|
280 | 340 |
|
746 | 341 |
shift == 0 ifTrue:[ |
342 |
shift := -6. |
|
798 | 343 |
srcIndex := srcIndex + 1. |
806 | 344 |
x < x2 ifTrue:[ |
798 | 345 |
byte := bytes at:srcIndex. |
346 |
] |
|
746 | 347 |
] ifFalse:[ |
348 |
shift := shift + 2. |
|
349 |
] |
|
280 | 350 |
]. |
746 | 351 |
|
798 | 352 |
"Created: 7.6.1996 / 19:12:31 / cg" |
810 | 353 |
"Modified: 10.6.1996 / 10:32:47 / cg" |
280 | 354 |
! |
355 |
||
798 | 356 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
280 | 357 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
358 |
The block is passed the x coordinate and the pixelValue at each pixel. |
|
359 |
This method allows slighly faster processing of an |
|
360 |
image than using valueAtX:y:, since some processing can be |
|
361 |
avoided when going from pixel to pixel. However, for |
|
362 |
real image processing, specialized methods should be written." |
|
363 |
||
364 |
|srcIndex "{ Class: SmallInteger }" |
|
365 |
byte "{ Class: SmallInteger }" |
|
366 |
shift "{ Class: SmallInteger }" |
|
367 |
value "{ Class: SmallInteger }" |
|
368 |
x1 "{ Class: SmallInteger }" |
|
369 |
x2 "{ Class: SmallInteger }"| |
|
370 |
||
371 |
"left pixel in high bits" |
|
372 |
||
373 |
x1 := xLow. |
|
374 |
x2 := xHigh. |
|
375 |
||
376 |
srcIndex := (self bytesPerRow * y) + 1. |
|
377 |
srcIndex := srcIndex + (x1 // 4). |
|
378 |
shift := #(-6 -4 -2 0) at:((x1 \\ 4) + 1). |
|
379 |
||
798 | 380 |
byte := bytes at:srcIndex. |
280 | 381 |
x1 to:x2 do:[:x | |
798 | 382 |
value := (byte bitShift:shift) bitAnd:3. |
280 | 383 |
|
798 | 384 |
aBlock value:x value:value. |
280 | 385 |
|
798 | 386 |
shift == 0 ifTrue:[ |
387 |
shift := -6. |
|
388 |
srcIndex := srcIndex + 1. |
|
806 | 389 |
x < x2 ifTrue:[ |
798 | 390 |
byte := bytes at:srcIndex. |
391 |
] |
|
392 |
] ifFalse:[ |
|
393 |
shift := shift + 2. |
|
394 |
] |
|
280 | 395 |
]. |
798 | 396 |
|
397 |
"Created: 7.6.1996 / 19:09:42 / cg" |
|
806 | 398 |
"Modified: 8.6.1996 / 13:36:28 / cg" |
280 | 399 |
! ! |
400 |
||
1 | 401 |
!Depth2Image methodsFor:'magnification'! |
402 |
||
403 |
magnifyRowFrom:srcBytes offset:srcStart |
|
2178 | 404 |
into:dstBytes offset:dstStart factor:mX |
1 | 405 |
|
406 |
"magnify a single pixel row - can only magnify by integer factors" |
|
407 |
||
408 |
%{ |
|
409 |
unsigned char *srcP, *dstP; |
|
410 |
int _mag; |
|
411 |
REGISTER int i; |
|
412 |
REGISTER unsigned char _byte; |
|
413 |
int _pixels; |
|
414 |
REGISTER int outcnt, bits, bit, mask, incnt; |
|
415 |
int shift; |
|
97 | 416 |
OBJ w = _INST(width); |
1 | 417 |
|
2178 | 418 |
/* helper for two-plane magnification by 2 |
419 |
* 0000 -> 0000 0000 |
|
420 |
* 0001 -> 0000 0101 |
|
421 |
* ... |
|
422 |
* 1111 -> 1111 1111 |
|
423 |
*/ |
|
1 | 424 |
static unsigned char mag2[16] = {0x00, 0x05, 0x0a, 0x0f, 0x50, 0x55, 0x5a, 0x5f, |
2178 | 425 |
0xa0, 0xa5, 0xaa, 0xaf, 0xf0, 0xf5, 0xfa, 0xff}; |
426 |
/* helper for two-plane magnification by 4 */ |
|
427 |
static unsigned char mag4[16] = {0x00, 0x55, 0xaa, 0xff}; |
|
1 | 428 |
|
97 | 429 |
if (__bothSmallInteger(srcStart, dstStart) |
430 |
&& __bothSmallInteger(w, mX) |
|
35 | 431 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
2178 | 432 |
_mag = __intVal(mX); |
433 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
|
434 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
|
435 |
_pixels = __intVal(w); |
|
436 |
||
437 |
switch (_mag) { |
|
438 |
case 1: |
|
439 |
break; |
|
1 | 440 |
|
2178 | 441 |
case 2: |
442 |
/* tuned for this common case */ |
|
443 |
while (_pixels > 0) { |
|
444 |
_byte = *srcP++; |
|
445 |
*dstP++ = mag2[ _byte >> 4 ]; |
|
446 |
if (_pixels > 2) { |
|
447 |
*dstP++ = mag2[ _byte & 0x0F ]; |
|
448 |
} |
|
449 |
_pixels -= 4; |
|
450 |
} |
|
451 |
break; |
|
1 | 452 |
|
2178 | 453 |
case3: |
454 |
/* tuned for this common case */ |
|
455 |
bits = 0, incnt = 0, outcnt = 0; |
|
456 |
shift = 6; |
|
457 |
_byte = *srcP++; |
|
458 |
while (_pixels--) { |
|
459 |
bit = (_byte >> shift) & 3; |
|
460 |
incnt++; |
|
461 |
if (incnt == 4) { |
|
462 |
incnt = 0; |
|
463 |
shift = 6; |
|
464 |
_byte = *srcP++; |
|
465 |
} else { |
|
466 |
shift -= 2; |
|
467 |
} |
|
468 |
||
469 |
switch (outcnt) { |
|
470 |
case 0: |
|
471 |
/* next three pixels */ |
|
472 |
bits = (((bit << 2) | bit) << 2) | bit; |
|
473 |
outcnt = 3; |
|
474 |
break; |
|
475 |
||
476 |
case 1: |
|
477 |
/* next three pixels & store */ |
|
478 |
bits = (((((bits << 2) | bit) << 2) | bit) << 2) | bit; |
|
479 |
*dstP++ = bits; |
|
480 |
outcnt = 0; |
|
481 |
break; |
|
482 |
||
483 |
case 2: |
|
484 |
/* next two pixels & store */ |
|
485 |
bits = (((bits << 2) | bit) << 2) | bit; |
|
486 |
*dstP++ = bits; |
|
487 |
bits = bit; |
|
488 |
outcnt = 1; |
|
489 |
break; |
|
1 | 490 |
|
2178 | 491 |
case 3: |
492 |
/* next pixel & store */ |
|
493 |
bits = (bits << 2) | bit; |
|
494 |
*dstP++ = bits; |
|
495 |
bits = (bit << 2) | bit; |
|
496 |
outcnt = 2; |
|
497 |
break; |
|
498 |
} |
|
499 |
} |
|
500 |
if (outcnt) { |
|
501 |
*dstP = bits << ((4-outcnt)*2); |
|
502 |
} |
|
503 |
break; |
|
504 |
||
505 |
case 4: |
|
506 |
/* tuned for this common case */ |
|
507 |
incnt = 0; |
|
508 |
shift = 6; |
|
509 |
_byte = *srcP++; |
|
510 |
while (_pixels--) { |
|
511 |
bit = (_byte >> shift) & 3; |
|
512 |
incnt++; |
|
513 |
if (incnt == 4) { |
|
514 |
incnt = 0; |
|
515 |
shift = 6; |
|
516 |
_byte = *srcP++; |
|
517 |
} else { |
|
518 |
shift -= 2; |
|
519 |
} |
|
520 |
*dstP++ = mag4[bit]; |
|
521 |
} |
|
522 |
break; |
|
1 | 523 |
|
2178 | 524 |
default: |
525 |
bits = 0, incnt = 0, outcnt = 0; |
|
526 |
shift = 6; |
|
527 |
_byte = *srcP++; |
|
528 |
while (_pixels--) { |
|
529 |
bit = (_byte >> shift) & 3; |
|
530 |
incnt++; |
|
531 |
if (incnt == 4) { |
|
532 |
incnt = 0; |
|
533 |
shift = 6; |
|
534 |
_byte = *srcP++; |
|
535 |
} else { |
|
536 |
shift -= 2; |
|
537 |
} |
|
1 | 538 |
|
2178 | 539 |
for (i=_mag; i>0; i--) { |
540 |
bits = (bits << 2) | bit; |
|
541 |
outcnt++; |
|
542 |
if (outcnt == 4) { |
|
543 |
*dstP++ = bits; |
|
544 |
bits = 0; |
|
545 |
outcnt = 0; |
|
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
if (outcnt) { |
|
550 |
*dstP = bits << ((4-outcnt)*2); |
|
551 |
} |
|
552 |
break; |
|
553 |
||
554 |
} |
|
555 |
RETURN (self); |
|
1 | 556 |
} |
557 |
%} |
|
558 |
. |
|
559 |
self primitiveFailed |
|
560 |
! ! |
|
280 | 561 |
|
562 |
!Depth2Image methodsFor:'queries'! |
|
563 |
||
564 |
bitsPerPixel |
|
565 |
"return the number of bits per pixel" |
|
566 |
||
567 |
^ 2 |
|
568 |
! |
|
569 |
||
570 |
bitsPerRow |
|
571 |
"return the number of bits in one scanline of the image" |
|
572 |
||
573 |
^ width * 2 |
|
574 |
! |
|
575 |
||
576 |
bytesPerRow |
|
577 |
"return the number of bytes in one scanline of the image" |
|
578 |
||
579 |
|nbytes| |
|
580 |
||
581 |
nbytes := width // 4. |
|
582 |
((width \\ 4) ~~ 0) ifTrue:[ |
|
583 |
^ nbytes + 1 |
|
584 |
]. |
|
585 |
^ nbytes |
|
586 |
! |
|
587 |
||
588 |
usedColors |
|
589 |
"return a collection of colors used in the receiver. |
|
590 |
For depth1 images, this is very easy" |
|
591 |
||
592 |
photometric ~~ #palette ifTrue:[ |
|
746 | 593 |
^ Array with:Color black |
594 |
with:(Color gray:33) |
|
595 |
with:(Color gray:67) |
|
596 |
with:Color black. |
|
280 | 597 |
]. |
598 |
^ colorMap |
|
746 | 599 |
|
600 |
"Modified: 28.5.1996 / 20:54:24 / cg" |
|
280 | 601 |
! |
602 |
||
603 |
usedValues |
|
604 |
"return a collection of color values used in the receiver." |
|
605 |
||
606 |
"actually, this is wrong - we have to look if those are |
|
607 |
really used. However, assume that we dont care for |
|
608 |
those extra colors here ..." |
|
609 |
||
610 |
^ #(0 1 2 3) |
|
611 |
! ! |
|
612 |
||
613 |
!Depth2Image class methodsFor:'documentation'! |
|
614 |
||
615 |
version |
|
2178 | 616 |
^ '$Header: /cvs/stx/stx/libview/Depth2Image.st,v 1.29 1998-07-23 14:30:28 tz Exp $' |
280 | 617 |
! ! |