changeset 6066 | 62426e8110ae |
parent 5475 | e6469c3d8a46 |
child 6298 | c2980b510cf1 |
6065:75ff98ae918d | 6066:62426e8110ae |
---|---|
40 Most images coming from the windows world are represented as Depth4Images. |
40 Most images coming from the windows world are represented as Depth4Images. |
41 It mainly consists of methods already implemented in Image, |
41 It mainly consists of methods already implemented in Image, |
42 reimplemented here for more performance. |
42 reimplemented here for more performance. |
43 |
43 |
44 [author:] |
44 [author:] |
45 Claus Gittinger |
45 Claus Gittinger |
46 |
46 |
47 [see also:] |
47 [see also:] |
48 Depth1Image Depth2Image Depth8Image Depth16Image Depth24Image |
48 Depth1Image Depth2Image Depth8Image Depth16Image Depth24Image |
49 ImageReader |
49 ImageReader |
50 " |
50 " |
51 ! ! |
51 ! ! |
52 |
52 |
53 !Depth4Image class methodsFor:'queries'! |
53 !Depth4Image class methodsFor:'queries'! |
54 |
54 |
83 lineIndex := (self bytesPerRow * y) + 1. |
83 lineIndex := (self bytesPerRow * y) + 1. |
84 byteIndex := lineIndex + (x // 2). |
84 byteIndex := lineIndex + (x // 2). |
85 |
85 |
86 "left pixel in high bits" |
86 "left pixel in high bits" |
87 byteIndex > bytes size ifTrue:[ |
87 byteIndex > bytes size ifTrue:[ |
88 ^ 0 |
88 ^ 0 |
89 ]. |
89 ]. |
90 byte := bytes at:byteIndex. |
90 byte := bytes at:byteIndex. |
91 x even ifTrue:[ |
91 x even ifTrue:[ |
92 ^ (byte bitShift:-4) bitAnd:16rF. |
92 ^ (byte bitShift:-4) bitAnd:16rF. |
93 ]. |
93 ]. |
94 ^ byte bitAnd:16rF. |
94 ^ byte bitAnd:16rF. |
95 |
95 |
96 "Created: 24.4.1997 / 16:06:43 / cg" |
96 "Created: 24.4.1997 / 16:06:43 / cg" |
97 ! |
97 ! |
109 |
109 |
110 "left pixel is in high bits" |
110 "left pixel is in high bits" |
111 index := lineIndex + (x // 2). |
111 index := lineIndex + (x // 2). |
112 byte := bytes at:index. |
112 byte := bytes at:index. |
113 x even ifTrue:[ |
113 x even ifTrue:[ |
114 byte := (byte bitAnd:16rF) bitOr:(aPixelValue bitShift:4) |
114 byte := (byte bitAnd:16rF) bitOr:(aPixelValue bitShift:4) |
115 ] ifFalse:[ |
115 ] ifFalse:[ |
116 byte := (byte bitAnd:16rF0) bitOr:aPixelValue |
116 byte := (byte bitAnd:16rF0) bitOr:aPixelValue |
117 ]. |
117 ]. |
118 bytes at:index put:byte |
118 bytes at:index put:byte |
119 |
119 |
120 "Created: 24.4.1997 / 17:06:39 / cg" |
120 "Created: 24.4.1997 / 17:06:39 / cg" |
121 ! |
121 ! |
123 rowAt:y into:aPixelBuffer |
123 rowAt:y into:aPixelBuffer |
124 "fill aBuffer with pixel values retrieved from a single row. |
124 "fill aBuffer with pixel values retrieved from a single row. |
125 Notice: row coordinate starts with 0." |
125 Notice: row coordinate starts with 0." |
126 |
126 |
127 |lineIndex "{ Class: SmallInteger }" |
127 |lineIndex "{ Class: SmallInteger }" |
128 byte "{ Class: SmallInteger }" |
128 byte "{ Class: SmallInteger }" |
129 w "{ Class: SmallInteger }" |
129 w "{ Class: SmallInteger }" |
130 pixel dstIdx bytes| |
130 pixel dstIdx bytes| |
131 |
131 |
132 bytes := self bits. |
132 bytes := self bits. |
133 dstIdx := 1. |
133 dstIdx := 1. |
134 w := width - 1. |
134 w := width - 1. |
135 lineIndex := (self bytesPerRow * y). |
135 lineIndex := (self bytesPerRow * y). |
136 0 to:w do:[:x | |
136 0 to:w do:[:x | |
137 x even ifTrue:[ |
137 x even ifTrue:[ |
138 lineIndex := lineIndex + 1. |
138 lineIndex := lineIndex + 1. |
139 byte := bytes at:lineIndex. |
139 byte := bytes at:lineIndex. |
140 pixel := (byte bitShift:-4) bitAnd:16rF. |
140 pixel := (byte bitShift:-4) bitAnd:16rF. |
141 ] ifFalse:[ |
141 ] ifFalse:[ |
142 pixel := byte bitAnd:16rF. |
142 pixel := byte bitAnd:16rF. |
143 ]. |
143 ]. |
144 aPixelBuffer at:dstIdx put:pixel. |
144 aPixelBuffer at:dstIdx put:pixel. |
145 dstIdx := dstIdx + 1 |
145 dstIdx := dstIdx + 1 |
146 ]. |
146 ]. |
147 |
147 |
148 "Created: 21.7.1997 / 18:04:00 / cg" |
148 "Created: 21.7.1997 / 18:04:00 / cg" |
149 "Modified: 21.7.1997 / 18:05:47 / cg" |
149 "Modified: 21.7.1997 / 18:05:47 / cg" |
150 ! ! |
150 ! ! |
153 |
153 |
154 anyImageAsTrueColorFormOn:aDevice |
154 anyImageAsTrueColorFormOn:aDevice |
155 "return a true-color device-form for receiver. |
155 "return a true-color device-form for receiver. |
156 Supports true color devices with depths: 8, 16, 24 and 32" |
156 Supports true color devices with depths: 8, 16, 24 and 32" |
157 |
157 |
158 |depth |
158 |depth |
159 colorValues |
159 colorValues |
160 form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
160 form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
161 usedDevicePadding usedDeviceBytesPerRow padd| |
161 usedDevicePadding usedDeviceBytesPerRow padd| |
162 |
162 |
163 depth := aDevice depth. |
163 depth := aDevice depth. |
164 |
164 |
165 "/ gather r/g/b values for all colors in the map ... |
165 "/ gather r/g/b values for all colors in the map ... |
167 colorValues := self rgbColormapFor:aDevice. |
167 colorValues := self rgbColormapFor:aDevice. |
168 |
168 |
169 bestFormat := self bestSupportedImageFormatFor:aDevice. |
169 bestFormat := self bestSupportedImageFormatFor:aDevice. |
170 usedDeviceDepth := bestFormat at:#depth. |
170 usedDeviceDepth := bestFormat at:#depth. |
171 usedDeviceDepth == 1 ifTrue:[ |
171 usedDeviceDepth == 1 ifTrue:[ |
172 ^ self asMonochromeFormOn:aDevice |
172 ^ self asMonochromeFormOn:aDevice |
173 ]. |
173 ]. |
174 usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
174 usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
175 usedDevicePadding := bestFormat at:#padding. |
175 usedDevicePadding := bestFormat at:#padding. |
176 |
176 |
177 usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding. |
177 usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding. |
179 imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
179 imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
180 |
180 |
181 "/ for now, only support some depths |
181 "/ for now, only support some depths |
182 |
182 |
183 usedDeviceBitsPerPixel == 16 ifTrue:[ |
183 usedDeviceBitsPerPixel == 16 ifTrue:[ |
184 "/ 16 bits/pixel |
184 "/ 16 bits/pixel |
185 |
185 |
186 "/ now, walk over the image and replace |
186 "/ now, walk over the image and replace |
187 "/ colorMap indices by color values in the bits array |
187 "/ colorMap indices by color values in the bits array |
188 |
188 |
189 %{ |
189 %{ |
190 unsigned char *srcPtr = 0; |
190 unsigned char *srcPtr = 0; |
191 unsigned char *dstPtr = 0; |
191 unsigned char *dstPtr = 0; |
192 OBJ _bytes = __INST(bytes); |
192 OBJ _bytes = __INST(bytes); |
193 |
193 |
194 if (__isByteArrayLike(_bytes)) { |
194 if (__isByteArrayLike(_bytes)) { |
195 srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
195 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
196 } else { |
196 } else { |
197 if (__isExternalBytesLike(_bytes)) { |
197 if (__isExternalBytesLike(_bytes)) { |
198 srcPtr = __externalBytesAddress(_bytes); |
198 srcPtr = __externalBytesAddress(_bytes); |
199 } |
199 } |
200 } |
200 } |
201 if (__isByteArray(imageBits)) { |
201 if (__isByteArray(imageBits)) { |
202 dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
202 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
203 } else { |
203 } else { |
204 if (__isExternalBytesLike(imageBits)) { |
204 if (__isExternalBytesLike(imageBits)) { |
205 dstPtr = __externalBytesAddress(imageBits); |
205 dstPtr = __externalBytesAddress(imageBits); |
206 } |
206 } |
207 } |
207 } |
208 |
208 |
209 if (__bothSmallInteger(_INST(height), _INST(width)) |
209 if (__bothSmallInteger(__INST(height), __INST(width)) |
210 && __isArrayLike(colorValues) |
210 && __isArrayLike(colorValues) |
211 && srcPtr |
211 && srcPtr |
212 && dstPtr) { |
212 && dstPtr) { |
213 int r,p; |
213 int r,p; |
214 int x, y, w, h, nPix; |
214 int x, y, w, h, nPix; |
215 int byte; |
215 int byte; |
216 |
216 |
217 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
217 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
218 |
218 |
219 w = __intVal(_INST(width)); |
219 w = __intVal(__INST(width)); |
220 h = __intVal(_INST(height)); |
220 h = __intVal(__INST(height)); |
221 r = 0; |
221 r = 0; |
222 p = __intVal(padd); |
222 p = __intVal(padd); |
223 nPix = w * h; |
223 nPix = w * h; |
224 while (nPix-- > 0) { |
224 while (nPix-- > 0) { |
225 unsigned idx, v; |
225 unsigned idx, v; |
226 OBJ clr; |
226 OBJ clr; |
227 |
227 |
228 if (r & 1) { |
228 if (r & 1) { |
229 idx = byte & 0xF; |
229 idx = byte & 0xF; |
230 } else { |
230 } else { |
231 byte = *srcPtr++; |
231 byte = *srcPtr++; |
232 idx = (byte>>4) & 0xF; |
232 idx = (byte>>4) & 0xF; |
233 } |
233 } |
234 clr = ap[idx]; |
234 clr = ap[idx]; |
235 v = __intVal(clr); |
235 v = __intVal(clr); |
236 #ifdef __MSBFIRST |
236 #ifdef __MSBFIRST |
237 ((short *)dstPtr)[0] = v; |
237 ((short *)dstPtr)[0] = v; |
238 #else |
238 #else |
239 # ifdef xxSWAP_BYTES |
239 # ifdef xxSWAP_BYTES |
240 SWAP_BYTES(v); |
240 SWAP_BYTES(v); |
241 ((short *)dstPtr)[0] = v; |
241 ((short *)dstPtr)[0] = v; |
242 # else |
242 # else |
243 dstPtr[0] = (v>>8) & 0xFF; |
243 dstPtr[0] = (v>>8) & 0xFF; |
244 dstPtr[1] = (v) & 0xFF; |
244 dstPtr[1] = (v) & 0xFF; |
245 # endif |
245 # endif |
246 #endif |
246 #endif |
247 dstPtr += 2; |
247 dstPtr += 2; |
248 |
248 |
249 if (++r == w) { |
249 if (++r == w) { |
250 dstPtr += p; |
250 dstPtr += p; |
251 r = 0; |
251 r = 0; |
252 } |
252 } |
253 } |
253 } |
254 } |
254 } |
255 %}. |
255 %}. |
256 ] ifFalse:[ |
256 ] ifFalse:[ |
257 usedDeviceBitsPerPixel == 32 ifTrue:[ |
257 usedDeviceBitsPerPixel == 32 ifTrue:[ |
258 "/ 32 bits/pixel |
258 "/ 32 bits/pixel |
259 |
259 |
260 "/ now, walk over the image and replace |
260 "/ now, walk over the image and replace |
261 "/ colorMap indices by color values in the bits array |
261 "/ colorMap indices by color values in the bits array |
262 |
262 |
263 %{ |
263 %{ |
264 unsigned char *srcPtr = 0; |
264 unsigned char *srcPtr = 0; |
265 unsigned char *dstPtr = 0; |
265 unsigned char *dstPtr = 0; |
266 OBJ _bytes = __INST(bytes); |
266 OBJ _bytes = __INST(bytes); |
267 |
267 |
268 if (__isByteArrayLike(_bytes)) { |
268 if (__isByteArrayLike(_bytes)) { |
269 srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
269 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
270 } else { |
270 } else { |
271 if (__isExternalBytesLike(_bytes)) { |
271 if (__isExternalBytesLike(_bytes)) { |
272 srcPtr = __externalBytesAddress(_bytes); |
272 srcPtr = __externalBytesAddress(_bytes); |
273 } |
273 } |
274 } |
274 } |
275 if (__isByteArray(imageBits)) { |
275 if (__isByteArray(imageBits)) { |
276 dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
276 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
277 } else { |
277 } else { |
278 if (__isExternalBytesLike(imageBits)) { |
278 if (__isExternalBytesLike(imageBits)) { |
279 dstPtr = __externalBytesAddress(imageBits); |
279 dstPtr = __externalBytesAddress(imageBits); |
280 } |
280 } |
281 } |
281 } |
282 |
282 |
283 if (__bothSmallInteger(_INST(height), _INST(width)) |
283 if (__bothSmallInteger(__INST(height), __INST(width)) |
284 && __isArrayLike(colorValues) |
284 && __isArrayLike(colorValues) |
285 && srcPtr |
285 && srcPtr |
286 && dstPtr) { |
286 && dstPtr) { |
287 int x, y, w, h, nPix; |
287 int x, y, w, h, nPix; |
288 int r,p; |
288 int r,p; |
289 int byte; |
289 int byte; |
290 |
290 |
291 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
291 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
292 |
292 |
293 w = __intVal(_INST(width)); |
293 w = __intVal(__INST(width)); |
294 h = __intVal(_INST(height)); |
294 h = __intVal(__INST(height)); |
295 r = 0; |
295 r = 0; |
296 p = __intVal(padd); |
296 p = __intVal(padd); |
297 nPix = w * h; |
297 nPix = w * h; |
298 while (nPix > 0) { |
298 while (nPix > 0) { |
299 unsigned idx, v; |
299 unsigned idx, v; |
300 OBJ clr; |
300 OBJ clr; |
301 |
301 |
302 if (r & 1) { |
302 if (r & 1) { |
303 idx = byte & 0xF; |
303 idx = byte & 0xF; |
304 } else { |
304 } else { |
305 byte = *srcPtr++; |
305 byte = *srcPtr++; |
306 idx = (byte>>4) & 0xF; |
306 idx = (byte>>4) & 0xF; |
307 } |
307 } |
308 clr = ap[idx]; |
308 clr = ap[idx]; |
309 v = __intVal(clr); |
309 v = __intVal(clr); |
310 #ifdef __MSBFIRST |
310 #ifdef __MSBFIRST |
311 ((long *)dstPtr)[0] = v; |
311 ((long *)dstPtr)[0] = v; |
312 #else |
312 #else |
313 dstPtr[0] = (v>>24) & 0xFF; |
313 dstPtr[0] = (v>>24) & 0xFF; |
314 dstPtr[1] = (v>>16) & 0xFF; |
314 dstPtr[1] = (v>>16) & 0xFF; |
315 dstPtr[2] = (v>>8) & 0xFF; |
315 dstPtr[2] = (v>>8) & 0xFF; |
316 dstPtr[3] = (v) & 0xFF; |
316 dstPtr[3] = (v) & 0xFF; |
317 #endif |
317 #endif |
318 dstPtr += 4; |
318 dstPtr += 4; |
319 nPix--; |
319 nPix--; |
320 |
320 |
321 if (++r == w) { |
321 if (++r == w) { |
322 dstPtr += p; |
322 dstPtr += p; |
323 r = 0; |
323 r = 0; |
324 } |
324 } |
325 } |
325 } |
326 } |
326 } |
327 %}. |
327 %}. |
328 ] ifFalse:[ |
328 ] ifFalse:[ |
329 usedDeviceBitsPerPixel == 8 ifTrue:[ |
329 usedDeviceBitsPerPixel == 8 ifTrue:[ |
330 "/ 8 bits/pixel |
330 "/ 8 bits/pixel |
331 |
331 |
332 "/ now, walk over the image and replace |
332 "/ now, walk over the image and replace |
333 "/ colorMap indices by color values in the bits array |
333 "/ colorMap indices by color values in the bits array |
334 |
334 |
335 %{ |
335 %{ |
336 unsigned char *srcPtr = 0; |
336 unsigned char *srcPtr = 0; |
337 unsigned char *dstPtr = 0; |
337 unsigned char *dstPtr = 0; |
338 OBJ _bytes = __INST(bytes); |
338 OBJ _bytes = __INST(bytes); |
339 |
339 |
340 if (__isByteArrayLike(_bytes)) { |
340 if (__isByteArrayLike(_bytes)) { |
341 srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
341 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
342 } else { |
342 } else { |
343 if (__isExternalBytesLike(_bytes)) { |
343 if (__isExternalBytesLike(_bytes)) { |
344 srcPtr = __externalBytesAddress(_bytes); |
344 srcPtr = __externalBytesAddress(_bytes); |
345 } |
345 } |
346 } |
346 } |
347 if (__isByteArray(imageBits)) { |
347 if (__isByteArray(imageBits)) { |
348 dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
348 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
349 } else { |
349 } else { |
350 if (__isExternalBytesLike(imageBits)) { |
350 if (__isExternalBytesLike(imageBits)) { |
351 dstPtr = __externalBytesAddress(imageBits); |
351 dstPtr = __externalBytesAddress(imageBits); |
352 } |
352 } |
353 } |
353 } |
354 |
354 |
355 if (__bothSmallInteger(_INST(height), _INST(width)) |
355 if (__bothSmallInteger(__INST(height), __INST(width)) |
356 && __isArrayLike(colorValues) |
356 && __isArrayLike(colorValues) |
357 && srcPtr |
357 && srcPtr |
358 && dstPtr) { |
358 && dstPtr) { |
359 int x, y, w, h, nPix; |
359 int x, y, w, h, nPix; |
360 int r,p, byte; |
360 int r,p, byte; |
361 |
361 |
362 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
362 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
363 |
363 |
364 w = __intVal(_INST(width)); |
364 w = __intVal(__INST(width)); |
365 h = __intVal(_INST(height)); |
365 h = __intVal(__INST(height)); |
366 r = 0; |
366 r = 0; |
367 p = __intVal(padd); |
367 p = __intVal(padd); |
368 |
368 |
369 nPix = w * h; |
369 nPix = w * h; |
370 while (nPix > 0) { |
370 while (nPix > 0) { |
371 unsigned idx, v; |
371 unsigned idx, v; |
372 OBJ clr; |
372 OBJ clr; |
373 |
373 |
374 if (r & 1) { |
374 if (r & 1) { |
375 idx = byte & 0xF; |
375 idx = byte & 0xF; |
376 } else { |
376 } else { |
377 byte = *srcPtr++; |
377 byte = *srcPtr++; |
378 idx = (byte>>4) & 0xF; |
378 idx = (byte>>4) & 0xF; |
379 } |
379 } |
380 clr = ap[idx]; |
380 clr = ap[idx]; |
381 v = __intVal(clr); |
381 v = __intVal(clr); |
382 |
382 |
383 dstPtr[0] = v; |
383 dstPtr[0] = v; |
384 |
384 |
385 dstPtr += 1; |
385 dstPtr += 1; |
386 nPix--; |
386 nPix--; |
387 |
387 |
388 if (++r == w) { |
388 if (++r == w) { |
389 dstPtr += p; |
389 dstPtr += p; |
390 r = 0; |
390 r = 0; |
391 } |
391 } |
392 } |
392 } |
393 } |
393 } |
394 %}. |
394 %}. |
395 ] ifFalse:[ |
395 ] ifFalse:[ |
396 usedDeviceBitsPerPixel == 24 ifTrue:[ |
396 usedDeviceBitsPerPixel == 24 ifTrue:[ |
397 "/ 24 bits/pixel |
397 "/ 24 bits/pixel |
398 |
398 |
399 "/ now, walk over the image and replace |
399 "/ now, walk over the image and replace |
400 "/ colorMap indices by color values in the bits array |
400 "/ colorMap indices by color values in the bits array |
401 |
401 |
402 %{ |
402 %{ |
403 unsigned char *srcPtr = 0; |
403 unsigned char *srcPtr = 0; |
404 unsigned char *dstPtr = 0; |
404 unsigned char *dstPtr = 0; |
405 OBJ _bytes = __INST(bytes); |
405 OBJ _bytes = __INST(bytes); |
406 |
406 |
407 if (__isByteArrayLike(_bytes)) { |
407 if (__isByteArrayLike(_bytes)) { |
408 srcPtr = _ByteArrayInstPtr(_bytes)->ba_element; |
408 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
409 } else { |
409 } else { |
410 if (__isExternalBytesLike(_bytes)) { |
410 if (__isExternalBytesLike(_bytes)) { |
411 srcPtr = __externalBytesAddress(_bytes); |
411 srcPtr = __externalBytesAddress(_bytes); |
412 } |
412 } |
413 } |
413 } |
414 if (__isByteArray(imageBits)) { |
414 if (__isByteArray(imageBits)) { |
415 dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
415 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
416 } else { |
416 } else { |
417 if (__isExternalBytesLike(imageBits)) { |
417 if (__isExternalBytesLike(imageBits)) { |
418 dstPtr = __externalBytesAddress(imageBits); |
418 dstPtr = __externalBytesAddress(imageBits); |
419 } |
419 } |
420 } |
420 } |
421 |
421 |
422 if (__bothSmallInteger(_INST(height), _INST(width)) |
422 if (__bothSmallInteger(__INST(height), __INST(width)) |
423 && __isArrayLike(colorValues) |
423 && __isArrayLike(colorValues) |
424 && srcPtr |
424 && srcPtr |
425 && dstPtr) { |
425 && dstPtr) { |
426 int x, y, w, h, nPix; |
426 int x, y, w, h, nPix; |
427 int r, p, byte; |
427 int r, p, byte; |
428 |
428 |
429 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
429 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
430 |
430 |
431 w = __intVal(_INST(width)); |
431 w = __intVal(__INST(width)); |
432 h = __intVal(_INST(height)); |
432 h = __intVal(__INST(height)); |
433 r = 0; |
433 r = 0; |
434 p = __intVal(padd); |
434 p = __intVal(padd); |
435 |
435 |
436 nPix = w * h; |
436 nPix = w * h; |
437 while (nPix > 0) { |
437 while (nPix > 0) { |
438 unsigned idx, v; |
438 unsigned idx, v; |
439 OBJ clr; |
439 OBJ clr; |
440 |
440 |
441 if (r & 1) { |
441 if (r & 1) { |
442 idx = byte & 0xF; |
442 idx = byte & 0xF; |
443 } else { |
443 } else { |
444 byte = *srcPtr++; |
444 byte = *srcPtr++; |
445 idx = (byte>>4) & 0xF; |
445 idx = (byte>>4) & 0xF; |
446 } |
446 } |
447 clr = ap[idx]; |
447 clr = ap[idx]; |
448 v = __intVal(clr); |
448 v = __intVal(clr); |
449 |
449 |
450 dstPtr[0] = (v>>16) & 0xFF; |
450 dstPtr[0] = (v>>16) & 0xFF; |
451 dstPtr[1] = (v>>8) & 0xFF; |
451 dstPtr[1] = (v>>8) & 0xFF; |
452 dstPtr[2] = (v) & 0xFF; |
452 dstPtr[2] = (v) & 0xFF; |
453 |
453 |
454 dstPtr += 3; |
454 dstPtr += 3; |
455 nPix--; |
455 nPix--; |
456 |
456 |
457 if (++r == w) { |
457 if (++r == w) { |
458 dstPtr += p; |
458 dstPtr += p; |
459 r = 0; |
459 r = 0; |
460 } |
460 } |
461 } |
461 } |
462 } |
462 } |
463 %}. |
463 %}. |
464 ] ifFalse:[ |
464 ] ifFalse:[ |
465 'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
465 'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
466 ^ nil |
466 ^ nil |
467 ] |
467 ] |
468 ] |
468 ] |
469 ] |
469 ] |
470 ]. |
470 ]. |
471 |
471 |
472 imageBits isNil ifTrue:[ |
472 imageBits isNil ifTrue:[ |
473 ^ nil |
473 ^ nil |
474 ]. |
474 ]. |
475 |
475 |
476 form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
476 form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
477 form isNil ifTrue:[^ nil]. |
477 form isNil ifTrue:[^ nil]. |
478 form initGC. |
478 form initGC. |
479 |
479 |
480 form |
480 form |
481 copyBitsFrom:imageBits |
481 copyBitsFrom:imageBits |
482 bitsPerPixel:usedDeviceBitsPerPixel |
482 bitsPerPixel:usedDeviceBitsPerPixel |
483 depth:usedDeviceDepth |
483 depth:usedDeviceDepth |
484 padding:usedDevicePadding |
484 padding:usedDevicePadding |
485 width:width height:height |
485 width:width height:height |
486 x:0 y:0 |
486 x:0 y:0 |
487 toX:0 y:0. |
487 toX:0 y:0. |
488 |
488 |
489 ^ form |
489 ^ form |
490 |
490 |
491 "Created: / 20-10-1995 / 22:05:10 / cg" |
491 "Created: / 20-10-1995 / 22:05:10 / cg" |
492 "Modified: / 29-05-2007 / 19:22:19 / cg" |
492 "Modified: / 29-05-2007 / 19:22:19 / cg" |
536 orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
536 orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
537 "return the bitmap for a dithered depth-bitmap from the image; |
537 "return the bitmap for a dithered depth-bitmap from the image; |
538 with a constant ditherMatrix, this can be used for thresholding. |
538 with a constant ditherMatrix, this can be used for thresholding. |
539 Redefined to make use of knowing that pixels are 4-bit values." |
539 Redefined to make use of knowing that pixels are 4-bit values." |
540 |
540 |
541 |dH nDither bytes |
541 |dH nDither bytes |
542 greyLevels greyMap1 greyMap2 |
542 greyLevels greyMap1 greyMap2 |
543 bytesPerRow "{Class: SmallInteger }" |
543 bytesPerRow "{Class: SmallInteger }" |
544 bytesPerOutRow "{Class: SmallInteger }" |
544 bytesPerOutRow "{Class: SmallInteger }" |
545 pixelsPerByte "{Class: SmallInteger }" |
545 pixelsPerByte "{Class: SmallInteger }" |
546 outBits |
546 outBits |
560 bytesPerRow := self bytesPerRow. |
560 bytesPerRow := self bytesPerRow. |
561 |
561 |
562 bytesPerOutRow := (w * depth + 7) // 8. |
562 bytesPerOutRow := (w * depth + 7) // 8. |
563 outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
563 outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
564 (outBits isNil or:[bytes isNil]) ifTrue:[ |
564 (outBits isNil or:[bytes isNil]) ifTrue:[ |
565 ^ nil |
565 ^ nil |
566 ]. |
566 ]. |
567 |
567 |
568 greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels |
568 greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels |
569 greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
569 greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
570 0 |
570 0 |
571 ] ifFalse:[ |
571 ] ifFalse:[ |
572 b truncated |
572 b truncated |
573 ] |
573 ] |
574 ]) asByteArray. |
574 ]) asByteArray. |
575 |
575 |
576 greyMap2 := self greyMapForRange:(greyLevels-1). |
576 greyMap2 := self greyMapForRange:(greyLevels-1). |
577 greyMap2 := (greyMap2 collect:[:el | |
577 greyMap2 := (greyMap2 collect:[:el | |
578 el isNil ifTrue:[ |
578 el isNil ifTrue:[ |
579 0 |
579 0 |
580 ] ifFalse:[ |
580 ] ifFalse:[ |
581 ((el - el truncated) "/ the error (0..1) |
581 ((el - el truncated) "/ the error (0..1) |
582 * nDither) rounded |
582 * nDither) rounded |
583 ]]) asByteArray. |
583 ]]) asByteArray. |
584 |
584 |
585 %{ |
585 %{ |
586 int __dW = __intVal(dW); |
586 int __dW = __intVal(dW); |
587 int __dH = __intVal(dH); |
587 int __dH = __intVal(dH); |
588 int __byte; |
588 int __byte; |
609 unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
609 unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
610 unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
610 unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
611 |
611 |
612 __oY = __dY = 0; |
612 __oY = __dY = 0; |
613 for (__y=0; __y<__h; __y++) { |
613 for (__y=0; __y<__h; __y++) { |
614 __nextDst = __dstIdx + __bytesPerOutRow; |
614 __nextDst = __dstIdx + __bytesPerOutRow; |
615 __nextSrc = __srcIdx + __bytesPerRow; |
615 __nextSrc = __srcIdx + __bytesPerRow; |
616 |
616 |
617 __byte = 0; |
617 __byte = 0; |
618 __bitCnt = 8; |
618 __bitCnt = 8; |
619 |
619 |
620 __oX = 0; |
620 __oX = 0; |
621 |
621 |
622 for (__x=0; __x<__w; __x++) { |
622 for (__x=0; __x<__w; __x++) { |
623 if (__x & 1) { |
623 if (__x & 1) { |
624 /* odd */ |
624 /* odd */ |
625 __grey = __inByte & 0xF; |
625 __grey = __inByte & 0xF; |
626 __srcIdx++; |
626 __srcIdx++; |
627 } else { |
627 } else { |
628 __inByte = __bytes[__srcIdx]; |
628 __inByte = __bytes[__srcIdx]; |
629 __grey = (__inByte >> 4) & 0xF; |
629 __grey = (__inByte >> 4) & 0xF; |
630 } |
630 } |
631 |
631 |
632 __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
632 __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
633 __dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
633 __dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
634 __dT = __ditherMatrix[__dY + __oX]; |
634 __dT = __ditherMatrix[__dY + __oX]; |
635 |
635 |
636 if (__dO > __dT) /* dither says: next pixel */ |
636 if (__dO > __dT) /* dither says: next pixel */ |
637 __pixel++; |
637 __pixel++; |
638 |
638 |
639 __oX++; |
639 __oX++; |
640 if (__oX == __dW) __oX = 0; |
640 if (__oX == __dW) __oX = 0; |
641 |
641 |
642 __byte = (__byte << __depth) | __pixel; |
642 __byte = (__byte << __depth) | __pixel; |
643 |
643 |
644 __bitCnt = __bitCnt - __depth; |
644 __bitCnt = __bitCnt - __depth; |
645 if (__bitCnt == 0) { |
645 if (__bitCnt == 0) { |
646 __outBits[__dstIdx] = __byte; |
646 __outBits[__dstIdx] = __byte; |
647 __dstIdx++; |
647 __dstIdx++; |
648 __byte = 0; |
648 __byte = 0; |
649 __bitCnt = 8; |
649 __bitCnt = 8; |
650 } |
650 } |
651 } |
651 } |
652 |
652 |
653 if (__bitCnt != 8) { |
653 if (__bitCnt != 8) { |
654 __byte = __byte << __bitCnt; |
654 __byte = __byte << __bitCnt; |
655 __outBits[__dstIdx] = __byte; |
655 __outBits[__dstIdx] = __byte; |
656 } |
656 } |
657 |
657 |
658 __oY++; __dY += __dW; |
658 __oY++; __dY += __dW; |
659 if (__oY == __dH) { |
659 if (__oY == __dH) { |
660 __oY = 0; |
660 __oY = 0; |
661 __dY = 0; |
661 __dY = 0; |
662 } |
662 } |
663 |
663 |
664 __srcIdx = __nextSrc; |
664 __srcIdx = __nextSrc; |
665 __dstIdx = __nextDst; |
665 __dstIdx = __nextDst; |
666 } |
666 } |
667 %}. |
667 %}. |
668 ^ outBits |
668 ^ outBits |
669 ! |
669 ! |
670 |
670 |
671 orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
671 orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
672 "return the dithered monochrome bits for the receiver image; |
672 "return the dithered monochrome bits for the receiver image; |
673 with a constant ditherMatrix, this can be used for thresholding. |
673 with a constant ditherMatrix, this can be used for thresholding. |
674 Redefined to make use of knowing that pixels are 4-bit values." |
674 Redefined to make use of knowing that pixels are 4-bit values." |
675 |
675 |
676 |dH nDither bytes |
676 |dH nDither bytes |
677 greyMap monoBits |
677 greyMap monoBits |
678 bytesPerMonoRow "{Class: SmallInteger }" |
678 bytesPerMonoRow "{Class: SmallInteger }" |
679 bytesPerRow "{Class: SmallInteger }" |
679 bytesPerRow "{Class: SmallInteger }" |
680 w "{Class: SmallInteger }" |
680 w "{Class: SmallInteger }" |
681 h "{Class: SmallInteger }"| |
681 h "{Class: SmallInteger }"| |
690 bytesPerRow := self bytesPerRow. |
690 bytesPerRow := self bytesPerRow. |
691 |
691 |
692 bytesPerMonoRow := w + 7 // 8. |
692 bytesPerMonoRow := w + 7 // 8. |
693 monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
693 monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
694 (monoBits isNil or:[bytes isNil]) ifTrue:[ |
694 (monoBits isNil or:[bytes isNil]) ifTrue:[ |
695 ^ nil |
695 ^ nil |
696 ]. |
696 ]. |
697 |
697 |
698 greyMap := self greyByteMapForRange:nDither. |
698 greyMap := self greyByteMapForRange:nDither. |
699 |
699 |
700 %{ |
700 %{ |
722 unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
722 unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
723 unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
723 unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
724 |
724 |
725 __oY = __dY = 0; |
725 __oY = __dY = 0; |
726 for (__y=0; __y<__h; __y++) { |
726 for (__y=0; __y<__h; __y++) { |
727 __nextDst = __dstIdx + __bytesPerMonoRow; |
727 __nextDst = __dstIdx + __bytesPerMonoRow; |
728 __nextSrc = __srcIdx + __bytesPerRow; |
728 __nextSrc = __srcIdx + __bytesPerRow; |
729 |
729 |
730 __byte = 0; |
730 __byte = 0; |
731 __bitCnt = 8; |
731 __bitCnt = 8; |
732 |
732 |
733 __oX = 0; |
733 __oX = 0; |
734 |
734 |
735 for (__x=0; __x<__w; __x++) { |
735 for (__x=0; __x<__w; __x++) { |
736 if (__x & 1) { |
736 if (__x & 1) { |
737 /* odd */ |
737 /* odd */ |
738 __grey = __inByte & 0xF; |
738 __grey = __inByte & 0xF; |
739 __srcIdx++; |
739 __srcIdx++; |
740 } else { |
740 } else { |
741 __inByte = __bytes[__srcIdx]; /* 0..255 */ |
741 __inByte = __bytes[__srcIdx]; /* 0..255 */ |
742 __grey = (__inByte >> 4) & 0xF; |
742 __grey = (__inByte >> 4) & 0xF; |
743 } |
743 } |
744 |
744 |
745 __grey = __greyMap[__grey]; |
745 __grey = __greyMap[__grey]; |
746 __dT = __ditherMatrix[__dY + __oX]; |
746 __dT = __ditherMatrix[__dY + __oX]; |
747 |
747 |
748 __oX++; |
748 __oX++; |
749 if (__oX == __dW) __oX = 0; |
749 if (__oX == __dW) __oX = 0; |
750 |
750 |
751 __byte = __byte << 1; |
751 __byte = __byte << 1; |
752 if (__grey > __dT) { |
752 if (__grey > __dT) { |
753 __byte = __byte | 1; /* white */ |
753 __byte = __byte | 1; /* white */ |
754 } |
754 } |
755 |
755 |
756 __bitCnt--; |
756 __bitCnt--; |
757 if (__bitCnt == 0) { |
757 if (__bitCnt == 0) { |
758 __monoBits[__dstIdx] = __byte; |
758 __monoBits[__dstIdx] = __byte; |
759 __dstIdx++; |
759 __dstIdx++; |
760 __byte = 0; |
760 __byte = 0; |
761 __bitCnt = 8; |
761 __bitCnt = 8; |
762 } |
762 } |
763 } |
763 } |
764 |
764 |
765 if (__bitCnt != 8) { |
765 if (__bitCnt != 8) { |
766 __byte = __byte << __bitCnt; |
766 __byte = __byte << __bitCnt; |
767 __monoBits[__dstIdx] = __byte; |
767 __monoBits[__dstIdx] = __byte; |
768 } |
768 } |
769 |
769 |
770 __oY++; __dY += __dW; |
770 __oY++; __dY += __dW; |
771 if (__oY == __dH) { |
771 if (__oY == __dH) { |
772 __oY = 0; |
772 __oY = 0; |
773 __dY = 0; |
773 __dY = 0; |
774 } |
774 } |
775 |
775 |
776 __srcIdx = __nextSrc; |
776 __srcIdx = __nextSrc; |
777 __dstIdx = __nextDst; |
777 __dstIdx = __nextDst; |
778 } |
778 } |
779 %}. |
779 %}. |
780 |
780 |
781 ^ monoBits |
781 ^ monoBits |
782 ! ! |
782 ! ! |
808 x2 := xHigh. |
808 x2 := xHigh. |
809 |
809 |
810 srcIndex := (self bytesPerRow * y) + 1. |
810 srcIndex := (self bytesPerRow * y) + 1. |
811 srcIndex := srcIndex + (x1 // 2). |
811 srcIndex := srcIndex + (x1 // 2). |
812 x1 even ifTrue:[ |
812 x1 even ifTrue:[ |
813 shift := -4 |
813 shift := -4 |
814 ] ifFalse:[ |
814 ] ifFalse:[ |
815 shift := 0 |
815 shift := 0 |
816 ]. |
816 ]. |
817 |
817 |
818 byte := bytes at:srcIndex. |
818 byte := bytes at:srcIndex. |
819 x1 to:x2 do:[:x | |
819 x1 to:x2 do:[:x | |
820 shift == 0 ifTrue:[ |
820 shift == 0 ifTrue:[ |
821 value := byte bitAnd:16rF. |
821 value := byte bitAnd:16rF. |
822 shift := -4. |
822 shift := -4. |
823 srcIndex := srcIndex + 1. |
823 srcIndex := srcIndex + 1. |
824 ] ifFalse:[ |
824 ] ifFalse:[ |
825 srcIndex > byteSize ifTrue:[ |
825 srcIndex > byteSize ifTrue:[ |
826 byte := 0. |
826 byte := 0. |
827 ] ifFalse:[ |
827 ] ifFalse:[ |
828 byte := bytes at:srcIndex. |
828 byte := bytes at:srcIndex. |
829 ]. |
829 ]. |
830 value := (byte bitShift:-4) bitAnd:16rF. |
830 value := (byte bitShift:-4) bitAnd:16rF. |
831 shift := 0 |
831 shift := 0 |
832 ]. |
832 ]. |
833 aBlock value:x value:(colorArray at:(value + 1)). |
833 aBlock value:x value:(colorArray at:(value + 1)). |
834 ] |
834 ] |
835 |
835 |
836 "Created: / 7.6.1996 / 19:12:33 / cg" |
836 "Created: / 7.6.1996 / 19:12:33 / cg" |
837 "Modified: / 28.7.1998 / 21:26:11 / cg" |
837 "Modified: / 28.7.1998 / 21:26:11 / cg" |
838 ! |
838 ! |
858 x1 := xLow. |
858 x1 := xLow. |
859 x2 := xHigh. |
859 x2 := xHigh. |
860 srcIndex := (self bytesPerRow * y) + 1. |
860 srcIndex := (self bytesPerRow * y) + 1. |
861 srcIndex := srcIndex + (x1 // 2). |
861 srcIndex := srcIndex + (x1 // 2). |
862 x1 even ifTrue:[ |
862 x1 even ifTrue:[ |
863 shift := -4 |
863 shift := -4 |
864 ] ifFalse:[ |
864 ] ifFalse:[ |
865 shift := 0 |
865 shift := 0 |
866 ]. |
866 ]. |
867 |
867 |
868 x1 to:x2 do:[:x | |
868 x1 to:x2 do:[:x | |
869 shift == 0 ifTrue:[ |
869 shift == 0 ifTrue:[ |
870 byte := bytes at:srcIndex. |
870 byte := bytes at:srcIndex. |
871 pixelValue := byte bitAnd:16rF. |
871 pixelValue := byte bitAnd:16rF. |
872 shift := -4. |
872 shift := -4. |
873 srcIndex := srcIndex + 1. |
873 srcIndex := srcIndex + 1. |
874 ] ifFalse:[ |
874 ] ifFalse:[ |
875 byte := bytes at:srcIndex. |
875 byte := bytes at:srcIndex. |
876 pixelValue := (byte bitShift:-4) bitAnd:16rF. |
876 pixelValue := (byte bitShift:-4) bitAnd:16rF. |
877 shift := 0 |
877 shift := 0 |
878 ]. |
878 ]. |
879 aBlock value:x value:pixelValue. |
879 aBlock value:x value:pixelValue. |
880 ] |
880 ] |
881 |
881 |
882 "Created: 7.6.1996 / 19:09:45 / cg" |
882 "Created: 7.6.1996 / 19:09:45 / cg" |
883 ! ! |
883 ! ! |
884 |
884 |
885 !Depth4Image methodsFor:'magnification'! |
885 !Depth4Image methodsFor:'magnification'! |
886 |
886 |
887 magnifyRowFrom:srcBytes offset:srcStart |
887 magnifyRowFrom:srcBytes offset:srcStart |
888 into:dstBytes offset:dstStart factor:mX |
888 into:dstBytes offset:dstStart factor:mX |
889 |
889 |
890 "magnify a single pixel row - can only magnify by integer factors. |
890 "magnify a single pixel row - can only magnify by integer factors. |
891 Specially tuned for factor 2." |
891 Specially tuned for factor 2." |
892 |
892 |
893 %{ |
893 %{ |
895 int _mag; |
895 int _mag; |
896 REGISTER int i; |
896 REGISTER int i; |
897 REGISTER unsigned char _byte; |
897 REGISTER unsigned char _byte; |
898 int _pixels; |
898 int _pixels; |
899 REGISTER int outcnt, bits, bit; |
899 REGISTER int outcnt, bits, bit; |
900 OBJ w = _INST(width); |
900 OBJ w = __INST(width); |
901 |
901 |
902 if (__bothSmallInteger(srcStart, dstStart) |
902 if (__bothSmallInteger(srcStart, dstStart) |
903 && __bothSmallInteger(w, mX) |
903 && __bothSmallInteger(w, mX) |
904 && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
904 && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
905 _mag = __intVal(mX); |
905 _mag = __intVal(mX); |
906 srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
906 srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
907 dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
907 dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
908 _pixels = __intVal(w); |
908 _pixels = __intVal(w); |
909 |
909 |
910 switch (_mag) { |
910 switch (_mag) { |
911 case 1: |
911 case 1: |
912 break; |
912 break; |
913 |
913 |
914 case 2: |
914 case 2: |
915 _byte = *srcP++; |
915 _byte = *srcP++; |
916 while (_pixels) { |
916 while (_pixels) { |
917 bit = (_byte >> 4) & 0xF; |
917 bit = (_byte >> 4) & 0xF; |
918 bits = (bit << 4) | bit; |
918 bits = (bit << 4) | bit; |
919 *dstP++ = bits; |
919 *dstP++ = bits; |
920 |
920 |
921 if (--_pixels) { |
921 if (--_pixels) { |
922 bit = _byte & 0xF; |
922 bit = _byte & 0xF; |
923 bits = (bit << 4) | bit; |
923 bits = (bit << 4) | bit; |
924 *dstP++ = bits; |
924 *dstP++ = bits; |
925 _byte = *srcP++; |
925 _byte = *srcP++; |
926 _pixels--; |
926 _pixels--; |
927 } |
927 } |
928 } |
928 } |
929 break; |
929 break; |
930 |
930 |
931 default: |
931 default: |
932 bits = 0, outcnt = 0; |
932 bits = 0, outcnt = 0; |
933 _byte = *srcP++; |
933 _byte = *srcP++; |
934 while (_pixels) { |
934 while (_pixels) { |
935 bit = (_byte >> 4) & 0xF; |
935 bit = (_byte >> 4) & 0xF; |
936 |
936 |
937 for (i=_mag; i>0; i--) { |
937 for (i=_mag; i>0; i--) { |
938 bits = (bits << 4) | bit; |
938 bits = (bits << 4) | bit; |
939 outcnt++; |
939 outcnt++; |
940 if (outcnt == 2) { |
940 if (outcnt == 2) { |
941 *dstP++ = bits; |
941 *dstP++ = bits; |
942 bits = 0; |
942 bits = 0; |
943 outcnt = 0; |
943 outcnt = 0; |
944 } |
944 } |
945 } |
945 } |
946 |
946 |
947 if (--_pixels) { |
947 if (--_pixels) { |
948 bit = _byte & 0xF; |
948 bit = _byte & 0xF; |
949 for (i=_mag; i>0; i--) { |
949 for (i=_mag; i>0; i--) { |
950 bits = (bits << 4) | bit; |
950 bits = (bits << 4) | bit; |
951 outcnt++; |
951 outcnt++; |
952 if (outcnt == 2) { |
952 if (outcnt == 2) { |
953 *dstP++ = bits; |
953 *dstP++ = bits; |
954 bits = 0; |
954 bits = 0; |
955 outcnt = 0; |
955 outcnt = 0; |
956 } |
956 } |
957 } |
957 } |
958 _byte = *srcP++; |
958 _byte = *srcP++; |
959 _pixels--; |
959 _pixels--; |
960 } |
960 } |
961 } |
961 } |
962 if (outcnt) { |
962 if (outcnt) { |
963 *dstP = bits << 4; |
963 *dstP = bits << 4; |
964 } |
964 } |
965 |
965 |
966 break; |
966 break; |
967 } |
967 } |
968 RETURN (self); |
968 RETURN (self); |
969 } |
969 } |
970 %}. |
970 %}. |
971 super |
971 super |
972 magnifyRowFrom:srcBytes offset:srcStart |
972 magnifyRowFrom:srcBytes offset:srcStart |
973 into:dstBytes offset:dstStart factor:mX |
973 into:dstBytes offset:dstStart factor:mX |
974 ! ! |
974 ! ! |
975 |
975 |
976 !Depth4Image methodsFor:'queries'! |
976 !Depth4Image methodsFor:'queries'! |
977 |
977 |
978 bitsPerPixel |
978 bitsPerPixel |
1002 colorFromValue:pixelValue |
1002 colorFromValue:pixelValue |
1003 "given a pixel value, return the corresponding color. |
1003 "given a pixel value, return the corresponding color. |
1004 Pixel values start with 0." |
1004 Pixel values start with 0." |
1005 |
1005 |
1006 photometric == #whiteIs0 ifTrue:[ |
1006 photometric == #whiteIs0 ifTrue:[ |
1007 ^ Color gray:100 - (100 / 15 * pixelValue) |
1007 ^ Color gray:100 - (100 / 15 * pixelValue) |
1008 ]. |
1008 ]. |
1009 photometric == #blackIs0 ifTrue:[ |
1009 photometric == #blackIs0 ifTrue:[ |
1010 ^ Color gray:(100 / 15 * pixelValue) |
1010 ^ Color gray:(100 / 15 * pixelValue) |
1011 ]. |
1011 ]. |
1012 photometric == #palette ifTrue:[ |
1012 photometric == #palette ifTrue:[ |
1013 pixelValue < colorMap size ifTrue:[ |
1013 pixelValue < colorMap size ifTrue:[ |
1014 ^ colorMap at:(pixelValue + 1) |
1014 ^ colorMap at:(pixelValue + 1) |
1015 ] |
1015 ] |
1016 ]. |
1016 ]. |
1017 ^ super colorFromValue:pixelValue |
1017 ^ super colorFromValue:pixelValue |
1018 ! |
1018 ! |
1019 |
1019 |
1020 usedValues |
1020 usedValues |
1022 |
1022 |
1023 |useFlags usedValues| |
1023 |useFlags usedValues| |
1024 |
1024 |
1025 useFlags := Array new:16 withAll:false. |
1025 useFlags := Array new:16 withAll:false. |
1026 width even ifFalse:[ |
1026 width even ifFalse:[ |
1027 0 to:self height - 1 do:[:y | |
1027 0 to:self height - 1 do:[:y | |
1028 self valuesAtY:y from:0 to:self width - 1 do:[:x :pixel | |
1028 self valuesAtY:y from:0 to:self width - 1 do:[:x :pixel | |
1029 useFlags at:(pixel + 1) put:true |
1029 useFlags at:(pixel + 1) put:true |
1030 ] |
1030 ] |
1031 ]. |
1031 ]. |
1032 ] ifTrue:[ |
1032 ] ifTrue:[ |
1033 self bits usedValues do:[:byte | |
1033 self bits usedValues do:[:byte | |
1034 useFlags at:(byte bitShift:-4)+1 put:true. |
1034 useFlags at:(byte bitShift:-4)+1 put:true. |
1035 useFlags at:(byte bitAnd:2r1111)+1 put:true. |
1035 useFlags at:(byte bitAnd:2r1111)+1 put:true. |
1036 ]. |
1036 ]. |
1037 ]. |
1037 ]. |
1038 ^ (0 to:15) select:[:i | useFlags at:(i+1)]. |
1038 ^ (0 to:15) select:[:i | useFlags at:(i+1)]. |
1039 |
1039 |
1040 "/ usedValues := OrderedCollection new. |
1040 "/ usedValues := OrderedCollection new. |
1041 "/ 1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]]. |
1041 "/ 1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]]. |
1045 ! ! |
1045 ! ! |
1046 |
1046 |
1047 !Depth4Image class methodsFor:'documentation'! |
1047 !Depth4Image class methodsFor:'documentation'! |
1048 |
1048 |
1049 version |
1049 version |
1050 ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.51 2009-11-05 14:37:10 stefan Exp $' |
1050 ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.52 2013-05-21 20:50:48 cg Exp $' |
1051 ! |
1051 ! |
1052 |
1052 |
1053 version_CVS |
1053 version_CVS |
1054 ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.51 2009-11-05 14:37:10 stefan Exp $' |
1054 ^ '$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.52 2013-05-21 20:50:48 cg Exp $' |
1055 ! ! |
1055 ! ! |