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