author | Claus Gittinger <cg@exept.de> |
Wed, 13 Sep 2017 10:26:19 +0200 | |
changeset 8175 | a6bf93e434e4 |
parent 8166 | 71ddc0db4c31 |
child 8201 | d8a475e6e994 |
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 |
%}. |
|
6841 | 264 |
pixelIndex := 1 + (((width * y) + x) * 4). |
4790 | 265 |
bytes isNil ifTrue:[ |
6841 | 266 |
self createPixelStore |
4790 | 267 |
]. |
7922 | 268 |
bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true. |
1663 | 269 |
|
4790 | 270 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
8089 | 271 |
"Modified: / 22-08-2017 / 18:21:47 / cg" |
6841 | 272 |
! |
273 |
||
274 |
rowAt:y putAll:pixelArray startingAt:startIndex |
|
275 |
"store a single rows bits from bits in the pixelArray argument; |
|
276 |
Return the pixelArray. |
|
277 |
Notice: row coordinate starts at 0." |
|
278 |
||
7922 | 279 |
|bytes pixel |
280 |
dstIdx "{ Class: SmallInteger }" |
|
6846 | 281 |
w "{ Class: SmallInteger }"| |
6841 | 282 |
|
283 |
bytes := self bits. |
|
284 |
dstIdx := (y * self bytesPerRow) + 1. |
|
6846 | 285 |
w := width - 1. |
286 |
||
287 |
0 to:w do:[:col | |
|
6841 | 288 |
pixel := pixelArray at:(startIndex + col). |
7922 | 289 |
bytes unsignedInt32At:dstIdx put:pixel MSB:true. |
6841 | 290 |
dstIdx := dstIdx + 4. |
291 |
]. |
|
292 |
^ pixelArray |
|
7917 | 293 |
|
7922 | 294 |
"Modified (comment): / 21-02-2017 / 15:03:24 / cg" |
1663 | 295 |
! ! |
296 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
297 |
!Depth32Image methodsFor:'converting rgb images'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
298 |
|
7492 | 299 |
computeAlphaValuesFromMask:aMaskImage |
300 |
"convert a mask into alpha values; |
|
7922 | 301 |
masked pixels get an alpha value of 0, unmasked of 255" |
7492 | 302 |
|
303 |
|alphaMask| |
|
304 |
||
7922 | 305 |
alphaMask := (self alphaMaskForPixelValue bitShift:self alphaShiftForPixelValue). |
7902 | 306 |
self |
307 |
valuesFromX:0 y:0 toX:(width-1) y:(height-1) |
|
308 |
do:[:x :y :pixelValue | |
|
309 |
(aMaskImage pixelAtX:x y:y) ~~ 0 ifTrue:[ |
|
310 |
self pixelAtX:x y:y put:(pixelValue bitOr:alphaMask). |
|
311 |
] ifFalse:[ |
|
312 |
self pixelAtX:x y:y put:(pixelValue bitClear:alphaMask). |
|
313 |
]. |
|
7492 | 314 |
]. |
315 |
photometric := #rgba |
|
7902 | 316 |
|
7922 | 317 |
"Modified: / 21-02-2017 / 16:41:02 / cg" |
7492 | 318 |
! |
319 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
320 |
rgbImageAsTrueColorFormOn:aDevice |
7122 | 321 |
"return a truecolor form from the rgba or argb-picture." |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
322 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
323 |
|bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
324 |
myDepth form imageBits padd |
8000 | 325 |
rightShiftR rightShiftG rightShiftB |
8094 | 326 |
shiftRed shiftGreen shiftBlue |
327 |
redOffs greenOffs blueOffs alphaOffs| |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
328 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
329 |
bytes := self bits. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
330 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
331 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4763 | 332 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
333 |
usedDeviceDepth := bestFormat at:#depth. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
334 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
335 |
usedDevicePadding := bestFormat at:#padding. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
336 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
337 |
rightShiftR := (8 - aDevice bitsRed). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
338 |
rightShiftG := (8 - aDevice bitsGreen). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
339 |
rightShiftB := (8 - aDevice bitsBlue). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
340 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
341 |
shiftRed := aDevice shiftRed. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
342 |
shiftGreen := aDevice shiftGreen. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
343 |
shiftBlue := aDevice shiftBlue. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
344 |
|
8094 | 345 |
redOffs := 0. |
346 |
greenOffs := 1. |
|
347 |
blueOffs := 2. |
|
348 |
alphaOffs := 3. |
|
349 |
||
350 |
((photometric == #argb) or:[ photometric == #rgb ]) ifTrue:[ |
|
351 |
redOffs := 1. greenOffs := 2. blueOffs := 3. alphaOffs := 0. |
|
8114 | 352 |
] ifFalse:[ |
353 |
(photometric == #rgba) ifFalse:[ |
|
354 |
^ self anyImageAsTrueColorFormOn:aDevice |
|
355 |
]. |
|
356 |
]. |
|
8094 | 357 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
358 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
359 |
"/ for now, only a few formats are supported |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
360 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
361 |
myDepth := self bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
362 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
7122 | 363 |
"/ |
364 |
"/ 24 bit/pixel |
|
365 |
"/ |
|
366 |
imageBits := ByteArray uninitializedNew:(width * height * 3). |
|
367 |
usedDevicePadding := 8. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
368 |
|
7122 | 369 |
"/ now, walk over the image and compose 24bit values from the r/g/b/a triples |
370 |
%{ |
|
371 |
unsigned char *srcPtr = 0; |
|
372 |
unsigned char *dstPtr = 0; |
|
8094 | 373 |
int _redOffs = __intVal(redOffs); |
374 |
int _greenOffs = __intVal(greenOffs); |
|
375 |
int _blueOffs = __intVal(blueOffs); |
|
376 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
377 |
|
7122 | 378 |
if (__isByteArrayLike(bytes)) { |
379 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
380 |
} else { |
|
381 |
if (__isExternalBytesLike(bytes)) { |
|
382 |
srcPtr = __externalBytesAddress(bytes); |
|
383 |
} |
|
384 |
} |
|
385 |
if (__isByteArray(imageBits)) { |
|
386 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
387 |
} else { |
|
388 |
if (__isExternalBytesLike(imageBits)) { |
|
389 |
dstPtr = __externalBytesAddress(imageBits); |
|
390 |
} |
|
391 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
392 |
|
7122 | 393 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
394 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
395 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
396 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
397 |
&& srcPtr |
|
398 |
&& dstPtr) { |
|
399 |
int rShRed = __intVal(rightShiftR), |
|
400 |
rShGreen = __intVal(rightShiftG), |
|
401 |
rShBlue = __intVal(rightShiftB), |
|
402 |
lShRed = __intVal(shiftRed), |
|
403 |
lShGreen = __intVal(shiftGreen), |
|
404 |
lShBlue = __intVal(shiftBlue); |
|
405 |
int x, y, w; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
406 |
|
7122 | 407 |
w = __intVal(__INST(width)); |
408 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
409 |
if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) { |
|
410 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
411 |
for (x=w; x > 0; x--) { |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
412 |
# ifdef __MSBFIRST |
8094 | 413 |
dstPtr[0] = srcPtr[_redOffs]; |
414 |
dstPtr[1] = srcPtr[_greenOffs]; |
|
415 |
dstPtr[2] = srcPtr[_blueOffs]; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
416 |
# else /* not MSB */ |
8094 | 417 |
dstPtr[0] = srcPtr[_blueOffs]; |
418 |
dstPtr[1] = srcPtr[_greenOffs]; |
|
419 |
dstPtr[2] = srcPtr[_redOffs]; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
420 |
# endif /* not MSB */ |
7122 | 421 |
dstPtr += 3; |
422 |
srcPtr += 4; |
|
423 |
} |
|
424 |
} |
|
425 |
} else { |
|
426 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
427 |
for (x=w; x > 0; x--) { |
|
428 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
429 |
|
8094 | 430 |
v = srcPtr[_redOffs] << lShRed; |
431 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
432 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
433 |
# ifdef __MSBFIRST |
7122 | 434 |
dstPtr[0] = (v) & 0xFF; |
435 |
dstPtr[1] = (v>>8) & 0xFF; |
|
436 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
437 |
# else /* not MSB */ |
7122 | 438 |
dstPtr[0] = (v>>16) & 0xFF; |
439 |
dstPtr[1] = (v>>8) & 0xFF; |
|
440 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
441 |
# endif /* not MSB */ |
7122 | 442 |
dstPtr += 3; |
443 |
srcPtr += 4; |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
} else { |
|
448 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
449 |
for (x=w; x > 0; x--) { |
|
450 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
451 |
|
8094 | 452 |
r = srcPtr[_redOffs] >> rShRed; |
453 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
454 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 455 |
v = r << lShRed; |
456 |
v |= (g << lShGreen); |
|
457 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
458 |
# ifdef __MSBFIRST |
7122 | 459 |
dstPtr[0] = (v) & 0xFF; |
460 |
dstPtr[1] = (v>>8) & 0xFF; |
|
461 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
462 |
# else /* not MSB */ |
7122 | 463 |
dstPtr[0] = (v>>16) & 0xFF; |
464 |
dstPtr[1] = (v>>8) & 0xFF; |
|
465 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
466 |
# endif /* not MSB */ |
7122 | 467 |
dstPtr += 3; |
468 |
srcPtr += 4; |
|
469 |
} |
|
470 |
} |
|
471 |
} |
|
472 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
473 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
474 |
] ifFalse:[ |
7122 | 475 |
"/ |
476 |
"/ 8, 16 or 32 bit/pixel ... |
|
477 |
"/ |
|
478 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
|
479 |
padd := width \\ (usedDevicePadding // 16). |
|
480 |
imageBits := ByteArray uninitializedNew:((width + padd) * height * 2). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
481 |
|
7122 | 482 |
"/ 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
|
483 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
484 |
%{ |
7122 | 485 |
unsigned char *srcPtr = 0; |
486 |
unsigned char *dstPtr = 0; |
|
8094 | 487 |
int _redOffs = __intVal(redOffs); |
488 |
int _greenOffs = __intVal(greenOffs); |
|
489 |
int _blueOffs = __intVal(blueOffs); |
|
490 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
491 |
|
7122 | 492 |
if (__isByteArrayLike(bytes)) { |
493 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
494 |
} else { |
|
495 |
if (__isExternalBytesLike(bytes)) { |
|
496 |
srcPtr = __externalBytesAddress(bytes); |
|
497 |
} |
|
498 |
} |
|
499 |
if (__isByteArray(imageBits)) { |
|
500 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
501 |
} else { |
|
502 |
if (__isExternalBytesLike(imageBits)) { |
|
503 |
dstPtr = __externalBytesAddress(imageBits); |
|
504 |
} |
|
505 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
506 |
|
7122 | 507 |
if (__bothSmallInteger(__INST(height),__INST(width)) |
508 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
509 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
510 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
511 |
&& srcPtr |
|
512 |
&& dstPtr) { |
|
513 |
int rShRed = __intVal(rightShiftR), |
|
514 |
rShGreen = __intVal(rightShiftG), |
|
515 |
rShBlue = __intVal(rightShiftB), |
|
516 |
lShRed = __intVal(shiftRed), |
|
517 |
lShGreen = __intVal(shiftGreen), |
|
518 |
lShBlue = __intVal(shiftBlue); |
|
519 |
int x, y, w; |
|
520 |
int p; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
521 |
|
7122 | 522 |
w = __intVal(__INST(width)); |
523 |
p = __intVal(padd) * 2; |
|
524 |
||
525 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
526 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
527 |
for (x=w; x > 0; x--) { |
|
528 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
529 |
|
8094 | 530 |
v = srcPtr[_redOffs] << lShRed; |
531 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
532 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
533 |
# ifdef __MSBFIRST |
7122 | 534 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
535 |
# else /* not MSB */ |
7122 | 536 |
dstPtr[0] = (v>>8) & 0xFF; |
537 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
538 |
# endif /* not MSB */ |
7122 | 539 |
dstPtr += 2; |
540 |
srcPtr += 4; |
|
541 |
} |
|
542 |
dstPtr += p; |
|
543 |
} |
|
544 |
} else { |
|
545 |
if (p == 0) { |
|
546 |
int n = __intVal(__INST(height)) * w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
547 |
|
7122 | 548 |
while (n >= 2) { |
549 |
unsigned w, r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
550 |
|
7122 | 551 |
n -= 2; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
552 |
|
8094 | 553 |
r = srcPtr[_redOffs]; |
554 |
g = srcPtr[_greenOffs]; |
|
555 |
b = srcPtr[_blueOffs]; |
|
7122 | 556 |
v = (r >> rShRed) << lShRed; |
557 |
v |= ((g >> rShGreen) << lShGreen); |
|
558 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
559 |
# ifdef __MSBFIRST |
7122 | 560 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
561 |
# else |
7122 | 562 |
dstPtr[0] = (v>>8) & 0xFF; |
563 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
564 |
# endif /* not MSB */ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
565 |
|
8094 | 566 |
r = srcPtr[3+_redOffs]; |
567 |
g = srcPtr[3+_greenOffs]; |
|
568 |
b = srcPtr[3+_blueOffs]; |
|
7122 | 569 |
v = (r >> rShRed) << lShRed; |
570 |
v |= ((g >> rShGreen) << lShGreen); |
|
571 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
572 |
# ifdef __MSBFIRST |
7122 | 573 |
((short *)dstPtr)[1] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
574 |
# else |
7122 | 575 |
dstPtr[2] = (v>>8) & 0xFF; |
576 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
577 |
# endif /* not MSB */ |
7122 | 578 |
dstPtr += 4; |
579 |
srcPtr += 8; |
|
580 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
581 |
|
7122 | 582 |
while (n--) { |
583 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
584 |
|
8094 | 585 |
r = srcPtr[_redOffs] >> rShRed; |
586 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
587 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 588 |
v = r << lShRed; |
589 |
v |= (g << lShGreen); |
|
590 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
591 |
# ifdef __MSBFIRST |
7122 | 592 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
593 |
# else /* not MSB */ |
7122 | 594 |
dstPtr[0] = (v>>8) & 0xFF; |
595 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
596 |
# endif /* not MSB */ |
7122 | 597 |
dstPtr += 2; |
598 |
srcPtr += 4; |
|
599 |
} |
|
600 |
} else { |
|
601 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
602 |
for (x=w; x > 0; x--) { |
|
603 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
604 |
|
8094 | 605 |
r = srcPtr[_redOffs] >> rShRed; |
606 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
607 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 608 |
v = r << lShRed; |
609 |
v |= (g << lShGreen); |
|
610 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
611 |
# ifdef __MSBFIRST |
7122 | 612 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
613 |
# else /* not MSB */ |
7122 | 614 |
dstPtr[0] = (v>>8) & 0xFF; |
615 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
616 |
# endif /* not MSB */ |
7122 | 617 |
dstPtr += 2; |
618 |
srcPtr += 4; |
|
619 |
} |
|
620 |
dstPtr += p; |
|
621 |
} |
|
622 |
} |
|
623 |
} |
|
624 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
625 |
%}. |
7122 | 626 |
] ifFalse:[ |
627 |
"/ |
|
628 |
"/ 32 or 8 bits/pixel ... |
|
629 |
"/ |
|
630 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
|
8000 | 631 |
"/ usedDevicePadding := 8. |
7122 | 632 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
633 |
|
7122 | 634 |
"/ 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
|
635 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
636 |
%{ |
7122 | 637 |
unsigned char *srcPtr = 0; |
638 |
unsigned char *dstPtr = 0; |
|
8094 | 639 |
int _redOffs = __intVal(redOffs); |
640 |
int _greenOffs = __intVal(greenOffs); |
|
641 |
int _blueOffs = __intVal(blueOffs); |
|
642 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
643 |
|
7122 | 644 |
if (__isByteArrayLike(bytes)) { |
645 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
646 |
} else { |
|
647 |
if (__isExternalBytesLike(bytes)) { |
|
648 |
srcPtr = __externalBytesAddress(bytes); |
|
649 |
} |
|
650 |
} |
|
651 |
if (__isByteArray(imageBits)) { |
|
652 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
653 |
} else { |
|
654 |
if (__isExternalBytesLike(imageBits)) { |
|
655 |
dstPtr = __externalBytesAddress(imageBits); |
|
656 |
} |
|
657 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
658 |
|
7122 | 659 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
660 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
661 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
662 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
663 |
&& srcPtr |
|
664 |
&& dstPtr) { |
|
665 |
int rShRed = __intVal(rightShiftR), |
|
666 |
rShGreen = __intVal(rightShiftG), |
|
667 |
rShBlue = __intVal(rightShiftB), |
|
668 |
lShRed = __intVal(shiftRed), |
|
669 |
lShGreen = __intVal(shiftGreen), |
|
670 |
lShBlue = __intVal(shiftBlue); |
|
671 |
int x, y, w; |
|
672 |
||
673 |
w = __intVal(__INST(width)); |
|
674 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
675 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
676 |
for (x=w; x > 0; x--) { |
|
677 |
unsigned v; |
|
678 |
||
8094 | 679 |
v = srcPtr[_redOffs] << lShRed; |
680 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
681 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
682 |
# ifdef __MSBFIRST |
7122 | 683 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
684 |
# else /* not MSB */ |
7122 | 685 |
dstPtr[0] = (v>>24) & 0xFF; |
686 |
dstPtr[1] = (v>>16) & 0xFF; |
|
687 |
dstPtr[2] = (v>>8) & 0xFF; |
|
688 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
689 |
# endif /* not MSB */ |
7122 | 690 |
dstPtr += 4; |
691 |
srcPtr += 4; |
|
692 |
} |
|
693 |
} |
|
694 |
} else { |
|
695 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
696 |
for (x=w; x > 0; x--) { |
|
697 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
698 |
|
8094 | 699 |
r = srcPtr[_redOffs] >> rShRed; |
700 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
701 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 702 |
v = r << lShRed; |
703 |
v |= (g << lShGreen); |
|
704 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
705 |
# ifdef __MSBFIRST |
7122 | 706 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
707 |
# else /* not MSB */ |
7122 | 708 |
dstPtr[0] = (v>>24) & 0xFF; |
709 |
dstPtr[1] = (v>>16) & 0xFF; |
|
710 |
dstPtr[2] = (v>>8) & 0xFF; |
|
711 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
712 |
# endif /* not MSB */ |
7122 | 713 |
dstPtr += 4; |
714 |
srcPtr += 4; |
|
715 |
} |
|
716 |
} |
|
717 |
} |
|
718 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
719 |
%}. |
7122 | 720 |
] ifFalse:[ |
721 |
"/ |
|
722 |
"/ 8 bits/pixel ... |
|
723 |
"/ |
|
724 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
725 |
usedDevicePadding := 8. |
|
726 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
727 |
|
7122 | 728 |
"/ 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
|
729 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
730 |
%{ |
7122 | 731 |
unsigned char *srcPtr = 0; |
732 |
unsigned char *dstPtr = 0; |
|
8094 | 733 |
int _redOffs = __intVal(redOffs); |
734 |
int _greenOffs = __intVal(greenOffs); |
|
735 |
int _blueOffs = __intVal(blueOffs); |
|
736 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
737 |
|
7122 | 738 |
if (__isByteArrayLike(bytes)) { |
739 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
740 |
} else { |
|
741 |
if (__isExternalBytesLike(bytes)) { |
|
742 |
srcPtr = __externalBytesAddress(bytes); |
|
743 |
} |
|
744 |
} |
|
745 |
if (__isByteArray(imageBits)) { |
|
746 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
747 |
} else { |
|
748 |
if (__isExternalBytesLike(imageBits)) { |
|
749 |
dstPtr = __externalBytesAddress(imageBits); |
|
750 |
} |
|
751 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
752 |
|
7122 | 753 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
754 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
755 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
756 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
757 |
&& srcPtr |
|
758 |
&& dstPtr) { |
|
759 |
int rShRed = __intVal(rightShiftR), |
|
760 |
rShGreen = __intVal(rightShiftG), |
|
761 |
rShBlue = __intVal(rightShiftB), |
|
762 |
lShRed = __intVal(shiftRed), |
|
763 |
lShGreen = __intVal(shiftGreen), |
|
764 |
lShBlue = __intVal(shiftBlue); |
|
765 |
int x, y, w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
766 |
|
7122 | 767 |
w = __intVal(__INST(width)); |
768 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
769 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
770 |
for (x=w; x > 0; x--) { |
|
771 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
772 |
|
8094 | 773 |
v = srcPtr[_redOffs] << lShRed; |
774 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
775 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
7122 | 776 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
777 |
|
7122 | 778 |
dstPtr += 1; |
779 |
srcPtr += 4; |
|
780 |
} |
|
781 |
} |
|
782 |
} else { |
|
783 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
784 |
for (x=w; x > 0; x--) { |
|
785 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
786 |
|
8094 | 787 |
r = srcPtr[_redOffs] >> rShRed; |
788 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
789 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 790 |
v = r << lShRed; |
791 |
v |= (g << lShGreen); |
|
792 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
793 |
|
7122 | 794 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
795 |
|
7122 | 796 |
dstPtr += 1; |
797 |
srcPtr += 4; |
|
798 |
} |
|
799 |
} |
|
800 |
} |
|
801 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
802 |
%}. |
7122 | 803 |
] |
804 |
]. |
|
805 |
] |
|
4761
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 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
808 |
imageBits isNil ifTrue:[ |
7122 | 809 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
810 |
usedDeviceBitsPerPixel errorPrintCR. |
|
811 |
^ self asMonochromeFormOn:aDevice |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
812 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
813 |
|
7497 | 814 |
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
|
815 |
form isNil ifTrue:[ |
7122 | 816 |
'Depth32Image [warning]: display bitmap creation failed' errorPrintCR. |
817 |
^ nil |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
818 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
819 |
form initGC. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
820 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
821 |
form |
7122 | 822 |
copyBitsFrom:imageBits |
823 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
824 |
depth:usedDeviceDepth |
|
825 |
padding:usedDevicePadding |
|
826 |
width:width height:height |
|
827 |
x:0 y:0 toX:0 y:0. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
828 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
829 |
^ form |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
830 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
831 |
"Created: / 27-05-2007 / 16:54:19 / cg" |
8114 | 832 |
"Modified: / 27-08-2017 / 21:06:49 / cg" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
833 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
834 |
|
6841 | 835 |
!Depth32Image methodsFor:'image manipulations'! |
836 |
||
837 |
negative |
|
7922 | 838 |
|bytes |
839 |
index "{ Class: SmallInteger }" |
|
840 |
newImage newBytes nBytes r g b a| |
|
6841 | 841 |
|
842 |
photometric ~~ #rgb ifTrue:[ |
|
843 |
^ super negative. |
|
844 |
]. |
|
845 |
bytes := self bits. |
|
846 |
||
847 |
newImage := self copy. |
|
848 |
nBytes := bytes size. |
|
849 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
850 |
index := 1. |
|
851 |
[index < nBytes] whileTrue:[ |
|
852 |
r := bytes at:index. |
|
853 |
newBytes at:index put:(255-r). |
|
854 |
index := index + 1. |
|
8085 | 855 |
|
6841 | 856 |
g := bytes at:index. |
857 |
newBytes at:index put:(255-g). |
|
858 |
index := index + 1. |
|
8085 | 859 |
|
6841 | 860 |
b := bytes at:index. |
861 |
newBytes at:index put:(255-b). |
|
862 |
index := index + 1. |
|
8085 | 863 |
|
7922 | 864 |
a := bytes at:index. |
865 |
newBytes at:index put:a. |
|
6841 | 866 |
index := index + 1. |
867 |
]. |
|
868 |
^ newImage |
|
7922 | 869 |
|
8085 | 870 |
"Modified (format): / 22-08-2017 / 17:13:38 / cg" |
6841 | 871 |
! ! |
872 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
873 |
!Depth32Image methodsFor:'initialization'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
874 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
875 |
initialize |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
876 |
super initialize. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
877 |
samplesPerPixel := 4. |
7819 | 878 |
bitsPerSample := #[8 8 8 8]. |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
879 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
880 |
"Created: / 27-05-2007 / 14:09:16 / cg" |
7819 | 881 |
"Modified: / 30-01-2017 / 19:32:13 / stefan" |
4761
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 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
884 |
!Depth32Image methodsFor:'magnification'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
885 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
886 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
887 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
888 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
889 |
"magnify a single pixel row - can only magnify by integer factors" |
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 |
%{ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
892 |
unsigned char *srcP, *dstP; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
893 |
int _mag; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
894 |
REGISTER int i; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
895 |
REGISTER unsigned char byte1, byte2, byte3, byte4; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
896 |
int _pixels; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
897 |
OBJ w = __INST(width); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
898 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
899 |
if (__bothSmallInteger(srcStart, dstStart) |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
900 |
&& __bothSmallInteger(w, mX) |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
901 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
902 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
903 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
904 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
905 |
_pixels = __intVal(w); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
906 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
907 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
908 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
909 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
910 |
byte3 = *(srcP+2); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
911 |
byte4 = *(srcP+3); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
912 |
srcP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
913 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
914 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
915 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
916 |
*(dstP+2) = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
917 |
*(dstP+3) = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
918 |
dstP += 4; |
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 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
921 |
RETURN (self); |
4761
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 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
924 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
925 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
926 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
927 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
928 |
"Created: / 28-05-2007 / 15:20:52 / cg" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
929 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
930 |
|
1663 | 931 |
!Depth32Image methodsFor:'queries'! |
932 |
||
7122 | 933 |
alphaBitsOf:pixel |
934 |
"given a pixel-value, return the alpha component as byteValue (0..255)" |
|
935 |
||
8085 | 936 |
photometric == #argb ifTrue:[ |
937 |
"a,r,g,b; MSB" |
|
938 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
939 |
]. |
|
7122 | 940 |
photometric == #rgba ifTrue:[ |
8002 | 941 |
"r,g,b,a; MSB" |
7122 | 942 |
^ pixel bitAnd:16rFF. |
943 |
]. |
|
8085 | 944 |
"r,g,b,0; MSB" |
945 |
^ 0 |
|
8002 | 946 |
|
8085 | 947 |
"Modified: / 22-08-2017 / 17:18:44 / cg" |
7122 | 948 |
! |
949 |
||
950 |
alphaComponentOf:pixel |
|
951 |
"given a pixel-value, return the alpha component in percent (0..100)" |
|
952 |
||
953 |
^ (self alphaBitsOf:pixel) * (100.0 / 255.0) |
|
954 |
! |
|
955 |
||
956 |
alphaMaskForPixelValue |
|
7922 | 957 |
"return the mask used with translation from pixelValues to alphaBits. |
958 |
Determines the number of bits of alpha" |
|
7122 | 959 |
|
960 |
^ 16rFF |
|
7922 | 961 |
|
962 |
"Modified (comment): / 21-02-2017 / 16:37:31 / cg" |
|
7122 | 963 |
! |
964 |
||
965 |
alphaShiftForPixelValue |
|
7922 | 966 |
"return the shift amount used with translation from pixelValues to alphaBits. |
967 |
That is the number of bits to shift the alpha value into the pixel value." |
|
7122 | 968 |
|
969 |
photometric == #argb ifTrue:[ |
|
8085 | 970 |
"/ a,r,g,b - alpha in high byte |
7922 | 971 |
^ 24. |
7122 | 972 |
]. |
8085 | 973 |
"/ r,g,b,a - alpha in low byte |
974 |
"/ or r,g,b,0 - no alpha |
|
975 |
^ 0 |
|
7896 | 976 |
|
8085 | 977 |
"Modified: / 22-08-2017 / 17:19:36 / cg" |
7122 | 978 |
! |
979 |
||
1663 | 980 |
bitsPerPixel |
981 |
"return the number of bits per pixel" |
|
982 |
||
983 |
^ 32 |
|
984 |
||
985 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
986 |
! |
|
987 |
||
988 |
bitsPerRow |
|
989 |
"return the number of bits in one scanline of the image" |
|
990 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
991 |
^ width * 32 |
1663 | 992 |
|
993 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
994 |
! |
|
995 |
||
6841 | 996 |
bitsPerSample |
997 |
"return the number of bits per sample. |
|
998 |
The return value is an array of bits-per-plane." |
|
999 |
||
1000 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
|
7819 | 1001 |
^ #[8 8 8 8] |
1002 |
||
1003 |
"Modified: / 30-01-2017 / 19:23:31 / stefan" |
|
6841 | 1004 |
! |
1005 |
||
1006 |
blueBitsOf:pixel |
|
1007 |
"given a pixel-value, return the blue component as byteValue (0..255)" |
|
1008 |
||
8089 | 1009 |
photometric == #rgba ifTrue:[ |
1010 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
7122 | 1011 |
]. |
8089 | 1012 |
"r,g,b,a or ignored,r,g,b" |
1013 |
^ pixel bitAnd:16rFF. |
|
7922 | 1014 |
|
8089 | 1015 |
"Modified: / 22-08-2017 / 18:23:41 / cg" |
6841 | 1016 |
! |
1017 |
||
1018 |
blueComponentOf:pixel |
|
1019 |
"given a pixel-value, return the blue component in percent (0..100)" |
|
1020 |
||
7122 | 1021 |
^ (self blueBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1022 |
! |
1023 |
||
1024 |
blueMaskForPixelValue |
|
1025 |
"return the mask used with translation from pixelValues to blueBits" |
|
1026 |
||
1027 |
^ 16rFF |
|
1028 |
! |
|
1029 |
||
1030 |
blueShiftForPixelValue |
|
1031 |
"return the shift amount used with translation from pixelValues to blueBits" |
|
1032 |
||
7122 | 1033 |
photometric == #argb ifTrue:[ |
1034 |
"a,r,g,b" |
|
1035 |
^ 0. |
|
1036 |
]. |
|
8085 | 1037 |
"r,g,b,a or r,g,b,0" |
1038 |
^ -8 |
|
7922 | 1039 |
|
8085 | 1040 |
"Modified: / 22-08-2017 / 17:19:55 / cg" |
6841 | 1041 |
! |
1042 |
||
1663 | 1043 |
bytesPerRow |
1044 |
"return the number of bytes in one scanline of the image" |
|
1045 |
||
1046 |
^ width * 4. |
|
1047 |
||
1048 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
5327 | 1049 |
! |
1050 |
||
6841 | 1051 |
greenBitsOf:pixel |
1052 |
"given a pixel-value, return the green component as byteValue (0..255)" |
|
1053 |
||
8089 | 1054 |
photometric == #rgba ifTrue:[ |
1055 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
7122 | 1056 |
]. |
8089 | 1057 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
7922 | 1058 |
|
8089 | 1059 |
"Modified: / 22-08-2017 / 18:25:26 / cg" |
6841 | 1060 |
! |
1061 |
||
1062 |
greenComponentOf:pixel |
|
1063 |
"given a pixel-value, return the green component in percent (0..100)" |
|
1064 |
||
7122 | 1065 |
^ (self greenBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1066 |
! |
1067 |
||
1068 |
greenMaskForPixelValue |
|
1069 |
"return the mask used with translation from pixelValues to redBits" |
|
1070 |
||
1071 |
^ 16rFF |
|
1072 |
! |
|
1073 |
||
1074 |
greenShiftForPixelValue |
|
1075 |
"return the shift amount used with translation from pixelValues to greenBits" |
|
1076 |
||
7122 | 1077 |
photometric == #argb ifTrue:[ |
1078 |
"a,r,g,b" |
|
1079 |
^ -8. |
|
1080 |
]. |
|
8085 | 1081 |
"r,g,b,a or r,g,b,0" |
1082 |
^ -16 |
|
7922 | 1083 |
|
8085 | 1084 |
"Modified: / 22-08-2017 / 17:20:14 / cg" |
6841 | 1085 |
! |
1086 |
||
5327 | 1087 |
hasAlphaChannel |
7922 | 1088 |
"could be #rgb in 32 bits..." |
1089 |
||
1090 |
^ (photometric == #argb) or:[photometric == #rgba] |
|
1091 |
||
1092 |
"Modified: / 21-02-2017 / 15:00:17 / cg" |
|
6841 | 1093 |
! |
1094 |
||
8085 | 1095 |
numAlphaBits |
1096 |
photometric == #argb ifTrue:[ |
|
1097 |
^ 8. |
|
1098 |
]. |
|
1099 |
photometric == #rgba ifTrue:[ |
|
1100 |
^ 8. |
|
1101 |
]. |
|
1102 |
^ 0 |
|
1103 |
||
1104 |
"Created: / 22-08-2017 / 17:38:59 / cg" |
|
1105 |
! |
|
1106 |
||
1107 |
numBlueBits |
|
1108 |
^ 8 |
|
1109 |
||
1110 |
"Created: / 22-08-2017 / 17:38:31 / cg" |
|
1111 |
! |
|
1112 |
||
1113 |
numGreenBits |
|
1114 |
^ 8 |
|
1115 |
||
1116 |
"Created: / 22-08-2017 / 17:38:28 / cg" |
|
1117 |
! |
|
1118 |
||
1119 |
numRedBits |
|
1120 |
^ 8 |
|
1121 |
||
1122 |
"Created: / 22-08-2017 / 17:38:25 / cg" |
|
1123 |
! |
|
1124 |
||
6841 | 1125 |
redBitsOf:pixel |
1126 |
"given a pixel-value, return the red component as byteValue (0..255)" |
|
1127 |
||
8089 | 1128 |
photometric == #rgba ifTrue:[ |
1129 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
7122 | 1130 |
]. |
8089 | 1131 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
7922 | 1132 |
|
8089 | 1133 |
"Modified: / 22-08-2017 / 18:25:52 / cg" |
6841 | 1134 |
! |
1135 |
||
1136 |
redComponentOf:pixel |
|
1137 |
"given a pixel-value, return the red component in percent (0..100)" |
|
1138 |
||
7122 | 1139 |
^ (self redBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1140 |
! |
1141 |
||
1142 |
redMaskForPixelValue |
|
1143 |
"return the mask used with translation from pixelValues to redBits" |
|
1144 |
||
1145 |
^ 16rFF |
|
1146 |
! |
|
1147 |
||
1148 |
redShiftForPixelValue |
|
1149 |
"return the shift amount used with translation from pixelValues to redBits" |
|
1150 |
||
8089 | 1151 |
photometric == #rgba ifTrue:[ |
1152 |
^ -24. |
|
7122 | 1153 |
]. |
8089 | 1154 |
^ -16 |
7922 | 1155 |
|
8089 | 1156 |
"Modified: / 22-08-2017 / 18:27:02 / cg" |
6841 | 1157 |
! |
1158 |
||
1159 |
rgbFromValue:pixelValue |
|
1160 |
"given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB)." |
|
1161 |
||
8089 | 1162 |
(photometric == #rgba) ifTrue:[ |
7922 | 1163 |
^ pixelValue rightShift:8 "lsb is alpha channel" |
1164 |
]. |
|
8089 | 1165 |
((photometric == #rgb) or:[photometric == #argb]) ifTrue:[ |
1166 |
^ pixelValue bitAnd:16rFFFFFF "msb is alpha channel" |
|
7922 | 1167 |
]. |
8089 | 1168 |
^ super rgbFromValue:pixelValue. |
7922 | 1169 |
|
8089 | 1170 |
"Modified: / 22-08-2017 / 18:32:22 / cg" |
6841 | 1171 |
! |
1172 |
||
1173 |
samplesPerPixel |
|
1174 |
"return the number of samples per pixel in the image." |
|
1175 |
||
1176 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
|
1177 |
^ 4 |
|
1178 |
! |
|
1179 |
||
1180 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
|
8089 | 1181 |
(photometric == #rgba) ifTrue:[ |
7922 | 1182 |
"/ alpha in low byte |
1183 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:16rFF |
|
1184 |
]. |
|
1185 |
(photometric == #argb) ifTrue:[ |
|
1186 |
"/ alpha in high byte |
|
1187 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:16rFF000000 |
|
1188 |
]. |
|
8085 | 1189 |
(photometric == #rgb) ifTrue:[ |
8089 | 1190 |
"/ no alpha |
1191 |
^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits |
|
8085 | 1192 |
]. |
8089 | 1193 |
^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits. |
7922 | 1194 |
|
8089 | 1195 |
"Modified: / 22-08-2017 / 18:34:30 / cg" |
8166 | 1196 |
! |
1197 |
||
1198 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits alphaBits:alphaBits |
|
1199 |
(photometric == #rgba) ifTrue:[ |
|
1200 |
"/ alpha in low byte |
|
1201 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:alphaBits |
|
1202 |
]. |
|
1203 |
(photometric == #argb) ifTrue:[ |
|
1204 |
"/ alpha in high byte |
|
1205 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:(alphaBits bitShift:24) |
|
1206 |
]. |
|
1207 |
(photometric == #rgb) ifTrue:[ |
|
1208 |
"/ no alpha |
|
1209 |
^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits |
|
1210 |
]. |
|
1211 |
^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits. |
|
1212 |
||
1213 |
"Created: / 05-09-2017 / 14:31:38 / cg" |
|
1663 | 1214 |
! ! |
1215 |
||
1216 |
!Depth32Image class methodsFor:'documentation'! |
|
1217 |
||
1218 |
version |
|
7122 | 1219 |
^ '$Header$' |
5474
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 |
|
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1222 |
version_CVS |
7122 | 1223 |
^ '$Header$' |
1663 | 1224 |
! ! |
6302 | 1225 |