138 imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
140 imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
139 |
141 |
140 "/ for now, only support some depths |
142 "/ for now, only support some depths |
141 |
143 |
142 usedDeviceBitsPerPixel == 16 ifTrue:[ |
144 usedDeviceBitsPerPixel == 16 ifTrue:[ |
143 "/ 16 bits/pixel |
145 "/ 16 bits/pixel |
144 |
146 |
145 "/ now, walk over the image and replace |
147 "/ now, walk over the image and replace |
146 "/ colorMap indices by color values in the bits array |
148 "/ colorMap indices by color values in the bits array |
147 |
149 |
148 %{ |
150 %{ |
149 unsigned char *srcPtr = 0; |
151 unsigned char *srcPtr = 0; |
150 unsigned char *dstPtr = 0; |
152 unsigned char *dstPtr = 0; |
151 OBJ _bytes = __INST(bytes); |
153 OBJ _bytes = __INST(bytes); |
152 |
154 |
153 if (__isByteArrayLike(_bytes)) { |
155 if (__isByteArrayLike(_bytes)) { |
154 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
156 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
155 } else { |
157 } else { |
156 if (__isExternalBytesLike(_bytes)) { |
158 if (__isExternalBytesLike(_bytes)) { |
157 srcPtr = __externalBytesAddress(_bytes); |
159 srcPtr = __externalBytesAddress(_bytes); |
158 } |
160 } |
159 } |
161 } |
160 if (__isByteArray(imageBits)) { |
162 if (__isByteArray(imageBits)) { |
161 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
163 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
162 } else { |
164 } else { |
163 if (__isExternalBytesLike(imageBits)) { |
165 if (__isExternalBytesLike(imageBits)) { |
164 dstPtr = __externalBytesAddress(imageBits); |
166 dstPtr = __externalBytesAddress(imageBits); |
165 } |
167 } |
166 } |
168 } |
167 |
169 |
168 if (__bothSmallInteger(__INST(height), __INST(width)) |
170 if (__bothSmallInteger(__INST(height), __INST(width)) |
169 && __isArrayLike(colorValues) |
171 && __isArrayLike(colorValues) |
170 && srcPtr |
172 && srcPtr |
171 && dstPtr) { |
173 && dstPtr) { |
172 int r,p; |
174 int r,p; |
173 int x, y, w, h, nPix; |
175 int x, y, w, h, nPix; |
174 int byte, shift; |
176 int byte, shift; |
175 |
177 |
176 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
178 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
177 |
179 |
178 w = __intVal(__INST(width)); |
180 w = __intVal(__INST(width)); |
179 h = __intVal(__INST(height)); |
181 h = __intVal(__INST(height)); |
180 r = 0; |
182 r = 0; |
181 p = __intVal(padd); |
183 p = __intVal(padd); |
182 |
184 |
183 nPix = w * h; |
185 nPix = w * h; |
184 shift = -2; |
186 shift = -2; |
185 while (nPix-- > 0) { |
187 while (nPix-- > 0) { |
186 unsigned idx, v; |
188 unsigned idx, v; |
187 OBJ clr; |
189 OBJ clr; |
188 |
190 |
189 if (shift < 0) { |
191 if (shift < 0) { |
190 byte = *srcPtr++; |
192 byte = *srcPtr++; |
191 shift = 6; |
193 shift = 6; |
192 } |
194 } |
193 idx = (byte >> shift) & 3; |
195 idx = (byte >> shift) & 3; |
194 shift -= 2; |
196 shift -= 2; |
195 |
197 |
196 clr = ap[idx]; |
198 clr = ap[idx]; |
197 v = __intVal(clr); |
199 v = __intVal(clr); |
198 #ifdef __MSBFIRST |
200 #ifdef __MSBFIRST |
199 ((short *)dstPtr)[0] = v; |
201 ((short *)dstPtr)[0] = v; |
200 #else |
202 #else |
201 # ifdef xxSWAP_BYTES |
203 # ifdef xxSWAP_BYTES |
202 SWAP_BYTES(v); |
204 SWAP_BYTES(v); |
203 ((short *)dstPtr)[0] = v; |
205 ((short *)dstPtr)[0] = v; |
204 # else |
206 # else |
205 dstPtr[0] = (v>>8) & 0xFF; |
207 dstPtr[0] = (v>>8) & 0xFF; |
206 dstPtr[1] = (v) & 0xFF; |
208 dstPtr[1] = (v) & 0xFF; |
207 # endif |
209 # endif |
208 #endif |
210 #endif |
209 dstPtr += 2; |
211 dstPtr += 2; |
210 |
212 |
211 if (++r == w) { |
213 if (++r == w) { |
212 dstPtr += p; |
214 dstPtr += p; |
213 r = 0; |
215 r = 0; |
214 shift = -2; |
216 shift = -2; |
215 } |
217 } |
216 } |
218 } |
217 } |
219 } |
218 %}. |
220 %}. |
219 ] ifFalse:[ |
221 ] ifFalse:[ |
220 usedDeviceBitsPerPixel == 32 ifTrue:[ |
222 usedDeviceBitsPerPixel == 32 ifTrue:[ |
221 "/ 32 bits/pixel |
223 "/ 32 bits/pixel |
222 |
224 |
223 "/ now, walk over the image and replace |
225 "/ now, walk over the image and replace |
224 "/ colorMap indices by color values in the bits array |
226 "/ colorMap indices by color values in the bits array |
225 |
227 |
226 %{ |
228 %{ |
227 unsigned char *srcPtr = 0; |
229 unsigned char *srcPtr = 0; |
228 unsigned char *dstPtr = 0; |
230 unsigned char *dstPtr = 0; |
229 OBJ _bytes = __INST(bytes); |
231 OBJ _bytes = __INST(bytes); |
230 |
232 |
231 if (__isByteArrayLike(_bytes)) { |
233 if (__isByteArrayLike(_bytes)) { |
232 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
234 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
233 } else { |
235 } else { |
234 if (__isExternalBytesLike(_bytes)) { |
236 if (__isExternalBytesLike(_bytes)) { |
235 srcPtr = __externalBytesAddress(_bytes); |
237 srcPtr = __externalBytesAddress(_bytes); |
236 } |
238 } |
237 } |
239 } |
238 if (__isByteArray(imageBits)) { |
240 if (__isByteArray(imageBits)) { |
239 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
241 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
240 } else { |
242 } else { |
241 if (__isExternalBytesLike(imageBits)) { |
243 if (__isExternalBytesLike(imageBits)) { |
242 dstPtr = __externalBytesAddress(imageBits); |
244 dstPtr = __externalBytesAddress(imageBits); |
243 } |
245 } |
244 } |
246 } |
245 |
247 |
246 if (__bothSmallInteger(__INST(height), __INST(width)) |
248 if (__bothSmallInteger(__INST(height), __INST(width)) |
247 && __isArrayLike(colorValues) |
249 && __isArrayLike(colorValues) |
248 && srcPtr |
250 && srcPtr |
249 && dstPtr) { |
251 && dstPtr) { |
250 int x, y, w, h, nPix; |
252 int x, y, w, h, nPix; |
251 int r,p; |
253 int r,p; |
252 int byte, shift; |
254 int byte, shift; |
253 |
255 |
254 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
256 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
255 |
257 |
256 w = __intVal(__INST(width)); |
258 w = __intVal(__INST(width)); |
257 h = __intVal(__INST(height)); |
259 h = __intVal(__INST(height)); |
258 r = 0; |
260 r = 0; |
259 p = __intVal(padd); |
261 p = __intVal(padd); |
260 |
262 |
261 nPix = w * h; |
263 nPix = w * h; |
262 shift = -2; |
264 shift = -2; |
263 while (nPix > 0) { |
265 while (nPix > 0) { |
264 unsigned idx, v; |
266 unsigned idx, v; |
265 OBJ clr; |
267 OBJ clr; |
266 |
268 |
267 if (shift < 0) { |
269 if (shift < 0) { |
268 byte = *srcPtr++; |
270 byte = *srcPtr++; |
269 shift = 6; |
271 shift = 6; |
270 } |
272 } |
271 idx = (byte >> shift) & 3; |
273 idx = (byte >> shift) & 3; |
272 shift -= 2; |
274 shift -= 2; |
273 |
275 |
274 clr = ap[idx]; |
276 clr = ap[idx]; |
275 v = __intVal(clr); |
277 v = __intVal(clr); |
276 #ifdef __MSBFIRST |
278 #ifdef __MSBFIRST |
277 ((long *)dstPtr)[0] = v; |
279 ((long *)dstPtr)[0] = v; |
278 #else |
280 #else |
279 dstPtr[0] = (v>>24) & 0xFF; |
281 dstPtr[0] = (v>>24) & 0xFF; |
280 dstPtr[1] = (v>>16) & 0xFF; |
282 dstPtr[1] = (v>>16) & 0xFF; |
281 dstPtr[2] = (v>>8) & 0xFF; |
283 dstPtr[2] = (v>>8) & 0xFF; |
282 dstPtr[3] = (v) & 0xFF; |
284 dstPtr[3] = (v) & 0xFF; |
283 #endif |
285 #endif |
284 dstPtr += 4; |
286 dstPtr += 4; |
285 nPix--; |
287 nPix--; |
286 |
288 |
287 if (++r == w) { |
289 if (++r == w) { |
288 dstPtr += p; |
290 dstPtr += p; |
289 r = 0; |
291 r = 0; |
290 shift = -2; |
292 shift = -2; |
291 } |
293 } |
292 } |
294 } |
293 } |
295 } |
294 %}. |
296 %}. |
295 ] ifFalse:[ |
297 ] ifFalse:[ |
296 usedDeviceBitsPerPixel == 8 ifTrue:[ |
298 usedDeviceBitsPerPixel == 8 ifTrue:[ |
297 "/ 8 bits/pixel |
299 "/ 8 bits/pixel |
298 |
300 |
299 "/ now, walk over the image and replace |
301 "/ now, walk over the image and replace |
300 "/ colorMap indices by color values in the bits array |
302 "/ colorMap indices by color values in the bits array |
301 |
303 |
302 %{ |
304 %{ |
303 unsigned char *srcPtr = 0; |
305 unsigned char *srcPtr = 0; |
304 unsigned char *dstPtr = 0; |
306 unsigned char *dstPtr = 0; |
305 OBJ _bytes = __INST(bytes); |
307 OBJ _bytes = __INST(bytes); |
306 |
308 |
307 if (__isByteArrayLike(_bytes)) { |
309 if (__isByteArrayLike(_bytes)) { |
308 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
310 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
309 } else { |
311 } else { |
310 if (__isExternalBytesLike(_bytes)) { |
312 if (__isExternalBytesLike(_bytes)) { |
311 srcPtr = __externalBytesAddress(_bytes); |
313 srcPtr = __externalBytesAddress(_bytes); |
312 } |
314 } |
313 } |
315 } |
314 if (__isByteArray(imageBits)) { |
316 if (__isByteArray(imageBits)) { |
315 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
317 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
316 } else { |
318 } else { |
317 if (__isExternalBytesLike(imageBits)) { |
319 if (__isExternalBytesLike(imageBits)) { |
318 dstPtr = __externalBytesAddress(imageBits); |
320 dstPtr = __externalBytesAddress(imageBits); |
319 } |
321 } |
320 } |
322 } |
321 |
323 |
322 if (__bothSmallInteger(__INST(height), __INST(width)) |
324 if (__bothSmallInteger(__INST(height), __INST(width)) |
323 && __isArrayLike(colorValues) |
325 && __isArrayLike(colorValues) |
324 && srcPtr |
326 && srcPtr |
325 && dstPtr) { |
327 && dstPtr) { |
326 int x, y, w, h, nPix; |
328 int x, y, w, h, nPix; |
327 int r,p, byte, shift; |
329 int r,p, byte, shift; |
328 |
330 |
329 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
331 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
330 |
332 |
331 w = __intVal(__INST(width)); |
333 w = __intVal(__INST(width)); |
332 h = __intVal(__INST(height)); |
334 h = __intVal(__INST(height)); |
333 r = 0; |
335 r = 0; |
334 p = __intVal(padd); |
336 p = __intVal(padd); |
335 |
337 |
336 nPix = w * h; |
338 nPix = w * h; |
337 shift = -2; |
339 shift = -2; |
338 while (nPix > 0) { |
340 while (nPix > 0) { |
339 unsigned idx, v; |
341 unsigned idx, v; |
340 OBJ clr; |
342 OBJ clr; |
341 |
343 |
342 if (shift < 0) { |
344 if (shift < 0) { |
343 byte = *srcPtr++; |
345 byte = *srcPtr++; |
344 shift = 6; |
346 shift = 6; |
345 } |
347 } |
346 idx = (byte >> shift) & 3; |
348 idx = (byte >> shift) & 3; |
347 shift -= 2; |
349 shift -= 2; |
348 |
350 |
349 clr = ap[idx]; |
351 clr = ap[idx]; |
350 v = __intVal(clr); |
352 v = __intVal(clr); |
351 |
353 |
352 dstPtr[0] = v; |
354 dstPtr[0] = v; |
353 |
355 |
354 dstPtr += 1; |
356 dstPtr += 1; |
355 nPix--; |
357 nPix--; |
356 |
358 |
357 if (++r == w) { |
359 if (++r == w) { |
358 dstPtr += p; |
360 dstPtr += p; |
359 r = 0; |
361 r = 0; |
360 shift = -2; |
362 shift = -2; |
361 } |
363 } |
362 } |
364 } |
363 } |
365 } |
364 %}. |
366 %}. |
365 ] ifFalse:[ |
367 ] ifFalse:[ |
366 usedDeviceBitsPerPixel == 24 ifTrue:[ |
368 usedDeviceBitsPerPixel == 24 ifTrue:[ |
367 "/ 24 bits/pixel |
369 "/ 24 bits/pixel |
368 |
370 |
369 "/ now, walk over the image and replace |
371 "/ now, walk over the image and replace |
370 "/ colorMap indices by color values in the bits array |
372 "/ colorMap indices by color values in the bits array |
371 |
373 |
372 %{ |
374 %{ |
373 unsigned char *srcPtr = 0; |
375 unsigned char *srcPtr = 0; |
374 unsigned char *dstPtr = 0; |
376 unsigned char *dstPtr = 0; |
375 OBJ _bytes = __INST(bytes); |
377 OBJ _bytes = __INST(bytes); |
376 |
378 |
377 if (__isByteArrayLike(_bytes)) { |
379 if (__isByteArrayLike(_bytes)) { |
378 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
380 srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
379 } else { |
381 } else { |
380 if (__isExternalBytesLike(_bytes)) { |
382 if (__isExternalBytesLike(_bytes)) { |
381 srcPtr = __externalBytesAddress(_bytes); |
383 srcPtr = __externalBytesAddress(_bytes); |
382 } |
384 } |
383 } |
385 } |
384 if (__isByteArray(imageBits)) { |
386 if (__isByteArray(imageBits)) { |
385 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
387 dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
386 } else { |
388 } else { |
387 if (__isExternalBytesLike(imageBits)) { |
389 if (__isExternalBytesLike(imageBits)) { |
388 dstPtr = __externalBytesAddress(imageBits); |
390 dstPtr = __externalBytesAddress(imageBits); |
389 } |
391 } |
390 } |
392 } |
391 |
393 |
392 if (__bothSmallInteger(__INST(height), __INST(width)) |
394 if (__bothSmallInteger(__INST(height), __INST(width)) |
393 && __isArrayLike(colorValues) |
395 && __isArrayLike(colorValues) |
394 && srcPtr |
396 && srcPtr |
395 && dstPtr) { |
397 && dstPtr) { |
396 int x, y, w, h, nPix; |
398 int x, y, w, h, nPix; |
397 int r, p, byte, shift; |
399 int r, p, byte, shift; |
398 |
400 |
399 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
401 OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
400 |
402 |
401 w = __intVal(__INST(width)); |
403 w = __intVal(__INST(width)); |
402 h = __intVal(__INST(height)); |
404 h = __intVal(__INST(height)); |
403 r = 0; |
405 r = 0; |
404 p = __intVal(padd); |
406 p = __intVal(padd); |
405 |
407 |
406 nPix = w * h; |
408 nPix = w * h; |
407 shift = -2; |
409 shift = -2; |
408 while (nPix > 0) { |
410 while (nPix > 0) { |
409 unsigned idx, v; |
411 unsigned idx, v; |
410 OBJ clr; |
412 OBJ clr; |
411 |
413 |
412 if (shift < 0) { |
414 if (shift < 0) { |
413 byte = *srcPtr++; |
415 byte = *srcPtr++; |
414 shift = 6; |
416 shift = 6; |
415 } |
417 } |
416 idx = (byte >> shift) & 3; |
418 idx = (byte >> shift) & 3; |
417 shift -= 2; |
419 shift -= 2; |
418 |
420 |
419 clr = ap[idx]; |
421 clr = ap[idx]; |
420 v = __intVal(clr); |
422 v = __intVal(clr); |
421 |
423 |
422 dstPtr[0] = (v>>16) & 0xFF; |
424 dstPtr[0] = (v>>16) & 0xFF; |
423 dstPtr[1] = (v>>8) & 0xFF; |
425 dstPtr[1] = (v>>8) & 0xFF; |
424 dstPtr[2] = (v) & 0xFF; |
426 dstPtr[2] = (v) & 0xFF; |
425 |
427 |
426 dstPtr += 3; |
428 dstPtr += 3; |
427 nPix--; |
429 nPix--; |
428 |
430 |
429 if (++r == w) { |
431 if (++r == w) { |
430 dstPtr += p; |
432 dstPtr += p; |
431 r = 0; |
433 r = 0; |
432 shift = -2; |
434 shift = -2; |
433 } |
435 } |
434 } |
436 } |
435 } |
437 } |
436 %}. |
438 %}. |
437 ] ifFalse:[ |
439 ] ifFalse:[ |
438 'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
440 'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
439 ^ nil |
441 ^ nil |
440 ] |
442 ] |
441 ] |
443 ] |
442 ] |
444 ] |
443 ]. |
445 ]. |
444 |
446 |
445 imageBits isNil ifTrue:[ |
447 imageBits isNil ifTrue:[ |
446 ^ nil |
448 ^ nil |
447 ]. |
449 ]. |
448 |
450 |
449 form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
451 form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
450 form isNil ifTrue:[^ nil]. |
452 form isNil ifTrue:[^ nil]. |
451 form initGC. |
453 form initGC. |
452 |
454 |
453 form |
455 form |
454 copyBitsFrom:imageBits |
456 copyBitsFrom:imageBits |
455 bitsPerPixel:usedDeviceBitsPerPixel |
457 bitsPerPixel:usedDeviceBitsPerPixel |
456 depth:usedDeviceDepth |
458 depth:usedDeviceDepth |
457 padding:usedDevicePadding |
459 padding:usedDevicePadding |
458 width:width height:height |
460 width:width height:height |
459 x:0 y:0 |
461 x:0 y:0 |
460 toX:0 y:0. |
462 toX:0 y:0. |
461 |
463 |
462 ^ form |
464 ^ form |
463 |
465 |
464 "Created: / 20-10-1995 / 22:05:10 / cg" |
466 "Created: / 20-10-1995 / 22:05:10 / cg" |
465 "Modified: / 29-05-2007 / 19:22:29 / cg" |
467 "Modified: / 29-05-2007 / 19:22:29 / cg" |