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