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