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