author | Claus Gittinger <cg@exept.de> |
Thu, 28 Apr 2016 14:18:50 +0200 | |
changeset 7319 | a7aeb15d709f |
parent 7279 | 51d86b5b7883 |
child 7286 | c3b4c3c664d4 |
child 7492 | 34cfdad00603 |
permissions | -rw-r--r-- |
1663 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
3 |
All Rights Reserved |
1663 | 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 |
" |
|
3263 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
6841 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1663 | 16 |
Image subclass:#Depth32Image |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Graphics-Images' |
|
21 |
! |
|
22 |
||
23 |
!Depth32Image class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
28 |
All Rights Reserved |
1663 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
this class represents 32 bit images. |
|
42 |
Only the minimum protocol is implemented here; much more is |
|
43 |
needed for higher performance operations on depth32 images. |
|
44 |
(however, 32bit images are very seldom used, so falling back into the |
|
45 |
slow general methods from Image should not hurt too much ..) |
|
46 |
||
47 |
[author:] |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
48 |
Claus Gittinger |
1663 | 49 |
|
50 |
[see also:] |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
51 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
52 |
ImageReader |
1663 | 53 |
" |
54 |
! ! |
|
55 |
||
56 |
!Depth32Image class methodsFor:'queries'! |
|
57 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
58 |
defaultPhotometric |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
59 |
"return the default photometric pixel interpretation" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
60 |
|
5324 | 61 |
^ #rgb |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
62 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
63 |
"Created: / 27-05-2007 / 14:03:59 / cg" |
4790 | 64 |
"Modified: / 06-06-2007 / 11:12:13 / cg" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
65 |
! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
66 |
|
1663 | 67 |
imageDepth |
68 |
"return the depth of images represented by instances of |
|
69 |
this class - here we return 32" |
|
70 |
||
71 |
^ 32 |
|
72 |
||
73 |
"Modified: 20.4.1996 / 23:40:01 / cg" |
|
74 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
75 |
! ! |
|
76 |
||
3263 | 77 |
!Depth32Image methodsFor:'accessing-pixels'! |
1663 | 78 |
|
6841 | 79 |
colorAtX:x y:y |
80 |
"retrieve a pixel at x/y; return a color. |
|
7124 | 81 |
Pixels start at x=0 , y=0 for upper left pixel, |
82 |
end at x = width-1, y=height-1 for lower right pixel" |
|
6841 | 83 |
|
84 |
|index "{ Class: SmallInteger }" |
|
7124 | 85 |
rVal gVal bVal aVal| |
6841 | 86 |
|
87 |
index := 1 + (((width * y) + x) * 4). |
|
7124 | 88 |
photometric == #rgb ifTrue:[ |
89 |
rVal := bytes at:(index). |
|
90 |
gVal := bytes at:(index + 1). |
|
91 |
bVal := bytes at:(index + 2). |
|
92 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal |
|
93 |
]. |
|
94 |
photometric == #rgba ifTrue:[ |
|
95 |
rVal := bytes at:(index). |
|
96 |
gVal := bytes at:(index + 1). |
|
97 |
bVal := bytes at:(index + 2). |
|
98 |
aVal := bytes at:(index + 3). |
|
99 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal |
|
100 |
]. |
|
101 |
photometric == #argb ifTrue:[ |
|
102 |
aVal := bytes at:(index). |
|
103 |
rVal := bytes at:(index + 1). |
|
104 |
gVal := bytes at:(index + 2). |
|
105 |
bVal := bytes at:(index + 3). |
|
106 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal |
|
107 |
]. |
|
6841 | 108 |
|
7124 | 109 |
"/ the inherited method should handle all cases. |
110 |
^ super colorAtX:x y:y. |
|
6841 | 111 |
! |
112 |
||
113 |
colorAtX:x y:y put:aColor |
|
114 |
"set the pixel at x/y to aColor. |
|
115 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
116 |
x = width-1, y=height-1 for lower right pixel." |
|
117 |
||
118 |
|index "{ Class: SmallInteger }"| |
|
119 |
||
7167 | 120 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
121 |
index := 1 + (((width * y) + x) * 4). |
|
122 |
bytes at:(index) put:(aColor redByte). |
|
123 |
bytes at:(index + 1) put:(aColor greenByte). |
|
124 |
bytes at:(index + 2) put:(aColor blueByte). |
|
125 |
bytes at:(index + 3) put:255. "alpha channel" |
|
126 |
^ self |
|
127 |
]. |
|
128 |
(photometric == #argb) ifTrue:[ |
|
129 |
index := 1 + (((width * y) + x) * 4). |
|
130 |
bytes at:(index) put:255. "alpha channel" |
|
131 |
bytes at:(index + 1) put:(aColor redByte). |
|
132 |
bytes at:(index + 2) put:(aColor greenByte). |
|
133 |
bytes at:(index + 3) put:(aColor blueByte). |
|
134 |
^ self |
|
135 |
]. |
|
6841 | 136 |
|
7167 | 137 |
super colorAtX:x y:y put:aColor. |
6841 | 138 |
! |
139 |
||
1663 | 140 |
pixelAtX:x y:y |
141 |
"retrieve a pixel at x/y; return a pixelValue. |
|
142 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
7279 | 143 |
x = width-1, y=height-1 for lower right pixel. |
144 |
The pixel value contains r/g/b/a in msb order (i.e. r at high, a at low bits)" |
|
1663 | 145 |
|
1669 | 146 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 147 |
|
7274 | 148 |
%{ /* NOCONTEXT */ |
149 |
OBJ b = __INST(bytes); |
|
150 |
OBJ w = __INST(width); |
|
151 |
||
152 |
if (__isByteArrayLike(b) |
|
153 |
&& __bothSmallInteger(x, y) |
|
154 |
&& __isSmallInteger(w) |
|
155 |
&& (__INST(pixelFunction)==nil) ) { |
|
156 |
int _idx; |
|
157 |
||
158 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
|
159 |
if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
|
160 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
161 |
unsigned int _pix; |
|
162 |
_pix = (((((pPix[0]<<8)+pPix[1])<<8)+pPix[2])<<8)+pPix[3]; |
|
163 |
#if __POINTER_SIZE__ == 8 |
|
164 |
RETURN( __MKSMALLINT(_pix) ); |
|
165 |
#else |
|
166 |
RETURN( __MKUINT(_pix) ); |
|
167 |
#endif |
|
168 |
} |
|
169 |
} |
|
170 |
%}. |
|
6302 | 171 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
172 |
||
6841 | 173 |
pixelIndex := 1 + (((width * y) + x) * 4). |
1663 | 174 |
|
175 |
"left pixel in high bits" |
|
7225 | 176 |
^ bytes unsignedInt32At:pixelIndex MSB:true. |
1663 | 177 |
|
178 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
1669 | 179 |
"Modified: 24.4.1997 / 23:11:05 / cg" |
1663 | 180 |
! |
181 |
||
182 |
pixelAtX:x y:y put:aPixelValue |
|
183 |
"set the pixel at x/y to aPixelValue. |
|
184 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
185 |
x = width-1, y=height-1 for lower right pixel" |
|
186 |
||
1669 | 187 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 188 |
|
6841 | 189 |
pixelIndex := 1 + (((width * y) + x) * 4). |
4790 | 190 |
bytes isNil ifTrue:[ |
6841 | 191 |
self createPixelStore |
4790 | 192 |
]. |
7225 | 193 |
bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true |
1663 | 194 |
|
4790 | 195 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
196 |
"Modified: / 06-06-2007 / 12:20:57 / cg" |
|
6841 | 197 |
! |
198 |
||
199 |
rowAt:y putAll:pixelArray startingAt:startIndex |
|
200 |
"store a single rows bits from bits in the pixelArray argument; |
|
201 |
Return the pixelArray. |
|
202 |
Notice: row coordinate starts at 0." |
|
203 |
||
6846 | 204 |
|bytes dstIdx pixel |
205 |
w "{ Class: SmallInteger }"| |
|
6841 | 206 |
|
207 |
bytes := self bits. |
|
208 |
dstIdx := (y * self bytesPerRow) + 1. |
|
6846 | 209 |
w := width - 1. |
210 |
||
211 |
0 to:w do:[:col | |
|
6841 | 212 |
pixel := pixelArray at:(startIndex + col). |
7225 | 213 |
bytes unsignedInt32At:dstIdx put:pixel MSB:true. |
6841 | 214 |
dstIdx := dstIdx + 4. |
215 |
]. |
|
216 |
^ pixelArray |
|
1663 | 217 |
! ! |
218 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
219 |
!Depth32Image methodsFor:'converting rgb images'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
220 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
221 |
rgbImageAsTrueColorFormOn:aDevice |
7122 | 222 |
"return a truecolor form from the rgba or argb-picture." |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
223 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
224 |
|bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
225 |
myDepth form imageBits padd |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
226 |
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue| |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
227 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
228 |
bytes := self bits. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
229 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
230 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4763 | 231 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
232 |
usedDeviceDepth := bestFormat at:#depth. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
233 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
234 |
usedDevicePadding := bestFormat at:#padding. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
235 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
236 |
rightShiftR := (8 - aDevice bitsRed). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
237 |
rightShiftG := (8 - aDevice bitsGreen). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
238 |
rightShiftB := (8 - aDevice bitsBlue). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
239 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
240 |
shiftRed := aDevice shiftRed. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
241 |
shiftGreen := aDevice shiftGreen. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
242 |
shiftBlue := aDevice shiftBlue. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
243 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
244 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
245 |
"/ for now, only a few formats are supported |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
246 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
247 |
myDepth := self bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
248 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
7122 | 249 |
"/ |
250 |
"/ 24 bit/pixel |
|
251 |
"/ |
|
252 |
imageBits := ByteArray uninitializedNew:(width * height * 3). |
|
253 |
usedDevicePadding := 8. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
254 |
|
7122 | 255 |
"/ now, walk over the image and compose 24bit values from the r/g/b/a triples |
256 |
%{ |
|
257 |
unsigned char *srcPtr = 0; |
|
258 |
unsigned char *dstPtr = 0; |
|
259 |
int redOffs = 0; |
|
260 |
int greenOffs = 1; |
|
261 |
int blueOffs = 2; |
|
262 |
int alphaOffs = 3; |
|
263 |
||
264 |
if (__INST(photometric) == @symbol(argb)) { |
|
265 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
266 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
267 |
|
7122 | 268 |
if (__isByteArrayLike(bytes)) { |
269 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
270 |
} else { |
|
271 |
if (__isExternalBytesLike(bytes)) { |
|
272 |
srcPtr = __externalBytesAddress(bytes); |
|
273 |
} |
|
274 |
} |
|
275 |
if (__isByteArray(imageBits)) { |
|
276 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
277 |
} else { |
|
278 |
if (__isExternalBytesLike(imageBits)) { |
|
279 |
dstPtr = __externalBytesAddress(imageBits); |
|
280 |
} |
|
281 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
282 |
|
7122 | 283 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
284 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
285 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
286 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
287 |
&& srcPtr |
|
288 |
&& dstPtr) { |
|
289 |
int rShRed = __intVal(rightShiftR), |
|
290 |
rShGreen = __intVal(rightShiftG), |
|
291 |
rShBlue = __intVal(rightShiftB), |
|
292 |
lShRed = __intVal(shiftRed), |
|
293 |
lShGreen = __intVal(shiftGreen), |
|
294 |
lShBlue = __intVal(shiftBlue); |
|
295 |
int x, y, w; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
296 |
|
7122 | 297 |
w = __intVal(__INST(width)); |
298 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
299 |
if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) { |
|
300 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
301 |
for (x=w; x > 0; x--) { |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
302 |
# ifdef __MSBFIRST |
7122 | 303 |
dstPtr[0] = srcPtr[redOffs]; |
304 |
dstPtr[1] = srcPtr[greenOffs]; |
|
305 |
dstPtr[2] = srcPtr[blueOffs]; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
306 |
# else /* not MSB */ |
7122 | 307 |
dstPtr[0] = srcPtr[blueOffs]; |
308 |
dstPtr[1] = srcPtr[greenOffs]; |
|
309 |
dstPtr[2] = srcPtr[redOffs]; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
310 |
# endif /* not MSB */ |
7122 | 311 |
dstPtr += 3; |
312 |
srcPtr += 4; |
|
313 |
} |
|
314 |
} |
|
315 |
} else { |
|
316 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
317 |
for (x=w; x > 0; x--) { |
|
318 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
319 |
|
7122 | 320 |
v = srcPtr[redOffs] << lShRed; |
321 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
322 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
323 |
# ifdef __MSBFIRST |
7122 | 324 |
dstPtr[0] = (v) & 0xFF; |
325 |
dstPtr[1] = (v>>8) & 0xFF; |
|
326 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
327 |
# else /* not MSB */ |
7122 | 328 |
dstPtr[0] = (v>>16) & 0xFF; |
329 |
dstPtr[1] = (v>>8) & 0xFF; |
|
330 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
331 |
# endif /* not MSB */ |
7122 | 332 |
dstPtr += 3; |
333 |
srcPtr += 4; |
|
334 |
} |
|
335 |
} |
|
336 |
} |
|
337 |
} else { |
|
338 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
339 |
for (x=w; x > 0; x--) { |
|
340 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
341 |
|
7122 | 342 |
r = srcPtr[redOffs] >> rShRed; |
343 |
g = srcPtr[greenOffs] >> rShGreen; |
|
344 |
b = srcPtr[blueOffs] >> rShBlue; |
|
345 |
v = r << lShRed; |
|
346 |
v |= (g << lShGreen); |
|
347 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
348 |
# ifdef __MSBFIRST |
7122 | 349 |
dstPtr[0] = (v) & 0xFF; |
350 |
dstPtr[1] = (v>>8) & 0xFF; |
|
351 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
352 |
# else /* not MSB */ |
7122 | 353 |
dstPtr[0] = (v>>16) & 0xFF; |
354 |
dstPtr[1] = (v>>8) & 0xFF; |
|
355 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
356 |
# endif /* not MSB */ |
7122 | 357 |
dstPtr += 3; |
358 |
srcPtr += 4; |
|
359 |
} |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
363 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
364 |
] ifFalse:[ |
7122 | 365 |
"/ |
366 |
"/ 8, 16 or 32 bit/pixel ... |
|
367 |
"/ |
|
368 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
|
369 |
padd := width \\ (usedDevicePadding // 16). |
|
370 |
imageBits := ByteArray uninitializedNew:((width + padd) * height * 2). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
371 |
|
7122 | 372 |
"/ now, walk over the image and compose 16bit values from the r/g/b triples |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
373 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
374 |
%{ |
7122 | 375 |
unsigned char *srcPtr = 0; |
376 |
unsigned char *dstPtr = 0; |
|
377 |
int redOffs = 0; |
|
378 |
int greenOffs = 1; |
|
379 |
int blueOffs = 2; |
|
380 |
int alphaOffs = 3; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
381 |
|
7122 | 382 |
if (__INST(photometric) == @symbol(argb)) { |
383 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
384 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
385 |
|
7122 | 386 |
if (__isByteArrayLike(bytes)) { |
387 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
388 |
} else { |
|
389 |
if (__isExternalBytesLike(bytes)) { |
|
390 |
srcPtr = __externalBytesAddress(bytes); |
|
391 |
} |
|
392 |
} |
|
393 |
if (__isByteArray(imageBits)) { |
|
394 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
395 |
} else { |
|
396 |
if (__isExternalBytesLike(imageBits)) { |
|
397 |
dstPtr = __externalBytesAddress(imageBits); |
|
398 |
} |
|
399 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
400 |
|
7122 | 401 |
if (__bothSmallInteger(__INST(height),__INST(width)) |
402 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
403 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
404 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
405 |
&& srcPtr |
|
406 |
&& dstPtr) { |
|
407 |
int rShRed = __intVal(rightShiftR), |
|
408 |
rShGreen = __intVal(rightShiftG), |
|
409 |
rShBlue = __intVal(rightShiftB), |
|
410 |
lShRed = __intVal(shiftRed), |
|
411 |
lShGreen = __intVal(shiftGreen), |
|
412 |
lShBlue = __intVal(shiftBlue); |
|
413 |
int x, y, w; |
|
414 |
int p; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
415 |
|
7122 | 416 |
w = __intVal(__INST(width)); |
417 |
p = __intVal(padd) * 2; |
|
418 |
||
419 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
420 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
421 |
for (x=w; x > 0; x--) { |
|
422 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
423 |
|
7122 | 424 |
v = srcPtr[redOffs] << lShRed; |
425 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
426 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
427 |
# ifdef __MSBFIRST |
7122 | 428 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
429 |
# else /* not MSB */ |
7122 | 430 |
dstPtr[0] = (v>>8) & 0xFF; |
431 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
432 |
# endif /* not MSB */ |
7122 | 433 |
dstPtr += 2; |
434 |
srcPtr += 4; |
|
435 |
} |
|
436 |
dstPtr += p; |
|
437 |
} |
|
438 |
} else { |
|
439 |
if (p == 0) { |
|
440 |
int n = __intVal(__INST(height)) * w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
441 |
|
7122 | 442 |
while (n >= 2) { |
443 |
unsigned w, r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
444 |
|
7122 | 445 |
n -= 2; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
446 |
|
7122 | 447 |
r = srcPtr[redOffs]; |
448 |
g = srcPtr[greenOffs]; |
|
449 |
b = srcPtr[blueOffs]; |
|
450 |
v = (r >> rShRed) << lShRed; |
|
451 |
v |= ((g >> rShGreen) << lShGreen); |
|
452 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
453 |
# ifdef __MSBFIRST |
7122 | 454 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
455 |
# else |
7122 | 456 |
dstPtr[0] = (v>>8) & 0xFF; |
457 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
458 |
# endif /* not MSB */ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
459 |
|
7122 | 460 |
r = srcPtr[3+redOffs]; |
461 |
g = srcPtr[3+greenOffs]; |
|
462 |
b = srcPtr[3+blueOffs]; |
|
463 |
v = (r >> rShRed) << lShRed; |
|
464 |
v |= ((g >> rShGreen) << lShGreen); |
|
465 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
466 |
# ifdef __MSBFIRST |
7122 | 467 |
((short *)dstPtr)[1] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
468 |
# else |
7122 | 469 |
dstPtr[2] = (v>>8) & 0xFF; |
470 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
471 |
# endif /* not MSB */ |
7122 | 472 |
dstPtr += 4; |
473 |
srcPtr += 8; |
|
474 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
475 |
|
7122 | 476 |
while (n--) { |
477 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
478 |
|
7122 | 479 |
r = srcPtr[redOffs] >> rShRed; |
480 |
g = srcPtr[greenOffs] >> rShGreen; |
|
481 |
b = srcPtr[blueOffs] >> rShBlue; |
|
482 |
v = r << lShRed; |
|
483 |
v |= (g << lShGreen); |
|
484 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
485 |
# ifdef __MSBFIRST |
7122 | 486 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
487 |
# else /* not MSB */ |
7122 | 488 |
dstPtr[0] = (v>>8) & 0xFF; |
489 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
490 |
# endif /* not MSB */ |
7122 | 491 |
dstPtr += 2; |
492 |
srcPtr += 4; |
|
493 |
} |
|
494 |
} else { |
|
495 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
496 |
for (x=w; x > 0; x--) { |
|
497 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
498 |
|
7122 | 499 |
r = srcPtr[redOffs] >> rShRed; |
500 |
g = srcPtr[greenOffs] >> rShGreen; |
|
501 |
b = srcPtr[blueOffs] >> rShBlue; |
|
502 |
v = r << lShRed; |
|
503 |
v |= (g << lShGreen); |
|
504 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
505 |
# ifdef __MSBFIRST |
7122 | 506 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
507 |
# else /* not MSB */ |
7122 | 508 |
dstPtr[0] = (v>>8) & 0xFF; |
509 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
510 |
# endif /* not MSB */ |
7122 | 511 |
dstPtr += 2; |
512 |
srcPtr += 4; |
|
513 |
} |
|
514 |
dstPtr += p; |
|
515 |
} |
|
516 |
} |
|
517 |
} |
|
518 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
519 |
%}. |
7122 | 520 |
] ifFalse:[ |
521 |
"/ |
|
522 |
"/ 32 or 8 bits/pixel ... |
|
523 |
"/ |
|
524 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
|
525 |
usedDevicePadding := 8. |
|
526 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
527 |
|
7122 | 528 |
"/ now, walk over the image and compose 32bit values from the r/g/b triples |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
529 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
530 |
%{ |
7122 | 531 |
unsigned char *srcPtr = 0; |
532 |
unsigned char *dstPtr = 0; |
|
533 |
int redOffs = 0; |
|
534 |
int greenOffs = 1; |
|
535 |
int blueOffs = 2; |
|
536 |
int alphaOffs = 3; |
|
537 |
||
538 |
if (__INST(photometric) == @symbol(argb)) { |
|
539 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
540 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
541 |
|
7122 | 542 |
if (__isByteArrayLike(bytes)) { |
543 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
544 |
} else { |
|
545 |
if (__isExternalBytesLike(bytes)) { |
|
546 |
srcPtr = __externalBytesAddress(bytes); |
|
547 |
} |
|
548 |
} |
|
549 |
if (__isByteArray(imageBits)) { |
|
550 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
551 |
} else { |
|
552 |
if (__isExternalBytesLike(imageBits)) { |
|
553 |
dstPtr = __externalBytesAddress(imageBits); |
|
554 |
} |
|
555 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
556 |
|
7122 | 557 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
558 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
559 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
560 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
561 |
&& srcPtr |
|
562 |
&& dstPtr) { |
|
563 |
int rShRed = __intVal(rightShiftR), |
|
564 |
rShGreen = __intVal(rightShiftG), |
|
565 |
rShBlue = __intVal(rightShiftB), |
|
566 |
lShRed = __intVal(shiftRed), |
|
567 |
lShGreen = __intVal(shiftGreen), |
|
568 |
lShBlue = __intVal(shiftBlue); |
|
569 |
int x, y, w; |
|
570 |
||
571 |
w = __intVal(__INST(width)); |
|
572 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
573 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
574 |
for (x=w; x > 0; x--) { |
|
575 |
unsigned v; |
|
576 |
||
577 |
v = srcPtr[redOffs] << lShRed; |
|
578 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
579 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
580 |
# ifdef __MSBFIRST |
7122 | 581 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
582 |
# else /* not MSB */ |
7122 | 583 |
dstPtr[0] = (v>>24) & 0xFF; |
584 |
dstPtr[1] = (v>>16) & 0xFF; |
|
585 |
dstPtr[2] = (v>>8) & 0xFF; |
|
586 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
587 |
# endif /* not MSB */ |
7122 | 588 |
dstPtr += 4; |
589 |
srcPtr += 4; |
|
590 |
} |
|
591 |
} |
|
592 |
} else { |
|
593 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
594 |
for (x=w; x > 0; x--) { |
|
595 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
596 |
|
7122 | 597 |
r = srcPtr[redOffs] >> rShRed; |
598 |
g = srcPtr[greenOffs] >> rShGreen; |
|
599 |
b = srcPtr[blueOffs] >> rShBlue; |
|
600 |
v = r << lShRed; |
|
601 |
v |= (g << lShGreen); |
|
602 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
603 |
# ifdef __MSBFIRST |
7122 | 604 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
605 |
# else /* not MSB */ |
7122 | 606 |
dstPtr[0] = (v>>24) & 0xFF; |
607 |
dstPtr[1] = (v>>16) & 0xFF; |
|
608 |
dstPtr[2] = (v>>8) & 0xFF; |
|
609 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
610 |
# endif /* not MSB */ |
7122 | 611 |
dstPtr += 4; |
612 |
srcPtr += 4; |
|
613 |
} |
|
614 |
} |
|
615 |
} |
|
616 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
617 |
%}. |
7122 | 618 |
] ifFalse:[ |
619 |
"/ |
|
620 |
"/ 8 bits/pixel ... |
|
621 |
"/ |
|
622 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
623 |
usedDevicePadding := 8. |
|
624 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
625 |
|
7122 | 626 |
"/ now, walk over the image and compose 8bit values from the r/g/b triples |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
627 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
628 |
%{ |
7122 | 629 |
unsigned char *srcPtr = 0; |
630 |
unsigned char *dstPtr = 0; |
|
631 |
int redOffs = 0; |
|
632 |
int greenOffs = 1; |
|
633 |
int blueOffs = 2; |
|
634 |
int alphaOffs = 3; |
|
635 |
||
636 |
if (__INST(photometric) == @symbol(argb)) { |
|
637 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
638 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
639 |
|
7122 | 640 |
if (__isByteArrayLike(bytes)) { |
641 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
642 |
} else { |
|
643 |
if (__isExternalBytesLike(bytes)) { |
|
644 |
srcPtr = __externalBytesAddress(bytes); |
|
645 |
} |
|
646 |
} |
|
647 |
if (__isByteArray(imageBits)) { |
|
648 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
649 |
} else { |
|
650 |
if (__isExternalBytesLike(imageBits)) { |
|
651 |
dstPtr = __externalBytesAddress(imageBits); |
|
652 |
} |
|
653 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
654 |
|
7122 | 655 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
656 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
657 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
658 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
659 |
&& srcPtr |
|
660 |
&& dstPtr) { |
|
661 |
int rShRed = __intVal(rightShiftR), |
|
662 |
rShGreen = __intVal(rightShiftG), |
|
663 |
rShBlue = __intVal(rightShiftB), |
|
664 |
lShRed = __intVal(shiftRed), |
|
665 |
lShGreen = __intVal(shiftGreen), |
|
666 |
lShBlue = __intVal(shiftBlue); |
|
667 |
int x, y, w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
668 |
|
7122 | 669 |
w = __intVal(__INST(width)); |
670 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
671 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
672 |
for (x=w; x > 0; x--) { |
|
673 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
674 |
|
7122 | 675 |
v = srcPtr[redOffs] << lShRed; |
676 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
677 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
678 |
dstPtr[0] = v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
679 |
|
7122 | 680 |
dstPtr += 1; |
681 |
srcPtr += 4; |
|
682 |
} |
|
683 |
} |
|
684 |
} else { |
|
685 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
686 |
for (x=w; x > 0; x--) { |
|
687 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
688 |
|
7122 | 689 |
r = srcPtr[redOffs] >> rShRed; |
690 |
g = srcPtr[greenOffs] >> rShGreen; |
|
691 |
b = srcPtr[blueOffs] >> rShBlue; |
|
692 |
v = r << lShRed; |
|
693 |
v |= (g << lShGreen); |
|
694 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
695 |
|
7122 | 696 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
697 |
|
7122 | 698 |
dstPtr += 1; |
699 |
srcPtr += 4; |
|
700 |
} |
|
701 |
} |
|
702 |
} |
|
703 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
704 |
%}. |
7122 | 705 |
] |
706 |
]. |
|
707 |
] |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
708 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
709 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
710 |
imageBits isNil ifTrue:[ |
7122 | 711 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
712 |
usedDeviceBitsPerPixel errorPrintCR. |
|
713 |
^ self asMonochromeFormOn:aDevice |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
714 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
715 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
716 |
form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
717 |
form isNil ifTrue:[ |
7122 | 718 |
'Depth32Image [warning]: display bitmap creation failed' errorPrintCR. |
719 |
^ nil |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
720 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
721 |
form initGC. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
722 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
723 |
form |
7122 | 724 |
copyBitsFrom:imageBits |
725 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
726 |
depth:usedDeviceDepth |
|
727 |
padding:usedDevicePadding |
|
728 |
width:width height:height |
|
729 |
x:0 y:0 toX:0 y:0. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
730 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
731 |
^ form |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
732 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
733 |
"Created: / 27-05-2007 / 16:54:19 / cg" |
4763 | 734 |
"Modified: / 29-05-2007 / 12:19:04 / cg" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
735 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
736 |
|
6841 | 737 |
!Depth32Image methodsFor:'image manipulations'! |
738 |
||
739 |
negative |
|
740 |
|bytes index newImage newBytes nBytes r g b| |
|
741 |
||
742 |
photometric ~~ #rgb ifTrue:[ |
|
743 |
^ super negative. |
|
744 |
]. |
|
745 |
bytes := self bits. |
|
746 |
||
747 |
newImage := self copy. |
|
748 |
nBytes := bytes size. |
|
749 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
750 |
index := 1. |
|
751 |
[index < nBytes] whileTrue:[ |
|
752 |
r := bytes at:index. |
|
753 |
newBytes at:index put:(255-r). |
|
754 |
index := index + 1. |
|
755 |
g := bytes at:index. |
|
756 |
newBytes at:index put:(255-g). |
|
757 |
index := index + 1. |
|
758 |
b := bytes at:index. |
|
759 |
newBytes at:index put:(255-b). |
|
760 |
index := index + 1. |
|
761 |
b := bytes at:index. |
|
762 |
newBytes at:index put:b. |
|
763 |
index := index + 1. |
|
764 |
]. |
|
765 |
^ newImage |
|
766 |
! ! |
|
767 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
768 |
!Depth32Image methodsFor:'initialization'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
769 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
770 |
initialize |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
771 |
super initialize. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
772 |
samplesPerPixel := 4. |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
773 |
bitsPerSample := #(8 8 8 8). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
774 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
775 |
"Created: / 27-05-2007 / 14:09:16 / cg" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
776 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
777 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
778 |
!Depth32Image methodsFor:'magnification'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
779 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
780 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
781 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
782 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
783 |
"magnify a single pixel row - can only magnify by integer factors" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
784 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
785 |
%{ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
786 |
unsigned char *srcP, *dstP; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
787 |
int _mag; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
788 |
REGISTER int i; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
789 |
REGISTER unsigned char byte1, byte2, byte3, byte4; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
790 |
int _pixels; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
791 |
OBJ w = __INST(width); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
792 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
793 |
if (__bothSmallInteger(srcStart, dstStart) |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
794 |
&& __bothSmallInteger(w, mX) |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
795 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
796 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
797 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
798 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
799 |
_pixels = __intVal(w); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
800 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
801 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
802 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
803 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
804 |
byte3 = *(srcP+2); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
805 |
byte4 = *(srcP+3); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
806 |
srcP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
807 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
808 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
809 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
810 |
*(dstP+2) = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
811 |
*(dstP+3) = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
812 |
dstP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
813 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
814 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
815 |
RETURN (self); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
816 |
} |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
817 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
818 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
819 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
820 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
821 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
822 |
"Created: / 28-05-2007 / 15:20:52 / cg" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
823 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
824 |
|
1663 | 825 |
!Depth32Image methodsFor:'queries'! |
826 |
||
7122 | 827 |
alphaBitsOf:pixel |
828 |
"given a pixel-value, return the alpha component as byteValue (0..255)" |
|
829 |
||
830 |
photometric == #rgba ifTrue:[ |
|
831 |
"r,g,b,a" |
|
832 |
^ pixel bitAnd:16rFF. |
|
833 |
]. |
|
834 |
photometric == #argb ifTrue:[ |
|
835 |
"a,r,g,b" |
|
836 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
837 |
]. |
|
7167 | 838 |
photometric == #rgb ifTrue:[ |
839 |
^ 0 |
|
840 |
]. |
|
7122 | 841 |
self error:'unsupported photometric' |
842 |
! |
|
843 |
||
844 |
alphaComponentOf:pixel |
|
845 |
"given a pixel-value, return the alpha component in percent (0..100)" |
|
846 |
||
847 |
^ (self alphaBitsOf:pixel) * (100.0 / 255.0) |
|
848 |
! |
|
849 |
||
850 |
alphaMaskForPixelValue |
|
851 |
"return the mask used with translation from pixelValues to alphaBits" |
|
852 |
||
853 |
^ 16rFF |
|
854 |
! |
|
855 |
||
856 |
alphaShiftForPixelValue |
|
857 |
"return the shift amount used with translation from pixelValues to alphaBits" |
|
858 |
||
859 |
photometric == #rgba ifTrue:[ |
|
860 |
"r,g,b,a" |
|
861 |
^ 0 |
|
862 |
]. |
|
863 |
photometric == #argb ifTrue:[ |
|
864 |
"a,r,g,b" |
|
865 |
^ -24. |
|
866 |
]. |
|
867 |
self error:'unsupported photometric' |
|
868 |
! |
|
869 |
||
1663 | 870 |
bitsPerPixel |
871 |
"return the number of bits per pixel" |
|
872 |
||
873 |
^ 32 |
|
874 |
||
875 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
876 |
! |
|
877 |
||
878 |
bitsPerRow |
|
879 |
"return the number of bits in one scanline of the image" |
|
880 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
881 |
^ width * 32 |
1663 | 882 |
|
883 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
884 |
! |
|
885 |
||
6841 | 886 |
bitsPerSample |
887 |
"return the number of bits per sample. |
|
888 |
The return value is an array of bits-per-plane." |
|
889 |
||
890 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
|
891 |
^ #(8 8 8 8) |
|
892 |
! |
|
893 |
||
894 |
blueBitsOf:pixel |
|
895 |
"given a pixel-value, return the blue component as byteValue (0..255)" |
|
896 |
||
7185 | 897 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7122 | 898 |
"r,g,b,a" |
899 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
900 |
]. |
|
901 |
photometric == #argb ifTrue:[ |
|
902 |
"a,r,g,b" |
|
903 |
^ pixel bitAnd:16rFF. |
|
904 |
]. |
|
905 |
self error:'unsupported photometric' |
|
6841 | 906 |
! |
907 |
||
908 |
blueComponentOf:pixel |
|
909 |
"given a pixel-value, return the blue component in percent (0..100)" |
|
910 |
||
7122 | 911 |
^ (self blueBitsOf:pixel) * (100.0 / 255.0) |
6841 | 912 |
! |
913 |
||
914 |
blueMaskForPixelValue |
|
915 |
"return the mask used with translation from pixelValues to blueBits" |
|
916 |
||
917 |
^ 16rFF |
|
918 |
! |
|
919 |
||
920 |
blueShiftForPixelValue |
|
921 |
"return the shift amount used with translation from pixelValues to blueBits" |
|
922 |
||
7122 | 923 |
photometric == #rgba ifTrue:[ |
924 |
"r,g,b,a" |
|
925 |
^ -8 |
|
926 |
]. |
|
927 |
photometric == #argb ifTrue:[ |
|
928 |
"a,r,g,b" |
|
929 |
^ 0. |
|
930 |
]. |
|
931 |
self error:'unsupported photometric' |
|
6841 | 932 |
! |
933 |
||
1663 | 934 |
bytesPerRow |
935 |
"return the number of bytes in one scanline of the image" |
|
936 |
||
937 |
^ width * 4. |
|
938 |
||
939 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
5327 | 940 |
! |
941 |
||
6841 | 942 |
greenBitsOf:pixel |
943 |
"given a pixel-value, return the green component as byteValue (0..255)" |
|
944 |
||
7185 | 945 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7122 | 946 |
"r,g,b,a" |
947 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
948 |
]. |
|
949 |
photometric == #argb ifTrue:[ |
|
950 |
"a,r,g,b" |
|
951 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
952 |
]. |
|
953 |
self error:'unsupported photometric' |
|
6841 | 954 |
! |
955 |
||
956 |
greenComponentOf:pixel |
|
957 |
"given a pixel-value, return the green component in percent (0..100)" |
|
958 |
||
7122 | 959 |
^ (self greenBitsOf:pixel) * (100.0 / 255.0) |
6841 | 960 |
! |
961 |
||
962 |
greenMaskForPixelValue |
|
963 |
"return the mask used with translation from pixelValues to redBits" |
|
964 |
||
965 |
^ 16rFF |
|
966 |
! |
|
967 |
||
968 |
greenShiftForPixelValue |
|
969 |
"return the shift amount used with translation from pixelValues to greenBits" |
|
970 |
||
7122 | 971 |
photometric == #rgba ifTrue:[ |
972 |
"r,g,b,a" |
|
973 |
^ -16 |
|
974 |
]. |
|
975 |
photometric == #argb ifTrue:[ |
|
976 |
"a,r,g,b" |
|
977 |
^ -8. |
|
978 |
]. |
|
979 |
self error:'unsupported photometric' |
|
6841 | 980 |
! |
981 |
||
5327 | 982 |
hasAlphaChannel |
983 |
^ true |
|
6841 | 984 |
! |
985 |
||
986 |
redBitsOf:pixel |
|
987 |
"given a pixel-value, return the red component as byteValue (0..255)" |
|
988 |
||
7185 | 989 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7122 | 990 |
"r,g,b,a" |
991 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
992 |
]. |
|
993 |
photometric == #argb ifTrue:[ |
|
994 |
"a,r,g,b" |
|
995 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
996 |
]. |
|
997 |
self error:'unsupported photometric' |
|
6841 | 998 |
! |
999 |
||
1000 |
redComponentOf:pixel |
|
1001 |
"given a pixel-value, return the red component in percent (0..100)" |
|
1002 |
||
7122 | 1003 |
^ (self redBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1004 |
! |
1005 |
||
1006 |
redMaskForPixelValue |
|
1007 |
"return the mask used with translation from pixelValues to redBits" |
|
1008 |
||
1009 |
^ 16rFF |
|
1010 |
! |
|
1011 |
||
1012 |
redShiftForPixelValue |
|
1013 |
"return the shift amount used with translation from pixelValues to redBits" |
|
1014 |
||
7122 | 1015 |
photometric == #rgba ifTrue:[ |
1016 |
"r,g,b,a" |
|
1017 |
^ -24 |
|
1018 |
]. |
|
1019 |
photometric == #argb ifTrue:[ |
|
1020 |
"a,r,g,b" |
|
1021 |
^ -16. |
|
1022 |
]. |
|
1023 |
self error:'unsupported photometric' |
|
6841 | 1024 |
! |
1025 |
||
1026 |
rgbFromValue:pixelValue |
|
1027 |
"given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB)." |
|
1028 |
||
1029 |
^ pixelValue rightShift:8 "lsb is alpha channel" |
|
1030 |
! |
|
1031 |
||
1032 |
samplesPerPixel |
|
1033 |
"return the number of samples per pixel in the image." |
|
1034 |
||
1035 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
|
1036 |
^ 4 |
|
1037 |
! |
|
1038 |
||
1039 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
|
1040 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:255 |
|
1663 | 1041 |
! ! |
1042 |
||
1043 |
!Depth32Image class methodsFor:'documentation'! |
|
1044 |
||
1045 |
version |
|
7122 | 1046 |
^ '$Header$' |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1047 |
! |
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1048 |
|
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1049 |
version_CVS |
7122 | 1050 |
^ '$Header$' |
1663 | 1051 |
! ! |
6302 | 1052 |