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:#Depth24Image
|
81
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Display Objects'
|
1
|
18 |
!
|
|
19 |
|
3
|
20 |
Depth24Image comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
81
|
22 |
All Rights Reserved
|
54
|
23 |
|
89
|
24 |
$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.9 1995-02-06 00:35:49 claus Exp $
|
46
|
25 |
'!
|
3
|
26 |
|
46
|
27 |
!Depth24Image class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
81
|
32 |
All Rights Reserved
|
3
|
33 |
|
46
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
3
|
42 |
|
46
|
43 |
version
|
|
44 |
"
|
89
|
45 |
$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.9 1995-02-06 00:35:49 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class represents true-color (24 bit / pixel) images.
|
|
52 |
It mainly consists of methods already implemented in Image,
|
|
53 |
reimplemented here for more performance.
|
|
54 |
"
|
|
55 |
! !
|
3
|
56 |
|
89
|
57 |
!Depth24Image class methodsFor:'queries'!
|
|
58 |
|
|
59 |
imageDepth
|
|
60 |
^ 24
|
|
61 |
! !
|
|
62 |
|
81
|
63 |
!Depth24Image methodsFor:'queries'!
|
1
|
64 |
|
|
65 |
bitsPerPixel
|
|
66 |
"return the number of bits per pixel"
|
|
67 |
|
|
68 |
^ 24
|
|
69 |
!
|
|
70 |
|
|
71 |
bitsPerRow
|
|
72 |
"return the number of bits in one scanline of the image"
|
|
73 |
|
|
74 |
^ width * 24
|
|
75 |
!
|
|
76 |
|
|
77 |
bitsPerSample
|
|
78 |
"return the number of bits per sample.
|
|
79 |
The return value is an array of bits-per-plane."
|
|
80 |
|
|
81 |
^ #(8 8 8)
|
|
82 |
!
|
|
83 |
|
|
84 |
bytesPerRow
|
|
85 |
"return the number of bytes in one scanline of the image"
|
|
86 |
|
|
87 |
^ width * 3
|
|
88 |
!
|
|
89 |
|
|
90 |
samplesPerPixel
|
|
91 |
"return the number of samples per pixel in the image."
|
|
92 |
|
|
93 |
^ 3
|
81
|
94 |
! !
|
|
95 |
|
|
96 |
!Depth24Image methodsFor:'accessing'!
|
1
|
97 |
|
|
98 |
atX:x y:y
|
|
99 |
"retrieve a pixel at x/y; return a color.
|
|
100 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
101 |
x = width-1, y=height-1 for lower right pixel"
|
|
102 |
|
38
|
103 |
|index "{ Class: SmallInteger }"
|
|
104 |
rVal gVal bVal|
|
1
|
105 |
|
|
106 |
index := 1 + (((width * y) + x) * 3).
|
|
107 |
rVal := bytes at:(index).
|
|
108 |
gVal := bytes at:(index + 1).
|
|
109 |
bVal := bytes at:(index + 2).
|
|
110 |
|
|
111 |
photometric ~~ #rgb ifTrue:[
|
81
|
112 |
self error:'format not supported'.
|
|
113 |
^ nil
|
1
|
114 |
].
|
|
115 |
^ Color red:rVal * 100 / 255
|
81
|
116 |
green:gVal * 100 / 255
|
|
117 |
blue:bVal * 100 / 255
|
1
|
118 |
!
|
|
119 |
|
89
|
120 |
atX:x y:y put:aColor
|
|
121 |
"set the pixel at x/y to aColor.
|
|
122 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
123 |
x = width-1, y=height-1 for lower right pixel."
|
|
124 |
|
|
125 |
|index "{ Class: SmallInteger }"
|
|
126 |
val "{ Class: SmallInteger }" |
|
|
127 |
|
|
128 |
index := 1 + (((width * y) + x) * 3).
|
|
129 |
val := (aColor red / 100 * 255) rounded.
|
|
130 |
bytes at:(index) put:val.
|
|
131 |
val := (aColor green / 100 * 255) rounded.
|
|
132 |
bytes at:(index + 1) put:val.
|
|
133 |
val := (aColor blue / 100 * 255) rounded.
|
|
134 |
bytes at:(index + 2) put:val.
|
|
135 |
!
|
|
136 |
|
1
|
137 |
valueAtX:x y:y
|
|
138 |
"retrieve a pixel at x/y; return a color.
|
|
139 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
140 |
x = width-1, y=height-1 for lower right pixel"
|
|
141 |
|
|
142 |
|index "{ Class: SmallInteger }"
|
|
143 |
rVal "{ Class: SmallInteger }"
|
|
144 |
gVal "{ Class: SmallInteger }"
|
|
145 |
bVal "{ Class: SmallInteger }"|
|
|
146 |
|
|
147 |
index := 1 + (((width * y) + x) * 3).
|
|
148 |
rVal := bytes at:(index).
|
|
149 |
gVal := bytes at:(index + 1).
|
|
150 |
bVal := bytes at:(index + 2).
|
|
151 |
^ (((rVal bitShift:8) bitOr:gVal) bitShift:8) bitOr:bVal
|
|
152 |
!
|
|
153 |
|
|
154 |
atX:x y:y putValue:aPixelValue
|
|
155 |
"set a pixel at x/y to aPixelValue, which is 24 bits RGB.
|
|
156 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
157 |
x = width-1, y=height-1 for lower right pixel"
|
|
158 |
|
|
159 |
|index "{ Class: SmallInteger }"
|
|
160 |
val "{ Class: SmallInteger }" |
|
|
161 |
|
|
162 |
index := 1 + (((width * y) + x) * 3).
|
|
163 |
val := aPixelValue.
|
|
164 |
bytes at:(index + 2) put:(val bitAnd:16rFF).
|
|
165 |
val := val bitShift:-8.
|
|
166 |
bytes at:(index + 1) put:(val bitAnd:16rFF).
|
|
167 |
val := val bitShift:-8.
|
|
168 |
bytes at:(index) put:val.
|
81
|
169 |
! !
|
|
170 |
|
89
|
171 |
!Depth24Image methodsFor:'enumerating'!
|
81
|
172 |
|
|
173 |
valueAtY:y from:xLow to:xHigh do:aBlock
|
|
174 |
"perform aBlock for each pixelValue from x1 to x2 in row y.
|
|
175 |
The block is passed the pixelValue at each pixel.
|
|
176 |
This method allows slighly faster processing of an
|
|
177 |
image than using valueAtX:y:, since some processing can be
|
|
178 |
avoided when going from pixel to pixel. However, for
|
|
179 |
real image processing, specialized methods should be written.
|
|
180 |
Notice that the pixelValue is the r/g/b value packed into an integer
|
|
181 |
(r bitShift:16) bitOr:(g bitSHift:8) bitOr:b"
|
|
182 |
|
|
183 |
|srcIndex "{ Class: SmallInteger }"
|
|
184 |
x1 "{ Class: SmallInteger }"
|
|
185 |
x2 "{ Class: SmallInteger }"
|
|
186 |
r "{ Class: SmallInteger }"
|
|
187 |
g "{ Class: SmallInteger }"
|
|
188 |
b "{ Class: SmallInteger }"|
|
|
189 |
|
|
190 |
x1 := xLow.
|
|
191 |
x2 := xHigh.
|
|
192 |
|
|
193 |
srcIndex := 1 + (((width * y) + x1) * 3).
|
|
194 |
|
|
195 |
x1 to:x2 do:[:x |
|
|
196 |
r := bytes at:(srcIndex).
|
|
197 |
g := bytes at:(srcIndex + 1).
|
|
198 |
b := bytes at:(srcIndex + 2).
|
|
199 |
srcIndex := srcIndex + 3.
|
|
200 |
aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
|
|
201 |
]
|
1
|
202 |
!
|
|
203 |
|
|
204 |
atY:y from:xLow to:xHigh do:aBlock
|
|
205 |
"perform aBlock for each pixel from x1 to x2 in row y.
|
|
206 |
The block is passed the color at each pixel.
|
|
207 |
This method allows slighly faster processing of an
|
|
208 |
image than using atX:y:, since some processing can be
|
|
209 |
avoided when going from pixel to pixel. However, for
|
|
210 |
real image processing, specialized methods should be written."
|
|
211 |
|
|
212 |
|srcIndex "{ Class: SmallInteger }"
|
|
213 |
x1 "{ Class: SmallInteger }"
|
|
214 |
x2 "{ Class: SmallInteger }"
|
|
215 |
rVal "{ Class: SmallInteger }"
|
|
216 |
gVal "{ Class: SmallInteger }"
|
|
217 |
bVal "{ Class: SmallInteger }"
|
|
218 |
lastR lastG lastB lastColor|
|
|
219 |
|
|
220 |
photometric ~~ #rgb ifTrue:[
|
81
|
221 |
self error:'format not supported'.
|
|
222 |
^ nil
|
1
|
223 |
].
|
|
224 |
|
|
225 |
x1 := xLow.
|
|
226 |
x2 := xHigh.
|
|
227 |
|
|
228 |
srcIndex := 1 + (((width * y) + x1) * 3).
|
|
229 |
|
|
230 |
x1 to:x2 do:[:x |
|
81
|
231 |
rVal := bytes at:(srcIndex).
|
|
232 |
gVal := bytes at:(srcIndex + 1).
|
|
233 |
bVal := bytes at:(srcIndex + 2).
|
|
234 |
srcIndex := srcIndex + 3.
|
|
235 |
(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
|
|
236 |
lastColor := Color red:rVal * 100 / 255
|
|
237 |
green:gVal * 100 / 255
|
|
238 |
blue:bVal * 100 / 255.
|
|
239 |
lastR := rVal.
|
|
240 |
lastG := gVal.
|
|
241 |
lastB := bVal.
|
|
242 |
].
|
|
243 |
aBlock value:x value:lastColor
|
1
|
244 |
]
|
|
245 |
! !
|
|
246 |
|
|
247 |
!Depth24Image methodsFor:'converting rgb images'!
|
|
248 |
|
|
249 |
rgbImageAsGreyFormOn:aDevice
|
|
250 |
"convert an rgb image to a grey image for greyscale displays"
|
|
251 |
|
|
252 |
|deviceDepth|
|
|
253 |
|
|
254 |
deviceDepth := aDevice depth.
|
|
255 |
|
|
256 |
"I have specially tuned methods for monochrome"
|
|
257 |
(deviceDepth == 1) ifTrue:[
|
81
|
258 |
DitherAlgorithm == #error ifTrue:[
|
|
259 |
^ self rgbImageAsErrorDitheredGreyFormOn:aDevice
|
|
260 |
].
|
|
261 |
DitherAlgorithm == #pattern ifTrue:[
|
|
262 |
^ self rgbImageAsPatternDitheredGreyFormOn:aDevice
|
|
263 |
].
|
|
264 |
^ self rgbImageAsMonoFormOn:aDevice
|
1
|
265 |
].
|
|
266 |
|
|
267 |
"and for 2plane greyscale (i.e. NeXTs)"
|
|
268 |
(deviceDepth == 2) ifTrue:[
|
81
|
269 |
DitherAlgorithm == #error ifTrue:[
|
|
270 |
^ self rgbImageAsErrorDitheredGreyFormOn:aDevice
|
|
271 |
].
|
|
272 |
DitherAlgorithm == #pattern ifTrue:[
|
|
273 |
^ self rgbImageAsPatternDitheredGreyFormOn:aDevice
|
|
274 |
].
|
|
275 |
^ self rgbImageAs2PlaneFormOn:aDevice
|
1
|
276 |
].
|
|
277 |
|
|
278 |
(deviceDepth == 8) ifTrue:[
|
81
|
279 |
^ self rgbImageAs8BitGreyFormOn:aDevice
|
1
|
280 |
].
|
|
281 |
|
|
282 |
"mhmh need another converter ...
|
|
283 |
till then we do:"
|
|
284 |
DitherAlgorithm == #error ifTrue:[
|
81
|
285 |
^ self rgbImageAsErrorDitheredGreyFormOn:aDevice
|
1
|
286 |
].
|
|
287 |
DitherAlgorithm == #pattern ifTrue:[
|
81
|
288 |
^ self rgbImageAsPatternDitheredGreyFormOn:aDevice
|
1
|
289 |
].
|
|
290 |
^ self rgbImageAsMonoFormOn:aDevice
|
|
291 |
!
|
|
292 |
|
|
293 |
rgbImageAsMonoFormOn:aDevice
|
|
294 |
"return a 1-bit monochrome form for aDevice from the rgb picture,
|
|
295 |
using a threshold algorithm.
|
|
296 |
(i.e. grey value < 0.5 -> black, grey value >= 0.5 -> white)."
|
|
297 |
|
|
298 |
|monoBits f
|
|
299 |
w "{ Class: SmallInteger }"
|
|
300 |
h "{ Class: SmallInteger }"
|
|
301 |
r "{ Class: SmallInteger }"
|
|
302 |
g "{ Class: SmallInteger }"
|
|
303 |
b "{ Class: SmallInteger }"
|
|
304 |
v "{ Class: SmallInteger }"
|
|
305 |
map rMap gMap bMap
|
|
306 |
srcIndex "{ Class: SmallInteger }"
|
|
307 |
dstIndex "{ Class: SmallInteger }"
|
|
308 |
bits "{ Class: SmallInteger }"
|
|
309 |
bitCount "{ Class: SmallInteger }"
|
89
|
310 |
failed |
|
1
|
311 |
|
|
312 |
w := width.
|
|
313 |
h := height.
|
|
314 |
monoBits := ByteArray uninitializedNew:(((w + 7) // 8) * h).
|
89
|
315 |
failed := true.
|
1
|
316 |
%{
|
|
317 |
register unsigned char *srcPtr, *dstPtr;
|
|
318 |
register _v, _bits, _bitCount;
|
|
319 |
register j;
|
|
320 |
register i;
|
|
321 |
extern OBJ ByteArray;
|
|
322 |
|
89
|
323 |
if (__isByteArray(_INST(bytes))
|
|
324 |
&& __isByteArray(monoBits)) {
|
|
325 |
failed = false;
|
81
|
326 |
srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
|
|
327 |
dstPtr = _ByteArrayInstPtr(monoBits)->ba_element;
|
|
328 |
for (i=_intVal(h); i>0; i--) {
|
|
329 |
_bitCount = 0;
|
|
330 |
_bits = 0;
|
|
331 |
for (j=_intVal(w); j>0; j--) {
|
|
332 |
_bits <<= 1;
|
1
|
333 |
|
81
|
334 |
_v = (*srcPtr++ * 3); /* 0.3*r + 0.6*g + b */
|
|
335 |
_v += (*srcPtr++ * 6);
|
|
336 |
_v += *srcPtr++;
|
|
337 |
_v /= 10;
|
|
338 |
if (_v & 0x80)
|
|
339 |
_bits |= 1;
|
1
|
340 |
|
81
|
341 |
_bitCount++;
|
|
342 |
if (_bitCount == 8) {
|
|
343 |
*dstPtr++ = _bits;
|
|
344 |
_bits = 0;
|
|
345 |
_bitCount = 0;
|
|
346 |
}
|
|
347 |
}
|
|
348 |
if (_bitCount != 0) {
|
|
349 |
while (_bitCount++ != 8) _bits <<= 1;
|
|
350 |
*dstPtr++ = _bits;
|
|
351 |
}
|
|
352 |
}
|
1
|
353 |
}
|
89
|
354 |
%}.
|
1
|
355 |
|
89
|
356 |
failed ifTrue:[
|
|
357 |
"/ the above is equivalent to:
|
|
358 |
"/
|
|
359 |
"/ srcIndex := 1.
|
|
360 |
"/ dstIndex := 1.
|
|
361 |
"/ 1 to:h do:[:row |
|
|
362 |
"/ bitCount := 0.
|
|
363 |
"/ bits := 0.
|
|
364 |
"/ 1 to:w do:[:col |
|
|
365 |
"/ bits := bits bitShift:1.
|
|
366 |
"/
|
|
367 |
"/ r := bytes at:srcIndex.
|
|
368 |
"/ srcIndex := srcIndex + 1.
|
|
369 |
"/ g := bytes at:srcIndex.
|
|
370 |
"/ srcIndex := srcIndex + 1.
|
|
371 |
"/ b := bytes at:srcIndex.
|
|
372 |
"/ srcIndex := srcIndex + 1.
|
|
373 |
"/ v := ((3 * r) + (6 * g) + (1 * b)) // 10.
|
|
374 |
"/ ((v bitAnd:16r80) == 0) ifFalse:[
|
|
375 |
"/ bits := bits bitOr:1
|
|
376 |
"/ ].
|
|
377 |
"/ bitCount := bitCount + 1.
|
|
378 |
"/ (bitCount == 8) ifTrue:[
|
|
379 |
"/ monoBits at:dstIndex put:bits.
|
|
380 |
"/ dstIndex := dstIndex + 1.
|
|
381 |
"/ bits := 0.
|
|
382 |
"/ bitCount := 0
|
|
383 |
"/ ]
|
|
384 |
"/ ].
|
|
385 |
"/ (bitCount ~~ 0) ifTrue:[
|
|
386 |
"/ [bitCount == 8] whileFalse:[
|
|
387 |
"/ bitCount := bitCount + 1.
|
|
388 |
"/ bits := bits bitShift:1.
|
|
389 |
"/ ].
|
|
390 |
"/ monoBits at:dstIndex put:bits.
|
|
391 |
"/ dstIndex := dstIndex + 1
|
|
392 |
"/ ]
|
|
393 |
"/ ]
|
|
394 |
self primitiveFailed.
|
|
395 |
^ nil
|
1
|
396 |
].
|
|
397 |
|
|
398 |
f := Form width:w height:h depth:1 on:aDevice.
|
|
399 |
f isNil ifTrue:[^ nil].
|
|
400 |
f initGC.
|
|
401 |
(aDevice blackpixel == 0) ifFalse:[
|
81
|
402 |
"have to invert bits"
|
|
403 |
f function:#copyInverted
|
1
|
404 |
].
|
|
405 |
aDevice drawBits:monoBits depth:1 width:w height:h
|
81
|
406 |
x:0 y:0
|
|
407 |
into:(f id) x:0 y:0 width:w height:h with:(f gcId).
|
1
|
408 |
^ f
|
|
409 |
!
|
|
410 |
|
|
411 |
rgbImageAs2PlaneFormOn:aDevice
|
|
412 |
"return a 2-bit device form for aDevice from the rgb picture,
|
|
413 |
using a threshold algorithm.
|
|
414 |
(i.e. grey value < 0.25 -> black // 0.25..0.5 -> darkgrey //
|
|
415 |
0.5 .. 0.75 -> lightgrey // > 0.75 -> white)."
|
|
416 |
|
|
417 |
|twoPlaneBits f
|
|
418 |
map rMap gMap bMap
|
89
|
419 |
failed
|
1
|
420 |
r "{ Class: SmallInteger }"
|
|
421 |
g "{ Class: SmallInteger }"
|
|
422 |
b "{ Class: SmallInteger }"
|
|
423 |
v "{ Class: SmallInteger }"
|
|
424 |
w "{ Class: SmallInteger }"
|
|
425 |
h "{ Class: SmallInteger }"
|
|
426 |
srcIndex "{ Class: SmallInteger }"
|
|
427 |
dstIndex "{ Class: SmallInteger }"
|
|
428 |
bits "{ Class: SmallInteger }"
|
|
429 |
bitCount "{ Class: SmallInteger }" |
|
|
430 |
|
|
431 |
w := width.
|
|
432 |
h := height.
|
|
433 |
twoPlaneBits := ByteArray uninitializedNew:(((w * 2 + 7) // 8) * h).
|
|
434 |
|
89
|
435 |
failed := true.
|
1
|
436 |
%{
|
|
437 |
register unsigned char *srcPtr, *dstPtr;
|
|
438 |
register _v, _bits, _bitCount;
|
|
439 |
register j;
|
|
440 |
register i;
|
|
441 |
extern OBJ ByteArray;
|
|
442 |
|
|
443 |
if ((_Class(_INST(bytes)) == ByteArray)
|
|
444 |
&& (_Class(twoPlaneBits) == ByteArray)) {
|
89
|
445 |
failed = false;
|
81
|
446 |
srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
|
|
447 |
dstPtr = _ByteArrayInstPtr(twoPlaneBits)->ba_element;
|
|
448 |
for (i=_intVal(h); i>0; i--) {
|
|
449 |
_bitCount = 0;
|
|
450 |
_bits = 0;
|
|
451 |
for (j=_intVal(w); j>0; j--) {
|
|
452 |
_v = (*srcPtr++ * 3); /* 0.3*r + 0.6*g + b */
|
|
453 |
_v += (*srcPtr++ * 6);
|
|
454 |
_v += *srcPtr++;
|
|
455 |
_v /= 10;
|
|
456 |
_bits <<= 2;
|
|
457 |
_bits |= (_v >> 6); /* take top 2 bits */
|
|
458 |
_bitCount++;
|
|
459 |
if (_bitCount == 4) {
|
|
460 |
*dstPtr++ = _bits;
|
|
461 |
_bits = 0;
|
|
462 |
_bitCount = 0;
|
|
463 |
}
|
|
464 |
}
|
|
465 |
if (_bitCount != 0) {
|
|
466 |
while (_bitCount++ != 4) _bits <<= 2;
|
|
467 |
*dstPtr++ = _bits;
|
|
468 |
}
|
|
469 |
}
|
1
|
470 |
}
|
89
|
471 |
%}.
|
|
472 |
failed ifTrue:[
|
|
473 |
"/ the above is equivalent to:
|
|
474 |
"/
|
|
475 |
"/ srcIndex := 1.
|
|
476 |
"/ dstIndex := 1.
|
|
477 |
"/ 1 to:h do:[:row |
|
|
478 |
"/ bitCount := 0.
|
|
479 |
"/ bits := 0.
|
|
480 |
"/ 1 to:w do:[:col |
|
|
481 |
"/ r := bytes at:srcIndex.
|
|
482 |
"/ srcIndex := srcIndex + 1.
|
|
483 |
"/ g := bytes at:srcIndex.
|
|
484 |
"/ srcIndex := srcIndex + 1.
|
|
485 |
"/ b := bytes at:srcIndex.
|
|
486 |
"/ srcIndex := srcIndex + 1.
|
|
487 |
"/ v := ((3 * r) + (6 * g) + (1 * b)) // 10.
|
|
488 |
"/ v := v bitShift:-6. "take 2 hi bits"
|
|
489 |
"/ bits := (bits bitShift:2) bitOr:v.
|
|
490 |
"/ bitCount := bitCount + 1.
|
|
491 |
"/ (bitCount == 4) ifTrue:[
|
|
492 |
"/ twoPlaneBits at:dstIndex put:bits.
|
|
493 |
"/ dstIndex := dstIndex + 1.
|
|
494 |
"/ bits := 0.
|
|
495 |
"/ bitCount := 0
|
|
496 |
"/ ]
|
|
497 |
"/ ].
|
|
498 |
"/ (bitCount ~~ 0) ifTrue:[
|
|
499 |
"/ [bitCount == 4] whileFalse:[
|
|
500 |
"/ bitCount := bitCount + 1.
|
|
501 |
"/ bits := bits bitShift:2.
|
|
502 |
"/ ].
|
|
503 |
"/ twoPlaneBits at:dstIndex put:bits.
|
|
504 |
"/ dstIndex := dstIndex + 1
|
|
505 |
"/ ]
|
|
506 |
"/ ]
|
|
507 |
self primitiveFailed.
|
|
508 |
^ nil
|
1
|
509 |
].
|
|
510 |
|
|
511 |
f := Form width:width height:height depth:2 on:aDevice.
|
|
512 |
f isNil ifTrue:[^ nil].
|
|
513 |
f initGC.
|
|
514 |
(aDevice blackpixel == 0) ifFalse:[
|
81
|
515 |
"have to invert bits"
|
|
516 |
f function:#copyInverted
|
1
|
517 |
].
|
|
518 |
aDevice drawBits:twoPlaneBits depth:2 width:width height:height
|
81
|
519 |
x:0 y:0
|
|
520 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId).
|
1
|
521 |
^ f
|
|
522 |
!
|
|
523 |
|
|
524 |
rgbImageAs8BitGreyFormOn:aDevice
|
|
525 |
"return an 8-bit greyForm from the rgb picture"
|
|
526 |
|
|
527 |
|greyBits f v
|
|
528 |
srcIndex "{ Class: SmallInteger }"
|
|
529 |
dstIndex "{ Class: SmallInteger }"
|
89
|
530 |
failed|
|
1
|
531 |
|
|
532 |
greyBits := ByteArray uninitializedNew:(width * height).
|
89
|
533 |
failed := false.
|
1
|
534 |
%{
|
|
535 |
register unsigned char *srcPtr, *dstPtr;
|
|
536 |
register _v;
|
|
537 |
register j;
|
|
538 |
register i;
|
|
539 |
extern OBJ ByteArray;
|
|
540 |
|
|
541 |
if ((_Class(_INST(bytes)) == ByteArray)
|
|
542 |
&& (_Class(greyBits) == ByteArray)) {
|
89
|
543 |
failed = false;
|
81
|
544 |
srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
|
|
545 |
dstPtr = _ByteArrayInstPtr(greyBits)->ba_element;
|
|
546 |
for (i=_intVal(_INST(height)); i>0; i--) {
|
|
547 |
for (j=_intVal(_INST(width)); j>0; j--) {
|
|
548 |
_v = (*srcPtr * 3); /* 0.3*r + 0.6*g + b */
|
|
549 |
_v += (*srcPtr++ * 6);
|
|
550 |
_v += *srcPtr++;
|
|
551 |
_v /= 10;
|
|
552 |
*dstPtr++ = _v >> 4 ;
|
|
553 |
}
|
|
554 |
}
|
1
|
555 |
}
|
|
556 |
%}
|
|
557 |
.
|
89
|
558 |
failed ifTrue:[
|
|
559 |
"/ the above is equivalent to:
|
|
560 |
"/
|
|
561 |
"/ srcIndex := 1.
|
|
562 |
"/ dstIndex := 1.
|
|
563 |
"/
|
|
564 |
"/ 1 to:height do:[:h |
|
|
565 |
"/ 1 to:width do:[:w |
|
|
566 |
"/ |v
|
|
567 |
"/ r "{ Class: SmallInteger }"
|
|
568 |
"/ g "{ Class: SmallInteger }"
|
|
569 |
"/ b "{ Class: SmallInteger }"|
|
|
570 |
"/
|
|
571 |
"/ r := bytes at:srcIndex.
|
|
572 |
"/ srcIndex := srcIndex + 1.
|
|
573 |
"/ g := bytes at:srcIndex.
|
|
574 |
"/ srcIndex := srcIndex + 1.
|
|
575 |
"/ b := bytes at:srcIndex.
|
|
576 |
"/ srcIndex := srcIndex + 1.
|
|
577 |
"/
|
|
578 |
"/ v := ((3 * r) + (6 * g) + (1 * b)) // 10.
|
|
579 |
"/ v := v bitShift:-4.
|
|
580 |
"/ greyBits at:dstIndex put:v.
|
|
581 |
"/ dstIndex := dstIndex + 1
|
|
582 |
"/ ]
|
|
583 |
"/ ]
|
|
584 |
self primitiveFailed.
|
|
585 |
^ nil
|
1
|
586 |
].
|
|
587 |
|
|
588 |
f := Form width:width height:height depth:8 on:aDevice.
|
|
589 |
f isNil ifTrue:[^ nil].
|
|
590 |
f initGC.
|
|
591 |
aDevice drawBits:greyBits depth:8 width:width height:height
|
81
|
592 |
x:0 y:0
|
|
593 |
into:(f id) x:0 y:0
|
|
594 |
width:width height:height with:(f gcId).
|
1
|
595 |
^ f
|
|
596 |
!
|
|
597 |
|
|
598 |
rgbImageAsPatternDitheredGreyFormOn:aDevice
|
|
599 |
"return a dithered greyForm for aDevice from the palette picture.
|
|
600 |
works for any destination depth.
|
|
601 |
A slow algorithm, using draw into the form (which indirectly does
|
|
602 |
the dither) - should be rewritten."
|
|
603 |
|
|
604 |
|f depth
|
|
605 |
nDither "{Class: SmallInteger }"
|
|
606 |
nColors "{Class: SmallInteger }"
|
|
607 |
v "{Class: SmallInteger }"
|
|
608 |
h "{Class: SmallInteger }"
|
|
609 |
w "{Class: SmallInteger }"
|
|
610 |
srcIndex "{Class: SmallInteger }"
|
|
611 |
dstIndex "{Class: SmallInteger }"
|
|
612 |
mask "{Class: SmallInteger }"
|
|
613 |
outBits "{Class: SmallInteger }"
|
|
614 |
outCount "{Class: SmallInteger }"
|
|
615 |
patternOffset "{Class: SmallInteger }"
|
|
616 |
patternBits "{Class: SmallInteger }"
|
|
617 |
run "{Class: SmallInteger }"
|
|
618 |
r "{Class: SmallInteger }"
|
|
619 |
g "{Class: SmallInteger }"
|
|
620 |
b "{Class: SmallInteger }"
|
|
621 |
index "{Class: SmallInteger }"
|
|
622 |
p0 "{Class: SmallInteger }"
|
|
623 |
p1 "{Class: SmallInteger }"
|
|
624 |
map last clr
|
|
625 |
patterns formBytes patternBytes
|
|
626 |
pixel0bytes pixel1bytes ditherPattern
|
|
627 |
ditherColors first delta|
|
|
628 |
|
|
629 |
Transcript showCr:'dithering ..'. Transcript endEntry.
|
|
630 |
|
|
631 |
h := height.
|
|
632 |
w := width.
|
|
633 |
|
|
634 |
nDither := NumberOfDitherColors.
|
|
635 |
ditherColors := Array new:nDither.
|
|
636 |
|
|
637 |
first := (100 / nDither / 2).
|
|
638 |
delta := 100 / nDither.
|
|
639 |
0 to:nDither-1 do:[:i |
|
81
|
640 |
ditherColors at:i+1 put:(Color grey:(i * delta + first)).
|
1
|
641 |
].
|
|
642 |
|
|
643 |
nColors := 256.
|
|
644 |
map := Array new:256.
|
|
645 |
1 to:256 do:[:i |
|
81
|
646 |
v := i - 1.
|
|
647 |
" v is now in the range 0 .. 255 "
|
|
648 |
v := (v * (nDither - 1) // 255) rounded.
|
|
649 |
" v is now 0 .. nDither-1 "
|
|
650 |
map at:i put:(ditherColors at:(v + 1))
|
1
|
651 |
].
|
|
652 |
|
|
653 |
"tuning - code below is so slooow"
|
|
654 |
|
|
655 |
"get the patterns, fill form bytes here"
|
|
656 |
|
|
657 |
w := width.
|
|
658 |
h := height.
|
|
659 |
|
|
660 |
depth := aDevice depth.
|
|
661 |
depth == 1 ifTrue:[
|
81
|
662 |
formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h.
|
|
663 |
patterns := Array new:nColors.
|
|
664 |
pixel0bytes := ByteArray uninitializedNew:nColors.
|
|
665 |
pixel1bytes := ByteArray uninitializedNew:nColors.
|
1
|
666 |
|
81
|
667 |
"extract dither patterns and values to use for 1/0 bits
|
|
668 |
in those from the dithercolors"
|
1
|
669 |
|
81
|
670 |
1 to:nColors do:[:i |
|
|
671 |
clr := (map at:i) on:aDevice.
|
|
672 |
ditherPattern := clr ditherForm.
|
1
|
673 |
|
81
|
674 |
ditherPattern isNil ifTrue:[
|
|
675 |
patterns at:i put:#[2r11111111
|
|
676 |
2r11111111
|
|
677 |
2r11111111
|
|
678 |
2r11111111
|
|
679 |
2r11111111
|
|
680 |
2r11111111
|
|
681 |
2r11111111
|
|
682 |
2r11111111].
|
|
683 |
pixel0bytes at:i put:clr colorId.
|
|
684 |
pixel1bytes at:i put:clr colorId
|
|
685 |
] ifFalse:[
|
|
686 |
patterns at:i put:(ditherPattern bits).
|
|
687 |
pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
|
|
688 |
pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
|
|
689 |
].
|
|
690 |
].
|
1
|
691 |
|
81
|
692 |
srcIndex := 1.
|
|
693 |
dstIndex := 1.
|
|
694 |
mask := 16r80.
|
|
695 |
outBits := 0.
|
|
696 |
patternOffset := 1.
|
|
697 |
1 to:h do:[:dstY |
|
|
698 |
last := nil.
|
|
699 |
1 to:w do:[:dstX |
|
|
700 |
r := bytes at:srcIndex.
|
|
701 |
g := bytes at:(srcIndex + 1).
|
|
702 |
b := bytes at:(srcIndex + 2).
|
|
703 |
srcIndex := srcIndex + 3.
|
1
|
704 |
|
81
|
705 |
v := ((3 * r) + (6 * g) + (1 * b)). "pixel grey value (*10)"
|
|
706 |
v == last ifFalse:[
|
|
707 |
index := v // 10 + 1. "index into map"
|
1
|
708 |
|
81
|
709 |
patternBytes := patterns at:index. "dither pattern for color"
|
|
710 |
patternBits := patternBytes at:patternOffset. "dither row"
|
|
711 |
p0 := pixel0bytes at:index. "value for 0-dither bit"
|
|
712 |
p1 := pixel1bytes at:index. "value for 1-dither bit"
|
|
713 |
last := v.
|
|
714 |
].
|
|
715 |
outBits := outBits bitShift:1.
|
1
|
716 |
|
81
|
717 |
(patternBits bitAnd:mask) == 0 ifTrue:[
|
|
718 |
outBits := outBits bitOr:p0.
|
|
719 |
] ifFalse:[
|
|
720 |
outBits := outBits bitOr:p1
|
|
721 |
].
|
|
722 |
mask := mask bitShift:-1.
|
|
723 |
mask == 0 ifTrue:[
|
|
724 |
mask := 16r80.
|
|
725 |
formBytes at:dstIndex put:outBits.
|
|
726 |
dstIndex := dstIndex + 1.
|
|
727 |
outBits := 0
|
|
728 |
]
|
|
729 |
].
|
|
730 |
mask == 16r80 ifFalse:[
|
|
731 |
[mask == 0] whileFalse:[
|
|
732 |
mask := mask bitShift:-1.
|
|
733 |
outBits := outBits bitShift:1.
|
|
734 |
].
|
|
735 |
formBytes at:dstIndex put:outBits.
|
|
736 |
dstIndex := dstIndex + 1.
|
|
737 |
mask := 16r80.
|
|
738 |
outBits := 0
|
|
739 |
].
|
|
740 |
patternOffset := patternOffset + 1.
|
|
741 |
patternOffset == 9 ifTrue:[
|
|
742 |
patternOffset := 1
|
|
743 |
]
|
|
744 |
].
|
|
745 |
f := Form width:w height:h fromArray:formBytes.
|
|
746 |
^ f
|
1
|
747 |
].
|
|
748 |
|
|
749 |
depth == 2 ifTrue:[
|
81
|
750 |
formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h.
|
|
751 |
patterns := Array new:nColors.
|
|
752 |
pixel0bytes := ByteArray uninitializedNew:nColors.
|
|
753 |
pixel1bytes := ByteArray uninitializedNew:nColors.
|
1
|
754 |
|
81
|
755 |
"extract dither patterns and values to use for 1/0 bits
|
|
756 |
in those from the dithercolors"
|
1
|
757 |
|
81
|
758 |
1 to:nColors do:[:i |
|
|
759 |
clr := (map at:i) on:aDevice.
|
|
760 |
ditherPattern := clr ditherForm.
|
1
|
761 |
|
81
|
762 |
ditherPattern isNil ifTrue:[
|
|
763 |
patterns at:i put:#[2r11111111
|
|
764 |
2r11111111
|
|
765 |
2r11111111
|
|
766 |
2r11111111
|
|
767 |
2r11111111
|
|
768 |
2r11111111
|
|
769 |
2r11111111
|
|
770 |
2r11111111].
|
|
771 |
pixel0bytes at:i put:clr colorId.
|
|
772 |
pixel1bytes at:i put:clr colorId
|
|
773 |
] ifFalse:[
|
|
774 |
patterns at:i put:(ditherPattern bits).
|
|
775 |
pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
|
|
776 |
pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
|
|
777 |
].
|
|
778 |
].
|
1
|
779 |
|
81
|
780 |
srcIndex := 1.
|
|
781 |
dstIndex := 1.
|
|
782 |
mask := 16r80.
|
|
783 |
outBits := 0.
|
|
784 |
patternOffset := 1.
|
|
785 |
1 to:h do:[:dstY |
|
|
786 |
last := nil.
|
|
787 |
outCount := 0.
|
|
788 |
mask := 16r80.
|
|
789 |
outBits := 0.
|
|
790 |
1 to:w do:[:dstX |
|
|
791 |
r := bytes at:srcIndex.
|
|
792 |
srcIndex := srcIndex + 1.
|
|
793 |
g := bytes at:srcIndex.
|
|
794 |
srcIndex := srcIndex + 1.
|
|
795 |
b := bytes at:srcIndex.
|
|
796 |
srcIndex := srcIndex + 1.
|
1
|
797 |
|
81
|
798 |
v := ((3 * r) + (6 * g) + (1 * b)). "pixel grey value (*10)"
|
|
799 |
v == last ifFalse:[
|
|
800 |
index := v // 10 + 1. "index into map"
|
1
|
801 |
|
81
|
802 |
patternBytes := patterns at:index. "dither pattern for color"
|
|
803 |
patternBits := patternBytes at:patternOffset. "dither row"
|
|
804 |
p0 := pixel0bytes at:index. "value for 0-dither bit"
|
|
805 |
p1 := pixel1bytes at:index. "value for 1-dither bit"
|
|
806 |
last := v.
|
|
807 |
].
|
|
808 |
outBits := outBits bitShift:2.
|
1
|
809 |
|
81
|
810 |
(patternBits bitAnd:mask) == 0 ifTrue:[
|
|
811 |
outBits := outBits bitOr:p0.
|
|
812 |
] ifFalse:[
|
|
813 |
outBits := outBits bitOr:p1
|
|
814 |
].
|
|
815 |
mask := mask bitShift:-1.
|
|
816 |
outCount := outCount + 1.
|
|
817 |
outCount == 4 ifTrue:[
|
|
818 |
formBytes at:dstIndex put:outBits.
|
|
819 |
dstIndex := dstIndex + 1.
|
|
820 |
outBits := 0.
|
|
821 |
outCount := 0.
|
|
822 |
mask == 0 ifTrue:[
|
|
823 |
mask := 16r80.
|
|
824 |
]
|
|
825 |
]
|
|
826 |
].
|
|
827 |
(outCount == 0) ifFalse:[
|
|
828 |
[outCount == 4] whileFalse:[
|
|
829 |
outCount := outCount + 1.
|
|
830 |
outBits := outBits bitShift:2.
|
|
831 |
].
|
|
832 |
formBytes at:dstIndex put:outBits.
|
|
833 |
dstIndex := dstIndex + 1.
|
|
834 |
].
|
|
835 |
patternOffset := patternOffset + 1.
|
|
836 |
patternOffset == 9 ifTrue:[
|
|
837 |
patternOffset := 1
|
|
838 |
]
|
|
839 |
].
|
|
840 |
f := Form width:w height:h depth:depth.
|
|
841 |
f initGC.
|
|
842 |
f device drawBits:formBytes depth:2
|
|
843 |
width:w height:h x:0 y:0
|
|
844 |
into:f id x:0 y:0 width:w height:h with:f gcId.
|
|
845 |
^ f
|
1
|
846 |
].
|
|
847 |
|
|
848 |
"draw each pixel using dither color (let others do the dithering)
|
|
849 |
although the code is simple, its very slow"
|
|
850 |
|
|
851 |
f := Form width:w height:h depth:(aDevice depth) on:aDevice.
|
|
852 |
f isNil ifTrue:[^ nil].
|
|
853 |
f initGC.
|
|
854 |
"draw each pixel using dither color"
|
|
855 |
|
|
856 |
srcIndex := 1.
|
|
857 |
0 to:h-1 do:[:dstY |
|
81
|
858 |
run := 0.
|
|
859 |
last := nil.
|
|
860 |
0 to:w-1 do:[:dstX |
|
|
861 |
r := bytes at:srcIndex.
|
|
862 |
srcIndex := srcIndex + 1.
|
|
863 |
g := bytes at:srcIndex.
|
|
864 |
srcIndex := srcIndex + 1.
|
|
865 |
b := bytes at:srcIndex.
|
|
866 |
srcIndex := srcIndex + 1.
|
1
|
867 |
|
81
|
868 |
v := ((3 * r) + (6 * g) + (1 * b)) // 10.
|
1
|
869 |
|
81
|
870 |
clr := map at:(v + 1).
|
1
|
871 |
|
81
|
872 |
clr == last ifTrue:[
|
|
873 |
run := run + 1
|
|
874 |
] ifFalse:[
|
|
875 |
(run ~~ 0) ifTrue:[
|
|
876 |
f fillRectangleX:dstX-run y:dstY width:run height:1.
|
|
877 |
].
|
|
878 |
run := 1.
|
|
879 |
f paint:clr.
|
|
880 |
last := clr
|
|
881 |
].
|
|
882 |
].
|
|
883 |
f fillRectangleX:width-run y:dstY width:run height:1.
|
1
|
884 |
].
|
|
885 |
^ f
|
89
|
886 |
!
|
1
|
887 |
|
89
|
888 |
rgbImageAsDitheredPseudoFormOn:aDevice
|
|
889 |
"return a dithered pseudocolor form from the rgb-picture.
|
|
890 |
This method depends on fixColors being allocated (see Color>>getColors*)"
|
|
891 |
|
|
892 |
^ self rgbImageAsDitheredPseudoFormOn:aDevice
|
|
893 |
colors:Color fixColors
|
|
894 |
nRed:Color numFixRed
|
|
895 |
nGreen:Color numFixGreen
|
|
896 |
nBlue:Color numFixBlue
|
|
897 |
!
|
|
898 |
|
|
899 |
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
|
|
900 |
"return a dithered pseudocolor form from the rgb-picture"
|
|
901 |
|
|
902 |
|pseudoBits f
|
|
903 |
h "{ Class: SmallInteger }"
|
|
904 |
w "{ Class: SmallInteger }"
|
|
905 |
"/ eR "{Class: SmallInteger }"
|
|
906 |
"/ eG "{Class: SmallInteger }"
|
|
907 |
"/ eB "{Class: SmallInteger }"
|
|
908 |
"/ wantR "{Class: SmallInteger }"
|
|
909 |
"/ wantG "{Class: SmallInteger }"
|
|
910 |
"/ wantB "{Class: SmallInteger }"
|
|
911 |
fixR "{Class: SmallInteger }"
|
|
912 |
fixG "{Class: SmallInteger }"
|
|
913 |
fixB "{Class: SmallInteger }"
|
|
914 |
srcIndex "{ Class: SmallInteger }"
|
|
915 |
dstIndex "{ Class: SmallInteger }"
|
|
916 |
deviceDepth has8BitImage
|
|
917 |
fixIds failed|
|
|
918 |
|
|
919 |
aDevice ~~ Display ifTrue:[^ nil].
|
|
920 |
|
|
921 |
fixR := nRed.
|
|
922 |
fixR == 0 ifTrue:[ ^ nil].
|
|
923 |
fixG := nGreen.
|
|
924 |
fixG == 0 ifTrue:[ ^ nil].
|
|
925 |
fixB := nBlue.
|
|
926 |
fixB == 0 ifTrue:[ ^ nil].
|
|
927 |
"/ simple check
|
|
928 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[
|
|
929 |
self error:'invalid color array passed'.
|
|
930 |
^ nil
|
|
931 |
].
|
|
932 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
|
|
933 |
|
|
934 |
deviceDepth := aDevice depth.
|
|
935 |
deviceDepth == 8 ifTrue:[
|
|
936 |
has8BitImage := true.
|
|
937 |
] ifFalse:[
|
|
938 |
has8BitImage := false.
|
|
939 |
aDevice supportedImageFormats do:[:fmt |
|
|
940 |
(fmt at:2) == 8 ifTrue:[
|
|
941 |
has8BitImage := true.
|
|
942 |
]
|
|
943 |
]
|
|
944 |
].
|
|
945 |
has8BitImage ifFalse:[^ nil].
|
|
946 |
|
|
947 |
'D24IMAGE: dithering ...' errorPrintNL.
|
|
948 |
|
|
949 |
pseudoBits := ByteArray uninitializedNew:(width * height).
|
|
950 |
|
|
951 |
h := height.
|
|
952 |
w := width.
|
|
953 |
|
|
954 |
%{
|
|
955 |
int __x, __y;
|
|
956 |
int __eR, __eG, __eB;
|
|
957 |
int __wantR, __wantG, __wantB;
|
|
958 |
unsigned char *srcP, *dstP;
|
|
959 |
unsigned char *redP, *greenP, *blueP;
|
|
960 |
int pix;
|
|
961 |
unsigned char *idP;
|
|
962 |
int __fR, __fG, __fB;
|
|
963 |
int iR, iG, iB;
|
|
964 |
int idx;
|
|
965 |
|
|
966 |
if (__isByteArray(_INST(bytes))
|
|
967 |
&& __isByteArray(pseudoBits)
|
|
968 |
&& __isByteArray(fixIds)
|
|
969 |
&& _isSmallInteger(fixR)
|
|
970 |
&& _isSmallInteger(fixG)
|
|
971 |
&& _isSmallInteger(fixB)) {
|
|
972 |
failed = false;
|
|
973 |
|
|
974 |
srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
|
|
975 |
dstP = _ByteArrayInstPtr(pseudoBits)->ba_element;
|
|
976 |
idP = _ByteArrayInstPtr(fixIds)->ba_element;
|
|
977 |
__fR = _intVal(fixR)-1;
|
|
978 |
__fG = _intVal(fixG)-1;
|
|
979 |
__fB = _intVal(fixB)-1;
|
|
980 |
|
|
981 |
for (__y=_intVal(h); __y>0; __y--) {
|
|
982 |
__eR = __eG = __eB = 0;
|
|
983 |
for (__x=_intVal(w); __x>0; __x--) {
|
|
984 |
int t;
|
|
985 |
int __want;
|
|
986 |
|
|
987 |
/*
|
|
988 |
* wR, wG and wB is the wanted r/g/b value;
|
|
989 |
* compute the index into the dId table ..
|
|
990 |
* values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
|
|
991 |
*
|
|
992 |
* bad kludge: knows how to index into FixColor table
|
|
993 |
*/
|
|
994 |
__wantR = srcP[0] + __eR;
|
|
995 |
__wantG = srcP[1] + __eG;
|
|
996 |
__wantB = srcP[2] + __eB;
|
|
997 |
srcP += 3;
|
|
998 |
|
|
999 |
if (__wantR > 255) __want = 255;
|
|
1000 |
else if (__wantR < 0) __want = 0;
|
|
1001 |
else __want = __wantR;
|
|
1002 |
|
|
1003 |
iR = __want * __fR / 128;
|
|
1004 |
iR = (iR / 2) + (iR & 1);
|
|
1005 |
idx = iR * (__fG+1);
|
|
1006 |
|
|
1007 |
if (__wantG > 255) __want = 255;
|
|
1008 |
else if (__wantG < 0) __want = 0;
|
|
1009 |
else __want = __wantG;
|
|
1010 |
|
|
1011 |
iG = __want * __fG / 128;
|
|
1012 |
iG = (iG / 2) + (iG & 1);
|
|
1013 |
idx = (idx + iG) * (__fB+1);
|
|
1014 |
|
|
1015 |
if (__wantB > 255) __want = 255;
|
|
1016 |
else if (__wantB < 0) __want = 0;
|
|
1017 |
else __want = __wantB;
|
|
1018 |
|
|
1019 |
iB = __want * __fB / 128;
|
|
1020 |
iB = (iB / 2) + (iB & 1);
|
|
1021 |
idx = idx + iB;
|
|
1022 |
|
|
1023 |
/*
|
|
1024 |
* store the corresponding dither colorId
|
|
1025 |
*/
|
|
1026 |
*dstP++ = idP[idx];
|
|
1027 |
|
|
1028 |
/*
|
|
1029 |
* the new error:
|
|
1030 |
*/
|
|
1031 |
__eR = __wantR - (iR * 256 / __fR);
|
|
1032 |
__eG = __wantG - (iG * 256 / __fG);
|
|
1033 |
__eB = __wantB - (iB * 256 / __fB);
|
|
1034 |
}
|
|
1035 |
}
|
|
1036 |
}
|
|
1037 |
%}.
|
|
1038 |
failed ifTrue:[
|
|
1039 |
self primitiveFailed.
|
|
1040 |
^ nil
|
|
1041 |
|
|
1042 |
"/ for non-C programmers:
|
|
1043 |
"/ the above code is (roughly) equivalent to:
|
|
1044 |
"/ srcIndex := 1.
|
|
1045 |
"/ dstIndex := 1.
|
|
1046 |
"/ 1 to:h do:[:y |
|
|
1047 |
"/ eR := eG := eB := 0.
|
|
1048 |
"/ 1 to:w do:[:x |
|
|
1049 |
"/ |pixel "{ Class: SmallInteger }"
|
|
1050 |
"/ clr
|
|
1051 |
"/ idx "{ Class: SmallInteger }"
|
|
1052 |
"/ iR "{ Class: SmallInteger }"
|
|
1053 |
"/ iG "{ Class: SmallInteger }"
|
|
1054 |
"/ iB "{ Class: SmallInteger }"
|
|
1055 |
"/ wR "{ Class: SmallInteger }"
|
|
1056 |
"/ wG "{ Class: SmallInteger }"
|
|
1057 |
"/ wB "{ Class: SmallInteger }" |
|
|
1058 |
"/
|
|
1059 |
"/ wantR := ((bytes at:srcIndex) + eR). srcIndex := srcIndex + 1.
|
|
1060 |
"/ wantG := ((bytes at:srcIndex) + eG). srcIndex := srcIndex + 1.
|
|
1061 |
"/ wantB := ((bytes at:srcIndex) + eB). srcIndex := srcIndex + 1.
|
|
1062 |
"/ wR := wantR.
|
|
1063 |
"/ wR > 255 ifTrue:[wR := 255] ifFalse:[wR < 0 ifTrue:[wR := 0]].
|
|
1064 |
"/ wG := wantG.
|
|
1065 |
"/ wG > 255 ifTrue:[wG := 255] ifFalse:[wG < 0 ifTrue:[wG := 0]].
|
|
1066 |
"/ wB := wantB.
|
|
1067 |
"/ wB > 255 ifTrue:[wB := 255] ifFalse:[wB < 0 ifTrue:[wB := 0]].
|
|
1068 |
"/
|
|
1069 |
"/ iR := wR * (fixR-1) // 128.
|
|
1070 |
"/ iR := (iR // 2) + (iR bitAnd:1).
|
|
1071 |
"/ iG := wG * (fixG-1) // 128.
|
|
1072 |
"/ iG := (iG // 2) + (iG bitAnd:1).
|
|
1073 |
"/ iB := wB * (fixB-1) // 128.
|
|
1074 |
"/ iB := (iB // 2) + (iB bitAnd:1).
|
|
1075 |
"/ idx := (iR * fixR + iG) * fixB + iB + 1.
|
|
1076 |
"/
|
|
1077 |
"/ clr := fixColors at:idx.
|
|
1078 |
"/
|
|
1079 |
"/ eR := wantR - (clr red * 2) asInteger.
|
|
1080 |
"/ eG := wantG - (clr green * 2) asInteger.
|
|
1081 |
"/ eB := wantB - (clr blue * 2) asInteger.
|
|
1082 |
"/
|
|
1083 |
"/ pixel := clr colorId.
|
|
1084 |
"/ pseudoBits at:dstIndex put:pixel.
|
|
1085 |
"/
|
|
1086 |
"/ dstIndex := dstIndex + 1
|
|
1087 |
"/ ].
|
|
1088 |
].
|
|
1089 |
|
|
1090 |
f := Form width:width height:height depth:aDevice depth on:aDevice.
|
|
1091 |
f isNil ifTrue:[^ nil].
|
|
1092 |
f colorMap:fixColors.
|
|
1093 |
f initGC.
|
|
1094 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:aDevice depth
|
|
1095 |
width:width height:height
|
|
1096 |
x:0 y:0
|
|
1097 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId).
|
|
1098 |
^ f
|
1
|
1099 |
!
|
|
1100 |
|
|
1101 |
rgbImageAsPseudoFormOn:aDevice
|
|
1102 |
"return a pseudocolor form from the rgb-picture"
|
|
1103 |
|
|
1104 |
|pseudoBits f
|
|
1105 |
r "{ Class: SmallInteger }"
|
|
1106 |
g "{ Class: SmallInteger }"
|
|
1107 |
b "{ Class: SmallInteger }"
|
|
1108 |
srcIndex "{ Class: SmallInteger }"
|
|
1109 |
dstIndex "{ Class: SmallInteger }"
|
|
1110 |
rMask "{ Class: SmallInteger }"
|
|
1111 |
gMask "{ Class: SmallInteger }"
|
|
1112 |
bMask "{ Class: SmallInteger }"
|
|
1113 |
redArray greenArray blueArray
|
|
1114 |
dataSize "{ Class: SmallInteger }"
|
|
1115 |
nColors "{ Class: SmallInteger }"
|
|
1116 |
fit fitMap colors color
|
|
1117 |
fast
|
|
1118 |
colorIndex "{ Class: SmallInteger }"
|
89
|
1119 |
depth nColorCells deep|
|
|
1120 |
|
|
1121 |
Color fixColors notNil ifTrue:[
|
|
1122 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice.
|
|
1123 |
f notNil ifTrue:[^ f].
|
|
1124 |
].
|
1
|
1125 |
|
|
1126 |
"find used colors; build color-tree"
|
|
1127 |
|
|
1128 |
fit := false.
|
|
1129 |
fitMap := false.
|
|
1130 |
depth := aDevice depth.
|
|
1131 |
nColorCells := aDevice ncells.
|
|
1132 |
|
89
|
1133 |
deep := (depth > 8).
|
|
1134 |
|
1
|
1135 |
rMask := 2r11111111.
|
|
1136 |
gMask := 2r11111111.
|
|
1137 |
bMask := 2r11111111.
|
|
1138 |
|
89
|
1139 |
'D24IMAGE: allocating colors ...' errorPrintNL.
|
66
|
1140 |
|
1
|
1141 |
[fit] whileFalse:[
|
81
|
1142 |
[fitMap] whileFalse:[
|
|
1143 |
srcIndex := 1.
|
|
1144 |
redArray := Array new:256.
|
1
|
1145 |
|
89
|
1146 |
"
|
|
1147 |
find used colors, build [r][g][b] 3-dimensional array
|
|
1148 |
containing true for used colors
|
|
1149 |
"
|
81
|
1150 |
nColors := 0.
|
|
1151 |
srcIndex := 1.
|
|
1152 |
dataSize := bytes size.
|
|
1153 |
[srcIndex < dataSize] whileTrue:[
|
1
|
1154 |
%{
|
81
|
1155 |
if (__isByteArray(_INST(bytes))) {
|
|
1156 |
int sI = _intVal(srcIndex);
|
|
1157 |
unsigned char *cp = _ByteArrayInstPtr(_INST(bytes))->ba_element;
|
1
|
1158 |
|
81
|
1159 |
r = _MKSMALLINT((cp[sI - 1] & _intVal(rMask)) + 1);
|
|
1160 |
g = _MKSMALLINT((cp[sI] & _intVal(gMask)) + 1);
|
|
1161 |
b = _MKSMALLINT((cp[sI + 1] & _intVal(bMask)) + 1);
|
|
1162 |
srcIndex = _MKSMALLINT(sI + 3);
|
|
1163 |
fast = true;
|
|
1164 |
} else {
|
|
1165 |
fast = false;
|
|
1166 |
}
|
1
|
1167 |
%}
|
|
1168 |
.
|
81
|
1169 |
fast ifFalse:[
|
|
1170 |
r := bytes at:srcIndex.
|
|
1171 |
r := (r bitAnd:rMask) + 1.
|
|
1172 |
srcIndex := srcIndex + 1.
|
|
1173 |
g := bytes at:srcIndex.
|
|
1174 |
g := (g bitAnd:gMask) + 1.
|
|
1175 |
srcIndex := srcIndex + 1.
|
|
1176 |
b := bytes at:srcIndex.
|
|
1177 |
b := (b bitAnd:bMask) + 1.
|
|
1178 |
srcIndex := srcIndex + 1
|
|
1179 |
].
|
1
|
1180 |
|
81
|
1181 |
greenArray := redArray at:r.
|
|
1182 |
greenArray isNil ifTrue:[
|
|
1183 |
greenArray := Array new:256.
|
|
1184 |
redArray at:r put:greenArray
|
|
1185 |
].
|
|
1186 |
blueArray := greenArray at:g.
|
|
1187 |
blueArray isNil ifTrue:[
|
89
|
1188 |
deep ifTrue:[blueArray := Array new:256]
|
|
1189 |
ifFalse:[blueArray := ByteArray new:256].
|
81
|
1190 |
greenArray at:g put:blueArray
|
|
1191 |
].
|
89
|
1192 |
(blueArray at:b) == 0 ifTrue:[
|
|
1193 |
blueArray at:b put:1.
|
81
|
1194 |
nColors := nColors + 1.
|
|
1195 |
(nColors > nColorCells) ifTrue:[
|
89
|
1196 |
'D24IMAGE: more than ' errorPrint. nColorCells errorPrint. ' colors' errorPrintNL.
|
81
|
1197 |
srcIndex := dataSize + 1
|
|
1198 |
]
|
|
1199 |
]
|
|
1200 |
].
|
1
|
1201 |
|
81
|
1202 |
"again with less color bits if it does not fit colormap"
|
1
|
1203 |
|
81
|
1204 |
(nColors <= nColorCells) ifTrue:[
|
|
1205 |
fitMap := true
|
|
1206 |
] ifFalse:[
|
|
1207 |
"must try again - cutting off some bits"
|
|
1208 |
(bMask == 2r11111111) ifTrue:[
|
|
1209 |
bMask := 2r11111110
|
|
1210 |
] ifFalse:[
|
89
|
1211 |
(bMask == 2r11111110) ifTrue:[
|
|
1212 |
bMask := 2r11111100
|
|
1213 |
] ifFalse:[
|
|
1214 |
rMask := (rMask bitShift:1) bitAnd:2r11111111.
|
|
1215 |
gMask := (gMask bitShift:1) bitAnd:2r11111111.
|
|
1216 |
bMask := (bMask bitShift:1) bitAnd:2r11111111
|
|
1217 |
]
|
81
|
1218 |
].
|
89
|
1219 |
'D24IMAGE: too many colors; retry with less color resolution' errorPrintNL.
|
38
|
1220 |
"
|
1
|
1221 |
'masks:' print. rMask print. ' ' print. gMask print. ' ' print.
|
|
1222 |
bMask printNewline
|
38
|
1223 |
"
|
81
|
1224 |
]
|
|
1225 |
].
|
1
|
1226 |
|
89
|
1227 |
'D24IMAGE: ' errorPrint. nColors errorPrint. ' colors used' errorPrintNL.
|
|
1228 |
|
81
|
1229 |
colors := Array new:nColors.
|
|
1230 |
colorIndex := 1.
|
1
|
1231 |
|
89
|
1232 |
"
|
|
1233 |
now, we have reduced things to the number of colors
|
|
1234 |
which are theoretically supported by the devices colormap.
|
|
1235 |
allocate all used colors in walking over true entries in
|
|
1236 |
the [r][g][b] table - this may still fail
|
|
1237 |
"
|
81
|
1238 |
fit := true.
|
1
|
1239 |
|
81
|
1240 |
r := 0.
|
|
1241 |
redArray do:[:greenArray |
|
|
1242 |
(fit and:[greenArray notNil]) ifTrue:[
|
|
1243 |
g := 0.
|
|
1244 |
greenArray do:[:blueArray |
|
|
1245 |
(fit and:[blueArray notNil]) ifTrue:[
|
|
1246 |
b := 0.
|
89
|
1247 |
blueArray do:[:present |
|
|
1248 |
|id|
|
|
1249 |
|
|
1250 |
(fit and:[present ~~ 0]) ifTrue:[
|
81
|
1251 |
color := Color red:(r * 100.0 / 255.0)
|
|
1252 |
green:(g * 100.0 / 255.0)
|
|
1253 |
blue:(b * 100.0 / 255.0).
|
|
1254 |
color := color on:aDevice.
|
89
|
1255 |
(id := color colorId) isNil ifTrue:[
|
81
|
1256 |
fit := false
|
|
1257 |
] ifFalse:[
|
|
1258 |
colors at:colorIndex put:color.
|
|
1259 |
colorIndex := colorIndex + 1.
|
89
|
1260 |
blueArray at:(b + 1) put:id
|
81
|
1261 |
]
|
|
1262 |
].
|
|
1263 |
b := b + 1
|
|
1264 |
]
|
|
1265 |
].
|
|
1266 |
g := g + 1
|
|
1267 |
]
|
|
1268 |
].
|
|
1269 |
r := r + 1
|
|
1270 |
].
|
1
|
1271 |
|
81
|
1272 |
"again with less color bits if we did not get all colors"
|
1
|
1273 |
|
81
|
1274 |
fit ifFalse:[
|
89
|
1275 |
'D24IMAGE: could not allocate color(s)' errorPrintNL.
|
1
|
1276 |
|
81
|
1277 |
"free the allocated colors"
|
|
1278 |
colors atAllPut:nil.
|
|
1279 |
"a kludge - force immediate freeing of colors"
|
|
1280 |
ObjectMemory scavenge.
|
1
|
1281 |
|
81
|
1282 |
"cut off one more color-bit - cut off blue first"
|
|
1283 |
(bMask == 2r11111111) ifTrue:[
|
|
1284 |
bMask := 2r11111110
|
|
1285 |
] ifFalse:[
|
|
1286 |
(bMask == 2r11111110) ifTrue:[
|
|
1287 |
bMask := 2r11111100
|
|
1288 |
] ifFalse:[
|
|
1289 |
rMask := (rMask bitShift:1) bitAnd:2r11111111.
|
|
1290 |
gMask := (gMask bitShift:1) bitAnd:2r11111111.
|
|
1291 |
bMask := (bMask bitShift:1) bitAnd:2r11111111
|
|
1292 |
]
|
|
1293 |
].
|
|
1294 |
fitMap := false.
|
|
1295 |
redArray := nil
|
|
1296 |
]
|
1
|
1297 |
].
|
|
1298 |
|
|
1299 |
"create pseudocolor bits and translate"
|
|
1300 |
|
|
1301 |
pseudoBits := ByteArray uninitializedNew:(width * height).
|
|
1302 |
|
|
1303 |
srcIndex := 1.
|
|
1304 |
dstIndex := 1.
|
|
1305 |
|
89
|
1306 |
(rMask == 2r11111111
|
|
1307 |
and:[gMask == 2r11111111
|
|
1308 |
and:[bMask == 2r11111111]]) ifTrue:[
|
|
1309 |
[srcIndex < dataSize] whileTrue:[
|
|
1310 |
r := bytes at:srcIndex.
|
|
1311 |
srcIndex := srcIndex + 1.
|
|
1312 |
g := bytes at:srcIndex.
|
|
1313 |
srcIndex := srcIndex + 1.
|
|
1314 |
b := bytes at:srcIndex.
|
|
1315 |
srcIndex := srcIndex + 1.
|
|
1316 |
greenArray := redArray at:(r + 1).
|
|
1317 |
blueArray := greenArray at:(g + 1).
|
|
1318 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
|
|
1319 |
dstIndex := dstIndex + 1
|
|
1320 |
]
|
|
1321 |
] ifFalse:[
|
|
1322 |
[srcIndex < dataSize] whileTrue:[
|
|
1323 |
r := bytes at:srcIndex.
|
|
1324 |
r := r bitAnd:rMask.
|
|
1325 |
srcIndex := srcIndex + 1.
|
|
1326 |
g := bytes at:srcIndex.
|
|
1327 |
g := g bitAnd:gMask.
|
|
1328 |
srcIndex := srcIndex + 1.
|
|
1329 |
b := bytes at:srcIndex.
|
|
1330 |
b := b bitAnd:bMask.
|
|
1331 |
srcIndex := srcIndex + 1.
|
|
1332 |
greenArray := redArray at:(r + 1).
|
|
1333 |
blueArray := greenArray at:(g + 1).
|
|
1334 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
|
|
1335 |
dstIndex := dstIndex + 1
|
|
1336 |
]
|
1
|
1337 |
].
|
|
1338 |
|
89
|
1339 |
f := Form width:width height:height depth:depth on:aDevice.
|
1
|
1340 |
f isNil ifTrue:[^ nil].
|
|
1341 |
f colorMap:colors.
|
|
1342 |
f initGC.
|
89
|
1343 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:depth
|
81
|
1344 |
width:width height:height
|
|
1345 |
x:0 y:0
|
|
1346 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId).
|
1
|
1347 |
^ f
|
|
1348 |
! !
|
|
1349 |
|
|
1350 |
!Depth24Image methodsFor:'magnification'!
|
|
1351 |
|
|
1352 |
magnifyRowFrom:srcBytes offset:srcStart
|
81
|
1353 |
into:dstBytes offset:dstStart factor:mX
|
1
|
1354 |
|
|
1355 |
"magnify a single pixel row - can only magnify by integer factors"
|
|
1356 |
|
|
1357 |
%{
|
|
1358 |
unsigned char *srcP, *dstP;
|
|
1359 |
int _mag;
|
|
1360 |
REGISTER int i;
|
|
1361 |
REGISTER unsigned char byte1, byte2, byte3;
|
|
1362 |
int _pixels;
|
|
1363 |
|
|
1364 |
if (_isSmallInteger(srcStart) && _isSmallInteger(dstStart)
|
|
1365 |
&& _isSmallInteger(_INST(width)) && _isSmallInteger(mX)
|
35
|
1366 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
|
81
|
1367 |
_mag = _intVal(mX);
|
|
1368 |
srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart);
|
|
1369 |
dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart);
|
|
1370 |
_pixels = _intVal(_INST(width));
|
1
|
1371 |
|
81
|
1372 |
while (_pixels--) {
|
|
1373 |
byte1 = *srcP;
|
|
1374 |
byte2 = *(srcP+1);
|
|
1375 |
byte3 = *(srcP+2);
|
|
1376 |
srcP += 3;
|
|
1377 |
for (i=_mag; i>0; i--) {
|
|
1378 |
*dstP = byte1;
|
|
1379 |
*(dstP+1) = byte2;
|
|
1380 |
*(dstP+2) = byte3;
|
|
1381 |
dstP += 3;
|
|
1382 |
}
|
|
1383 |
}
|
|
1384 |
RETURN (self);
|
1
|
1385 |
}
|
|
1386 |
%}
|
|
1387 |
.
|
|
1388 |
self primitiveFailed
|
|
1389 |
!
|
|
1390 |
|
|
1391 |
hardMagnifyBy:extent
|
|
1392 |
"return a new image magnified by extent, aPoint.
|
|
1393 |
This is the general magnification method, handling non-integral values"
|
|
1394 |
|
|
1395 |
|mX mY
|
|
1396 |
newWidth "{ Class: SmallInteger }"
|
|
1397 |
newHeight "{ Class: SmallInteger }"
|
|
1398 |
w "{ Class: SmallInteger }"
|
|
1399 |
h "{ Class: SmallInteger }"
|
|
1400 |
newImage newBytes
|
|
1401 |
value "{ Class: SmallInteger }"
|
|
1402 |
srcRowIdx "{ Class: SmallInteger }"
|
|
1403 |
srcIndex "{ Class: SmallInteger }"
|
|
1404 |
dstIndex "{ Class: SmallInteger }"|
|
|
1405 |
|
|
1406 |
mX := extent x.
|
|
1407 |
mY := extent y.
|
|
1408 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
|
|
1409 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self].
|
|
1410 |
|
|
1411 |
newWidth := (width * mX) truncated.
|
|
1412 |
newHeight := (height * mY) truncated.
|
|
1413 |
newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight).
|
|
1414 |
|
|
1415 |
newImage := self species new.
|
|
1416 |
newImage bits:newBytes.
|
|
1417 |
newImage width:newWidth.
|
|
1418 |
newImage height:newHeight.
|
|
1419 |
newImage photometric:photometric.
|
|
1420 |
newImage samplesPerPixel:samplesPerPixel.
|
|
1421 |
newImage bitsPerSample:#(8 8 8).
|
|
1422 |
|
|
1423 |
"walk over destination image fetching pixels from source image"
|
|
1424 |
|
|
1425 |
mY := mY asFloat.
|
|
1426 |
mX := mX asFloat.
|
|
1427 |
%{
|
|
1428 |
REGISTER unsigned char *_dstP = _ByteArrayInstPtr(newBytes)->ba_element;
|
|
1429 |
unsigned char *_srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
|
|
1430 |
unsigned char *_srcRowP, *sP;
|
|
1431 |
int _width3 = _intVal(_INST(width)) * 3;
|
|
1432 |
int _w = _intVal(newWidth) - 1;
|
|
1433 |
int _h = _intVal(newHeight) - 1;
|
|
1434 |
int _row, _col;
|
|
1435 |
double _mX = _floatVal(mX);
|
|
1436 |
double _mY = _floatVal(mY);
|
|
1437 |
|
|
1438 |
for (_row = 0; _row <= _h; _row++) {
|
81
|
1439 |
_srcRowP = _srcP + (_width3 * (int)((double)_row / _mY));
|
|
1440 |
for (_col = 0; _col <= _w; _col++) {
|
|
1441 |
sP = _srcRowP + (((int)((double)_col / _mX)) * 3);
|
|
1442 |
_dstP[0] = sP[0];
|
|
1443 |
_dstP[1] = sP[1];
|
|
1444 |
_dstP[2] = sP[2];
|
|
1445 |
_dstP += 3;
|
|
1446 |
}
|
1
|
1447 |
}
|
|
1448 |
%}
|
|
1449 |
.
|
81
|
1450 |
" the above C-code is equivalent to:
|
|
1451 |
|
1
|
1452 |
dstIndex := 1.
|
|
1453 |
w := newWidth - 1.
|
|
1454 |
h := newHeight - 1.
|
|
1455 |
0 to:h do:[:row |
|
81
|
1456 |
srcRowIdx := (width * 3 * (row // mY)) + 1.
|
|
1457 |
0 to:w do:[:col |
|
|
1458 |
srcIndex := srcRowIdx + ((col // mX) * 3).
|
|
1459 |
value := bytes at:srcIndex.
|
|
1460 |
newBytes at:dstIndex put:value.
|
|
1461 |
value := bytes at:(srcIndex + 1).
|
|
1462 |
newBytes at:(dstIndex + 1) put:value.
|
|
1463 |
value := bytes at:(srcIndex + 2).
|
|
1464 |
newBytes at:(dstIndex + 2) put:value.
|
|
1465 |
dstIndex := dstIndex + 3
|
|
1466 |
]
|
1
|
1467 |
].
|
|
1468 |
"
|
|
1469 |
^ newImage
|
|
1470 |
! !
|