author | Claus Gittinger <cg@exept.de> |
Sat, 20 Apr 2019 09:14:08 +0200 | |
changeset 8673 | 8cda4102607a |
parent 8339 | b2b10047577b |
child 8728 | 289cdc983b33 |
permissions | -rw-r--r-- |
8339 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1663 | 3 |
" |
4 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
5 |
All Rights Reserved |
1663 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3263 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6841 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1663 | 18 |
Image subclass:#Depth32Image |
19 |
instanceVariableNames:'' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Graphics-Images' |
|
23 |
! |
|
24 |
||
25 |
!Depth32Image class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
30 |
All Rights Reserved |
1663 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
7902 | 43 |
this class represents 32 bit (eg. rgb+alpha) images. |
44 |
||
1663 | 45 |
Only the minimum protocol is implemented here; much more is |
46 |
needed for higher performance operations on depth32 images. |
|
7902 | 47 |
|
8327 | 48 |
with #rgb, #rgba, #rgbx, photometrics |
49 |
pixels are internally stored byte-wise in rgba order. |
|
50 |
(i.e. r at low-address byte, a at high-address byte). |
|
51 |
For rgb, a zero is always retrieved as alpha; 255 for rgbx. |
|
52 |
||
53 |
When reading pixel values, photometric argb is returned as aarrggbb, |
|
54 |
photometric rgb is returned as 00rrggbb, |
|
55 |
photometric rgba is returned as rrggbb00, |
|
56 |
both on LSB and on MSB machines. |
|
57 |
(i.e. blue in lower bits of the returned 32bit integer, alpha in the high bits for argb, |
|
58 |
and in the low bits for rgba) |
|
59 |
Thus, pixelValues and rgbValues are identical, simulating MSB on all |
|
60 |
architectures. |
|
61 |
(this should be transparent, if you use the rgbValueAt |
|
62 |
accessors; however, some old code uses pixelValueAt:, assuming that the |
|
63 |
returned pixel value is rrggbb - which it would not be without this hack). |
|
64 |
||
65 |
This also makes depth24Image's rgbValues compatible with depth32Image's rgbValues. |
|
66 |
||
67 |
For argb and xrgb formats, alpha (or dummy alpha) is in the first byte |
|
68 |
(which are the high bits, as we present pixel values always MSB). |
|
69 |
||
1663 | 70 |
[author:] |
7902 | 71 |
Claus Gittinger |
1663 | 72 |
|
73 |
[see also:] |
|
7902 | 74 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image |
75 |
ImageReader |
|
1663 | 76 |
" |
77 |
! ! |
|
78 |
||
79 |
!Depth32Image class methodsFor:'queries'! |
|
80 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
81 |
defaultPhotometric |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
82 |
"return the default photometric pixel interpretation" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
83 |
|
7903 | 84 |
"/ here we return #rgb - thus ignoring any alpha channel. |
85 |
"/ the reason is that many displays and graphics formats do use |
|
86 |
"/ 32bit per pixel, but provide an alpha value of 0, instead of 255. |
|
87 |
"/ Thus returning rgba here would make many images invisible (totally transparent) |
|
88 |
||
5324 | 89 |
^ #rgb |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
90 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
91 |
"Created: / 27-05-2007 / 14:03:59 / cg" |
7903 | 92 |
"Modified: / 16-02-2017 / 17:41:09 / cg" |
93 |
"Modified (comment): / 16-02-2017 / 19:00:25 / cg" |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
94 |
! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
95 |
|
1663 | 96 |
imageDepth |
97 |
"return the depth of images represented by instances of |
|
98 |
this class - here we return 32" |
|
99 |
||
100 |
^ 32 |
|
101 |
||
102 |
"Modified: 20.4.1996 / 23:40:01 / cg" |
|
103 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
104 |
! ! |
|
105 |
||
3263 | 106 |
!Depth32Image methodsFor:'accessing-pixels'! |
1663 | 107 |
|
6841 | 108 |
colorAtX:x y:y |
109 |
"retrieve a pixel at x/y; return a color. |
|
7124 | 110 |
Pixels start at x=0 , y=0 for upper left pixel, |
111 |
end at x = width-1, y=height-1 for lower right pixel" |
|
6841 | 112 |
|
113 |
|index "{ Class: SmallInteger }" |
|
7124 | 114 |
rVal gVal bVal aVal| |
6841 | 115 |
|
116 |
index := 1 + (((width * y) + x) * 4). |
|
8339 | 117 |
((photometric == #rgb) or:[photometric == #xrgb]) ifTrue:[ |
118 |
"/ byteorder is: <ignoredAlpha>,r,g,b |
|
119 |
rVal := bytes at:(index + 1). |
|
120 |
gVal := bytes at:(index + 2). |
|
121 |
bVal := bytes at:(index + 3). |
|
7124 | 122 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal |
123 |
]. |
|
8327 | 124 |
(photometric == #rgba) ifTrue:[ |
125 |
"/ byteorder is: r,g,b,<ignoredAlpha> |
|
7124 | 126 |
rVal := bytes at:(index). |
127 |
gVal := bytes at:(index + 1). |
|
128 |
bVal := bytes at:(index + 2). |
|
129 |
aVal := bytes at:(index + 3). |
|
130 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal |
|
131 |
]. |
|
132 |
photometric == #argb ifTrue:[ |
|
8327 | 133 |
"/ byteorder is: a,r,g,b |
7124 | 134 |
aVal := bytes at:(index). |
135 |
rVal := bytes at:(index + 1). |
|
136 |
gVal := bytes at:(index + 2). |
|
137 |
bVal := bytes at:(index + 3). |
|
138 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal |
|
139 |
]. |
|
8339 | 140 |
photometric == #xrgb ifTrue:[ |
141 |
"/ byteorder is: ignored-alpha,r,g,b |
|
142 |
rVal := bytes at:(index + 1). |
|
143 |
gVal := bytes at:(index + 2). |
|
144 |
bVal := bytes at:(index + 3). |
|
145 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal |
|
146 |
]. |
|
7124 | 147 |
"/ the inherited method should handle all cases. |
8089 | 148 |
^ super colorAtX:x y:y. |
149 |
||
150 |
"Modified: / 22-08-2017 / 18:17:38 / cg" |
|
6841 | 151 |
! |
152 |
||
153 |
colorAtX:x y:y put:aColor |
|
154 |
"set the pixel at x/y to aColor. |
|
155 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
156 |
x = width-1, y=height-1 for lower right pixel." |
|
157 |
||
8089 | 158 |
|index "{ Class: SmallInteger }" |
159 |
r g b| |
|
6841 | 160 |
|
8085 | 161 |
index := 1 + (((width * y) + x) * 4). |
8089 | 162 |
r := aColor redByte. |
163 |
g := aColor greenByte. |
|
164 |
b := aColor blueByte. |
|
165 |
||
8339 | 166 |
((photometric == #rgb) or:[(photometric == #xrgb)]) ifTrue:[ |
167 |
"/ byteorder is: ignored-alpha,r,g,b |
|
168 |
bytes at:(index + 1) put:r. |
|
169 |
bytes at:(index + 2) put:g. |
|
170 |
bytes at:(index + 3) put:b. |
|
8085 | 171 |
^ self |
172 |
]. |
|
173 |
(photometric == #rgba) ifTrue:[ |
|
8327 | 174 |
"/ byteorder is: r,g,b,a |
8089 | 175 |
bytes at:(index + 0) put:r. |
176 |
bytes at:(index + 1) put:g. |
|
177 |
bytes at:(index + 2) put:b. |
|
8085 | 178 |
bytes at:(index + 3) put:(aColor alphaByte). "alpha channel in last byte" |
7167 | 179 |
^ self |
180 |
]. |
|
181 |
(photometric == #argb) ifTrue:[ |
|
8327 | 182 |
"/ byteorder is: a,r,g,b |
8089 | 183 |
bytes at:(index + 0) put:(aColor alphaByte). "alpha channel in first byte" |
184 |
bytes at:(index + 1) put:r. |
|
185 |
bytes at:(index + 2) put:g. |
|
186 |
bytes at:(index + 3) put:b. |
|
7167 | 187 |
^ self |
188 |
]. |
|
8327 | 189 |
(photometric == #rgbx) ifTrue:[ |
190 |
"/ byteorder is: <ignoredAlpha>,r,g,b |
|
8339 | 191 |
bytes at:(index + 0) put:r. |
8327 | 192 |
bytes at:(index + 1) put:g. |
193 |
bytes at:(index + 2) put:b. |
|
194 |
^ self |
|
195 |
]. |
|
6841 | 196 |
|
7917 | 197 |
super colorAtX:x y:y put:aColor. |
198 |
||
8089 | 199 |
"Modified: / 22-08-2017 / 18:17:14 / cg" |
6841 | 200 |
! |
201 |
||
1663 | 202 |
pixelAtX:x y:y |
203 |
"retrieve a pixel at x/y; return a pixelValue. |
|
7514 | 204 |
The interpretation of the returned value depends on the photometric |
205 |
and the colormap. See also Image>>atX:y:) |
|
1663 | 206 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
7279 | 207 |
x = width-1, y=height-1 for lower right pixel. |
8327 | 208 |
With rgba photometric, the pixel value contains r/g/b/a in lsb order |
209 |
(i.e. r at low, a at high bits); |
|
210 |
with argb, alpha is in the low byte" |
|
1663 | 211 |
|
1669 | 212 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 213 |
|
7274 | 214 |
%{ /* NOCONTEXT */ |
215 |
OBJ b = __INST(bytes); |
|
216 |
OBJ w = __INST(width); |
|
217 |
||
218 |
if (__isByteArrayLike(b) |
|
219 |
&& __bothSmallInteger(x, y) |
|
220 |
&& __isSmallInteger(w) |
|
221 |
&& (__INST(pixelFunction)==nil) ) { |
|
222 |
int _idx; |
|
223 |
||
224 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
|
225 |
if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
|
226 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
227 |
unsigned int _pix; |
|
7917 | 228 |
|
7922 | 229 |
#ifdef __MSBFIRST__ |
230 |
_pix = ((int *)pPix)[0]; |
|
231 |
#else |
|
232 |
_pix = pPix[0] << 24; |
|
233 |
_pix |= pPix[1] << 16; |
|
234 |
_pix |= pPix[2] << 8; |
|
235 |
_pix |= pPix[3]; |
|
236 |
#endif |
|
237 |
||
7274 | 238 |
#if __POINTER_SIZE__ == 8 |
239 |
RETURN( __MKSMALLINT(_pix) ); |
|
240 |
#else |
|
241 |
RETURN( __MKUINT(_pix) ); |
|
242 |
#endif |
|
243 |
} |
|
244 |
} |
|
245 |
%}. |
|
6302 | 246 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
247 |
||
6841 | 248 |
pixelIndex := 1 + (((width * y) + x) * 4). |
7922 | 249 |
^ bytes unsignedInt32At:pixelIndex MSB:true. |
1663 | 250 |
|
7917 | 251 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
7922 | 252 |
"Modified: / 21-02-2017 / 17:21:44 / cg" |
8089 | 253 |
"Modified (comment): / 22-08-2017 / 18:24:22 / cg" |
1663 | 254 |
! |
255 |
||
256 |
pixelAtX:x y:y put:aPixelValue |
|
257 |
"set the pixel at x/y to aPixelValue. |
|
7922 | 258 |
The interpretation of the pixelValue depends on the photometric. |
1663 | 259 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
8327 | 260 |
x = width-1, y=height-1 for lower right pixel. |
261 |
With rgba photometric, the pixel value contains r/g/b/a in lsb order |
|
262 |
(i.e. r at low, a at high bits); |
|
263 |
with argb, alpha is in the low byte" |
|
1663 | 264 |
|
1669 | 265 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 266 |
|
8089 | 267 |
%{ /* NOCONTEXT */ |
268 |
OBJ b = __INST(bytes); |
|
269 |
OBJ w = __INST(width); |
|
270 |
||
271 |
if ((b != nil) |
|
272 |
&& __isByteArrayLike(b) |
|
273 |
&& __bothSmallInteger(x, y) |
|
274 |
&& __isSmallInteger(aPixelValue) |
|
275 |
&& (__INST(pixelFunction)==nil) ) { |
|
276 |
int _idx; |
|
277 |
||
278 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
|
279 |
if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
|
280 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
281 |
unsigned int _pix = __intVal(aPixelValue); |
|
282 |
||
283 |
#ifdef __MSBFIRST__ |
|
284 |
((int *)pPix)[0] = _pix; |
|
285 |
#else |
|
286 |
pPix[0] = (_pix >> 24) & 0xFF; |
|
287 |
pPix[1] = (_pix >> 16) & 0xFF; |
|
288 |
pPix[2] = (_pix >> 8) & 0xFF; |
|
289 |
pPix[3] = _pix & 0xFF; |
|
290 |
#endif |
|
291 |
RETURN(self); |
|
292 |
} |
|
293 |
} |
|
294 |
%}. |
|
8201 | 295 |
bytes isNil ifTrue:[ self createPixelStore ]. |
296 |
||
6841 | 297 |
pixelIndex := 1 + (((width * y) + x) * 4). |
7922 | 298 |
bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true. |
1663 | 299 |
|
4790 | 300 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
8089 | 301 |
"Modified: / 22-08-2017 / 18:21:47 / cg" |
6841 | 302 |
! |
303 |
||
304 |
rowAt:y putAll:pixelArray startingAt:startIndex |
|
305 |
"store a single rows bits from bits in the pixelArray argument; |
|
8327 | 306 |
The interpretation of the pixel values depends on the photometric. |
6841 | 307 |
Notice: row coordinate starts at 0." |
308 |
||
7922 | 309 |
|bytes pixel |
310 |
dstIdx "{ Class: SmallInteger }" |
|
6846 | 311 |
w "{ Class: SmallInteger }"| |
6841 | 312 |
|
313 |
bytes := self bits. |
|
314 |
dstIdx := (y * self bytesPerRow) + 1. |
|
6846 | 315 |
w := width - 1. |
316 |
||
317 |
0 to:w do:[:col | |
|
6841 | 318 |
pixel := pixelArray at:(startIndex + col). |
8327 | 319 |
"/ msbFirst |
7922 | 320 |
bytes unsignedInt32At:dstIdx put:pixel MSB:true. |
6841 | 321 |
dstIdx := dstIdx + 4. |
322 |
]. |
|
7917 | 323 |
|
7922 | 324 |
"Modified (comment): / 21-02-2017 / 15:03:24 / cg" |
1663 | 325 |
! ! |
326 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
327 |
!Depth32Image methodsFor:'converting rgb images'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
328 |
|
7492 | 329 |
computeAlphaValuesFromMask:aMaskImage |
330 |
"convert a mask into alpha values; |
|
7922 | 331 |
masked pixels get an alpha value of 0, unmasked of 255" |
7492 | 332 |
|
333 |
|alphaMask| |
|
334 |
||
7922 | 335 |
alphaMask := (self alphaMaskForPixelValue bitShift:self alphaShiftForPixelValue). |
7902 | 336 |
self |
337 |
valuesFromX:0 y:0 toX:(width-1) y:(height-1) |
|
338 |
do:[:x :y :pixelValue | |
|
339 |
(aMaskImage pixelAtX:x y:y) ~~ 0 ifTrue:[ |
|
340 |
self pixelAtX:x y:y put:(pixelValue bitOr:alphaMask). |
|
341 |
] ifFalse:[ |
|
342 |
self pixelAtX:x y:y put:(pixelValue bitClear:alphaMask). |
|
343 |
]. |
|
7492 | 344 |
]. |
345 |
photometric := #rgba |
|
7902 | 346 |
|
7922 | 347 |
"Modified: / 21-02-2017 / 16:41:02 / cg" |
7492 | 348 |
! |
349 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
350 |
rgbImageAsTrueColorFormOn:aDevice |
7122 | 351 |
"return a truecolor form from the rgba or argb-picture." |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
352 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
353 |
|bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
354 |
myDepth form imageBits padd |
8000 | 355 |
rightShiftR rightShiftG rightShiftB |
8094 | 356 |
shiftRed shiftGreen shiftBlue |
357 |
redOffs greenOffs blueOffs alphaOffs| |
|
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 |
bytes := self bits. |
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 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4763 | 362 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
363 |
usedDeviceDepth := bestFormat at:#depth. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
364 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
365 |
usedDevicePadding := bestFormat at:#padding. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
366 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
367 |
rightShiftR := (8 - aDevice bitsRed). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
368 |
rightShiftG := (8 - aDevice bitsGreen). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
369 |
rightShiftB := (8 - aDevice bitsBlue). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
370 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
371 |
shiftRed := aDevice shiftRed. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
372 |
shiftGreen := aDevice shiftGreen. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
373 |
shiftBlue := aDevice shiftBlue. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
374 |
|
8094 | 375 |
redOffs := 0. |
376 |
greenOffs := 1. |
|
377 |
blueOffs := 2. |
|
378 |
alphaOffs := 3. |
|
379 |
||
380 |
((photometric == #argb) or:[ photometric == #rgb ]) ifTrue:[ |
|
381 |
redOffs := 1. greenOffs := 2. blueOffs := 3. alphaOffs := 0. |
|
8114 | 382 |
] ifFalse:[ |
383 |
(photometric == #rgba) ifFalse:[ |
|
384 |
^ self anyImageAsTrueColorFormOn:aDevice |
|
385 |
]. |
|
386 |
]. |
|
8094 | 387 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
388 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
389 |
"/ for now, only a few formats are supported |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
390 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
391 |
myDepth := self bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
392 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
7122 | 393 |
"/ |
394 |
"/ 24 bit/pixel |
|
395 |
"/ |
|
396 |
imageBits := ByteArray uninitializedNew:(width * height * 3). |
|
397 |
usedDevicePadding := 8. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
398 |
|
7122 | 399 |
"/ now, walk over the image and compose 24bit values from the r/g/b/a triples |
400 |
%{ |
|
401 |
unsigned char *srcPtr = 0; |
|
402 |
unsigned char *dstPtr = 0; |
|
8094 | 403 |
int _redOffs = __intVal(redOffs); |
404 |
int _greenOffs = __intVal(greenOffs); |
|
405 |
int _blueOffs = __intVal(blueOffs); |
|
406 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
407 |
|
7122 | 408 |
if (__isByteArrayLike(bytes)) { |
409 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
410 |
} else { |
|
411 |
if (__isExternalBytesLike(bytes)) { |
|
412 |
srcPtr = __externalBytesAddress(bytes); |
|
413 |
} |
|
414 |
} |
|
415 |
if (__isByteArray(imageBits)) { |
|
416 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
417 |
} else { |
|
418 |
if (__isExternalBytesLike(imageBits)) { |
|
419 |
dstPtr = __externalBytesAddress(imageBits); |
|
420 |
} |
|
421 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
422 |
|
7122 | 423 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
424 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
425 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
426 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
427 |
&& srcPtr |
|
428 |
&& dstPtr) { |
|
429 |
int rShRed = __intVal(rightShiftR), |
|
430 |
rShGreen = __intVal(rightShiftG), |
|
431 |
rShBlue = __intVal(rightShiftB), |
|
432 |
lShRed = __intVal(shiftRed), |
|
433 |
lShGreen = __intVal(shiftGreen), |
|
434 |
lShBlue = __intVal(shiftBlue); |
|
435 |
int x, y, w; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
436 |
|
7122 | 437 |
w = __intVal(__INST(width)); |
438 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
439 |
if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) { |
|
440 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
441 |
for (x=w; x > 0; x--) { |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
442 |
# ifdef __MSBFIRST |
8094 | 443 |
dstPtr[0] = srcPtr[_redOffs]; |
444 |
dstPtr[1] = srcPtr[_greenOffs]; |
|
445 |
dstPtr[2] = srcPtr[_blueOffs]; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
446 |
# else /* not MSB */ |
8094 | 447 |
dstPtr[0] = srcPtr[_blueOffs]; |
448 |
dstPtr[1] = srcPtr[_greenOffs]; |
|
449 |
dstPtr[2] = srcPtr[_redOffs]; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
450 |
# endif /* not MSB */ |
7122 | 451 |
dstPtr += 3; |
452 |
srcPtr += 4; |
|
453 |
} |
|
454 |
} |
|
455 |
} else { |
|
456 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
457 |
for (x=w; x > 0; x--) { |
|
458 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
459 |
|
8094 | 460 |
v = srcPtr[_redOffs] << lShRed; |
461 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
462 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
463 |
# ifdef __MSBFIRST |
7122 | 464 |
dstPtr[0] = (v) & 0xFF; |
465 |
dstPtr[1] = (v>>8) & 0xFF; |
|
466 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
467 |
# else /* not MSB */ |
7122 | 468 |
dstPtr[0] = (v>>16) & 0xFF; |
469 |
dstPtr[1] = (v>>8) & 0xFF; |
|
470 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
471 |
# endif /* not MSB */ |
7122 | 472 |
dstPtr += 3; |
473 |
srcPtr += 4; |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
} else { |
|
478 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
479 |
for (x=w; x > 0; x--) { |
|
480 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
481 |
|
8094 | 482 |
r = srcPtr[_redOffs] >> rShRed; |
483 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
484 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 485 |
v = r << lShRed; |
486 |
v |= (g << lShGreen); |
|
487 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
488 |
# ifdef __MSBFIRST |
7122 | 489 |
dstPtr[0] = (v) & 0xFF; |
490 |
dstPtr[1] = (v>>8) & 0xFF; |
|
491 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
492 |
# else /* not MSB */ |
7122 | 493 |
dstPtr[0] = (v>>16) & 0xFF; |
494 |
dstPtr[1] = (v>>8) & 0xFF; |
|
495 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
496 |
# endif /* not MSB */ |
7122 | 497 |
dstPtr += 3; |
498 |
srcPtr += 4; |
|
499 |
} |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
503 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
504 |
] ifFalse:[ |
7122 | 505 |
"/ |
506 |
"/ 8, 16 or 32 bit/pixel ... |
|
507 |
"/ |
|
508 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
|
509 |
padd := width \\ (usedDevicePadding // 16). |
|
510 |
imageBits := ByteArray uninitializedNew:((width + padd) * height * 2). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
511 |
|
7122 | 512 |
"/ 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
|
513 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
514 |
%{ |
7122 | 515 |
unsigned char *srcPtr = 0; |
516 |
unsigned char *dstPtr = 0; |
|
8094 | 517 |
int _redOffs = __intVal(redOffs); |
518 |
int _greenOffs = __intVal(greenOffs); |
|
519 |
int _blueOffs = __intVal(blueOffs); |
|
520 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
521 |
|
7122 | 522 |
if (__isByteArrayLike(bytes)) { |
523 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
524 |
} else { |
|
525 |
if (__isExternalBytesLike(bytes)) { |
|
526 |
srcPtr = __externalBytesAddress(bytes); |
|
527 |
} |
|
528 |
} |
|
529 |
if (__isByteArray(imageBits)) { |
|
530 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
531 |
} else { |
|
532 |
if (__isExternalBytesLike(imageBits)) { |
|
533 |
dstPtr = __externalBytesAddress(imageBits); |
|
534 |
} |
|
535 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
536 |
|
7122 | 537 |
if (__bothSmallInteger(__INST(height),__INST(width)) |
538 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
539 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
540 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
541 |
&& srcPtr |
|
542 |
&& dstPtr) { |
|
543 |
int rShRed = __intVal(rightShiftR), |
|
544 |
rShGreen = __intVal(rightShiftG), |
|
545 |
rShBlue = __intVal(rightShiftB), |
|
546 |
lShRed = __intVal(shiftRed), |
|
547 |
lShGreen = __intVal(shiftGreen), |
|
548 |
lShBlue = __intVal(shiftBlue); |
|
549 |
int x, y, w; |
|
550 |
int p; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
551 |
|
7122 | 552 |
w = __intVal(__INST(width)); |
553 |
p = __intVal(padd) * 2; |
|
554 |
||
555 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
556 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
557 |
for (x=w; x > 0; x--) { |
|
558 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
559 |
|
8094 | 560 |
v = srcPtr[_redOffs] << lShRed; |
561 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
562 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
563 |
# ifdef __MSBFIRST |
7122 | 564 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
565 |
# else /* not MSB */ |
7122 | 566 |
dstPtr[0] = (v>>8) & 0xFF; |
567 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
568 |
# endif /* not MSB */ |
7122 | 569 |
dstPtr += 2; |
570 |
srcPtr += 4; |
|
571 |
} |
|
572 |
dstPtr += p; |
|
573 |
} |
|
574 |
} else { |
|
575 |
if (p == 0) { |
|
576 |
int n = __intVal(__INST(height)) * w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
577 |
|
7122 | 578 |
while (n >= 2) { |
579 |
unsigned w, r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
580 |
|
7122 | 581 |
n -= 2; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
582 |
|
8094 | 583 |
r = srcPtr[_redOffs]; |
584 |
g = srcPtr[_greenOffs]; |
|
585 |
b = srcPtr[_blueOffs]; |
|
7122 | 586 |
v = (r >> rShRed) << lShRed; |
587 |
v |= ((g >> rShGreen) << lShGreen); |
|
588 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
589 |
# ifdef __MSBFIRST |
7122 | 590 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
591 |
# else |
7122 | 592 |
dstPtr[0] = (v>>8) & 0xFF; |
593 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
594 |
# endif /* not MSB */ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
595 |
|
8094 | 596 |
r = srcPtr[3+_redOffs]; |
597 |
g = srcPtr[3+_greenOffs]; |
|
598 |
b = srcPtr[3+_blueOffs]; |
|
7122 | 599 |
v = (r >> rShRed) << lShRed; |
600 |
v |= ((g >> rShGreen) << lShGreen); |
|
601 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
602 |
# ifdef __MSBFIRST |
7122 | 603 |
((short *)dstPtr)[1] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
604 |
# else |
7122 | 605 |
dstPtr[2] = (v>>8) & 0xFF; |
606 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
607 |
# endif /* not MSB */ |
7122 | 608 |
dstPtr += 4; |
609 |
srcPtr += 8; |
|
610 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
611 |
|
7122 | 612 |
while (n--) { |
613 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
614 |
|
8094 | 615 |
r = srcPtr[_redOffs] >> rShRed; |
616 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
617 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 618 |
v = r << lShRed; |
619 |
v |= (g << lShGreen); |
|
620 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
621 |
# ifdef __MSBFIRST |
7122 | 622 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
623 |
# else /* not MSB */ |
7122 | 624 |
dstPtr[0] = (v>>8) & 0xFF; |
625 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
626 |
# endif /* not MSB */ |
7122 | 627 |
dstPtr += 2; |
628 |
srcPtr += 4; |
|
629 |
} |
|
630 |
} else { |
|
631 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
632 |
for (x=w; x > 0; x--) { |
|
633 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
634 |
|
8094 | 635 |
r = srcPtr[_redOffs] >> rShRed; |
636 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
637 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 638 |
v = r << lShRed; |
639 |
v |= (g << lShGreen); |
|
640 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
641 |
# ifdef __MSBFIRST |
7122 | 642 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
643 |
# else /* not MSB */ |
7122 | 644 |
dstPtr[0] = (v>>8) & 0xFF; |
645 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
646 |
# endif /* not MSB */ |
7122 | 647 |
dstPtr += 2; |
648 |
srcPtr += 4; |
|
649 |
} |
|
650 |
dstPtr += p; |
|
651 |
} |
|
652 |
} |
|
653 |
} |
|
654 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
655 |
%}. |
7122 | 656 |
] ifFalse:[ |
657 |
"/ |
|
658 |
"/ 32 or 8 bits/pixel ... |
|
659 |
"/ |
|
660 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
|
8000 | 661 |
"/ usedDevicePadding := 8. |
7122 | 662 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
663 |
|
7122 | 664 |
"/ 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
|
665 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
666 |
%{ |
7122 | 667 |
unsigned char *srcPtr = 0; |
668 |
unsigned char *dstPtr = 0; |
|
8094 | 669 |
int _redOffs = __intVal(redOffs); |
670 |
int _greenOffs = __intVal(greenOffs); |
|
671 |
int _blueOffs = __intVal(blueOffs); |
|
672 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
673 |
|
7122 | 674 |
if (__isByteArrayLike(bytes)) { |
675 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
676 |
} else { |
|
677 |
if (__isExternalBytesLike(bytes)) { |
|
678 |
srcPtr = __externalBytesAddress(bytes); |
|
679 |
} |
|
680 |
} |
|
681 |
if (__isByteArray(imageBits)) { |
|
682 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
683 |
} else { |
|
684 |
if (__isExternalBytesLike(imageBits)) { |
|
685 |
dstPtr = __externalBytesAddress(imageBits); |
|
686 |
} |
|
687 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
688 |
|
7122 | 689 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
690 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
691 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
692 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
693 |
&& srcPtr |
|
694 |
&& dstPtr) { |
|
695 |
int rShRed = __intVal(rightShiftR), |
|
696 |
rShGreen = __intVal(rightShiftG), |
|
697 |
rShBlue = __intVal(rightShiftB), |
|
698 |
lShRed = __intVal(shiftRed), |
|
699 |
lShGreen = __intVal(shiftGreen), |
|
700 |
lShBlue = __intVal(shiftBlue); |
|
701 |
int x, y, w; |
|
702 |
||
703 |
w = __intVal(__INST(width)); |
|
704 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
705 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
706 |
for (x=w; x > 0; x--) { |
|
707 |
unsigned v; |
|
708 |
||
8094 | 709 |
v = srcPtr[_redOffs] << lShRed; |
710 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
711 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
712 |
# ifdef __MSBFIRST |
7122 | 713 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
714 |
# else /* not MSB */ |
7122 | 715 |
dstPtr[0] = (v>>24) & 0xFF; |
716 |
dstPtr[1] = (v>>16) & 0xFF; |
|
717 |
dstPtr[2] = (v>>8) & 0xFF; |
|
718 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
719 |
# endif /* not MSB */ |
7122 | 720 |
dstPtr += 4; |
721 |
srcPtr += 4; |
|
722 |
} |
|
723 |
} |
|
724 |
} else { |
|
725 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
726 |
for (x=w; x > 0; x--) { |
|
727 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
728 |
|
8094 | 729 |
r = srcPtr[_redOffs] >> rShRed; |
730 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
731 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 732 |
v = r << lShRed; |
733 |
v |= (g << lShGreen); |
|
734 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
735 |
# ifdef __MSBFIRST |
7122 | 736 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
737 |
# else /* not MSB */ |
7122 | 738 |
dstPtr[0] = (v>>24) & 0xFF; |
739 |
dstPtr[1] = (v>>16) & 0xFF; |
|
740 |
dstPtr[2] = (v>>8) & 0xFF; |
|
741 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
742 |
# endif /* not MSB */ |
7122 | 743 |
dstPtr += 4; |
744 |
srcPtr += 4; |
|
745 |
} |
|
746 |
} |
|
747 |
} |
|
748 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
749 |
%}. |
7122 | 750 |
] ifFalse:[ |
751 |
"/ |
|
752 |
"/ 8 bits/pixel ... |
|
753 |
"/ |
|
754 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
755 |
usedDevicePadding := 8. |
|
756 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
757 |
|
7122 | 758 |
"/ 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
|
759 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
760 |
%{ |
7122 | 761 |
unsigned char *srcPtr = 0; |
762 |
unsigned char *dstPtr = 0; |
|
8094 | 763 |
int _redOffs = __intVal(redOffs); |
764 |
int _greenOffs = __intVal(greenOffs); |
|
765 |
int _blueOffs = __intVal(blueOffs); |
|
766 |
// int _alphaOffs = __intVal(alphaOffs); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
767 |
|
7122 | 768 |
if (__isByteArrayLike(bytes)) { |
769 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
770 |
} else { |
|
771 |
if (__isExternalBytesLike(bytes)) { |
|
772 |
srcPtr = __externalBytesAddress(bytes); |
|
773 |
} |
|
774 |
} |
|
775 |
if (__isByteArray(imageBits)) { |
|
776 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
777 |
} else { |
|
778 |
if (__isExternalBytesLike(imageBits)) { |
|
779 |
dstPtr = __externalBytesAddress(imageBits); |
|
780 |
} |
|
781 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
782 |
|
7122 | 783 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
784 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
785 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
786 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
787 |
&& srcPtr |
|
788 |
&& dstPtr) { |
|
789 |
int rShRed = __intVal(rightShiftR), |
|
790 |
rShGreen = __intVal(rightShiftG), |
|
791 |
rShBlue = __intVal(rightShiftB), |
|
792 |
lShRed = __intVal(shiftRed), |
|
793 |
lShGreen = __intVal(shiftGreen), |
|
794 |
lShBlue = __intVal(shiftBlue); |
|
795 |
int x, y, w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
796 |
|
7122 | 797 |
w = __intVal(__INST(width)); |
798 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
799 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
800 |
for (x=w; x > 0; x--) { |
|
801 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
802 |
|
8094 | 803 |
v = srcPtr[_redOffs] << lShRed; |
804 |
v |= (srcPtr[_greenOffs] << lShGreen); |
|
805 |
v |= (srcPtr[_blueOffs] << lShBlue); |
|
7122 | 806 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
807 |
|
7122 | 808 |
dstPtr += 1; |
809 |
srcPtr += 4; |
|
810 |
} |
|
811 |
} |
|
812 |
} else { |
|
813 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
814 |
for (x=w; x > 0; x--) { |
|
815 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
816 |
|
8094 | 817 |
r = srcPtr[_redOffs] >> rShRed; |
818 |
g = srcPtr[_greenOffs] >> rShGreen; |
|
819 |
b = srcPtr[_blueOffs] >> rShBlue; |
|
7122 | 820 |
v = r << lShRed; |
821 |
v |= (g << lShGreen); |
|
822 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
823 |
|
7122 | 824 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
825 |
|
7122 | 826 |
dstPtr += 1; |
827 |
srcPtr += 4; |
|
828 |
} |
|
829 |
} |
|
830 |
} |
|
831 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
832 |
%}. |
7122 | 833 |
] |
834 |
]. |
|
835 |
] |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
836 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
837 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
838 |
imageBits isNil ifTrue:[ |
7122 | 839 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
840 |
usedDeviceBitsPerPixel errorPrintCR. |
|
841 |
^ self asMonochromeFormOn:aDevice |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
842 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
843 |
|
7497 | 844 |
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
|
845 |
form isNil ifTrue:[ |
7122 | 846 |
'Depth32Image [warning]: display bitmap creation failed' errorPrintCR. |
847 |
^ nil |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
848 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
849 |
form initGC. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
850 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
851 |
form |
7122 | 852 |
copyBitsFrom:imageBits |
853 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
854 |
depth:usedDeviceDepth |
|
855 |
padding:usedDevicePadding |
|
856 |
width:width height:height |
|
857 |
x:0 y:0 toX:0 y:0. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
858 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
859 |
^ form |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
860 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
861 |
"Created: / 27-05-2007 / 16:54:19 / cg" |
8114 | 862 |
"Modified: / 27-08-2017 / 21:06:49 / cg" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
863 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
864 |
|
6841 | 865 |
!Depth32Image methodsFor:'image manipulations'! |
866 |
||
867 |
negative |
|
7922 | 868 |
|bytes |
869 |
index "{ Class: SmallInteger }" |
|
8327 | 870 |
newImage newBytes nBytes r g b a |
871 |
alphaFirst| |
|
6841 | 872 |
|
8327 | 873 |
((photometric ~~ #argb) |
874 |
and:[(photometric ~~ #rgba) |
|
875 |
and:[(photometric ~~ #xrgb) |
|
876 |
and:[(photometric ~~ #rgbx) |
|
877 |
and:[(photometric ~~ #rgb0) |
|
878 |
and:[(photometric ~~ #'0rgb')]]]]]) ifTrue:[ |
|
6841 | 879 |
^ super negative. |
880 |
]. |
|
8327 | 881 |
|
882 |
alphaFirst := (photometric == #argb) |
|
883 |
or:[ (photometric == #xrgb) |
|
884 |
or:[ (photometric == #'0rgb') ]]. |
|
885 |
||
6841 | 886 |
bytes := self bits. |
887 |
||
888 |
newImage := self copy. |
|
889 |
nBytes := bytes size. |
|
890 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
891 |
index := 1. |
|
892 |
[index < nBytes] whileTrue:[ |
|
8327 | 893 |
alphaFirst ifTrue:[ |
894 |
a := bytes at:index. |
|
895 |
newBytes at:index put:a. |
|
896 |
index := index + 1. |
|
897 |
]. |
|
898 |
||
6841 | 899 |
r := bytes at:index. |
900 |
newBytes at:index put:(255-r). |
|
901 |
index := index + 1. |
|
8085 | 902 |
|
6841 | 903 |
g := bytes at:index. |
904 |
newBytes at:index put:(255-g). |
|
905 |
index := index + 1. |
|
8085 | 906 |
|
6841 | 907 |
b := bytes at:index. |
908 |
newBytes at:index put:(255-b). |
|
909 |
index := index + 1. |
|
8085 | 910 |
|
8327 | 911 |
alphaFirst ifFalse:[ |
912 |
a := bytes at:index. |
|
913 |
newBytes at:index put:a. |
|
914 |
index := index + 1. |
|
915 |
] |
|
6841 | 916 |
]. |
917 |
^ newImage |
|
7922 | 918 |
|
8085 | 919 |
"Modified (format): / 22-08-2017 / 17:13:38 / cg" |
6841 | 920 |
! ! |
921 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
922 |
!Depth32Image methodsFor:'initialization'! |
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 |
initialize |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
925 |
super initialize. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
926 |
samplesPerPixel := 4. |
7819 | 927 |
bitsPerSample := #[8 8 8 8]. |
4761
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 |
"Created: / 27-05-2007 / 14:09:16 / cg" |
7819 | 930 |
"Modified: / 30-01-2017 / 19:32:13 / stefan" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
931 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
932 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
933 |
!Depth32Image methodsFor:'magnification'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
934 |
|
8262 | 935 |
hardAntiAliasedMagnifiedBy:scaleArg |
936 |
"return a new image magnified by scalePoint, aPoint. |
|
937 |
This interpolates pixels and is therefore much slower, |
|
938 |
but generates nicer looking magnifications." |
|
939 |
||
940 |
|scalePoint mX |
|
941 |
mY |
|
942 |
newWidth "{ Class: SmallInteger }" |
|
943 |
newHeight "{ Class: SmallInteger }" |
|
944 |
w "{ Class: SmallInteger }" |
|
945 |
h "{ Class: SmallInteger }" |
|
946 |
newImage newBits bitsPerPixel newBytesPerRow newMask |
|
947 |
value |
|
948 |
srcRow pixelArray| |
|
949 |
||
950 |
scalePoint := scaleArg asPoint. |
|
951 |
mX := scalePoint x. |
|
952 |
mY := scalePoint y. |
|
953 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
954 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
955 |
||
956 |
newWidth := (width * mX) truncated. |
|
957 |
newHeight := (height * mY) truncated. |
|
958 |
||
959 |
bitsPerPixel := self depth. |
|
960 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
961 |
newBits := ByteArray new: "uninitializedNew:" (newBytesPerRow * newHeight). |
|
962 |
newBits isNil ifTrue:[ |
|
963 |
'Depth32Image [warning]: failed to allocate byteArray for image bits' errorPrintCR. |
|
964 |
^ nil |
|
965 |
]. |
|
966 |
||
967 |
mask notNil ifTrue:[ |
|
968 |
newMask := (mask magnifiedBy:scalePoint) |
|
969 |
]. |
|
970 |
||
971 |
newImage := self species new. |
|
972 |
newImage |
|
973 |
width:newWidth |
|
974 |
height:newHeight |
|
975 |
photometric:photometric |
|
976 |
samplesPerPixel:samplesPerPixel |
|
977 |
bitsPerSample:bitsPerSample |
|
978 |
colorMap:nil |
|
979 |
bits:newBits |
|
980 |
mask:newMask. |
|
981 |
||
982 |
mY := mY asFloat. |
|
983 |
mX := mX asFloat. |
|
984 |
||
985 |
%{ |
|
986 |
REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBits)->ba_element; |
|
987 |
unsigned char *_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
988 |
unsigned char *_srcRowP, *sP; |
|
989 |
int _width4 = __intVal(__INST(width)) * 4; |
|
990 |
int _oldW = __intVal(__INST(width)) - 1; |
|
991 |
int _oldH = __intVal(__INST(height)) - 1; |
|
992 |
int _w = __intVal(newWidth) - 1; |
|
993 |
int _h = __intVal(newHeight) - 1; |
|
994 |
int _row, _col; |
|
995 |
double _mX = __floatVal(mX); |
|
996 |
double _mY = __floatVal(mY); |
|
997 |
||
998 |
for (_row = 0; _row <= _h; _row++) { |
|
999 |
double _srcY; |
|
1000 |
double _dY; |
|
1001 |
int _sR; |
|
1002 |
||
1003 |
_srcY = ((double)_row / _mY); |
|
1004 |
_sR = (int)_srcY; |
|
1005 |
_dY = _srcY - ((double)_sR); |
|
1006 |
_srcRowP = _srcP + (_width4 * _sR); |
|
1007 |
||
1008 |
for (_col = 0; _col <= _w; _col++) { |
|
1009 |
unsigned int rHere, gHere, bHere, aHere; |
|
1010 |
unsigned int rRight, gRight, bRight, aRight; |
|
1011 |
unsigned int rRightBelow, gRightBelow, bRightBelow, aRightBelow; |
|
1012 |
unsigned int rBelow, gBelow, bBelow, aBelow; |
|
1013 |
unsigned int _r, _g, _b, _a; |
|
1014 |
double wHere, wRight, wRightBelow, wBelow, sumW; |
|
1015 |
double _srcX; |
|
1016 |
double _dX; |
|
1017 |
int _sC; |
|
1018 |
||
1019 |
_srcX = ((double)_col / _mX); |
|
1020 |
_sC = (int)_srcX; |
|
1021 |
_dX = _srcX - ((double)_sC); |
|
1022 |
sP = _srcRowP + (_sC * 4); |
|
1023 |
||
1024 |
rHere = sP[0]; |
|
1025 |
gHere = sP[1]; |
|
1026 |
bHere = sP[2]; |
|
1027 |
aHere = sP[3]; |
|
1028 |
||
1029 |
if (_sC < _oldW) { |
|
1030 |
rRight = sP[0+4]; |
|
1031 |
gRight = sP[0+5]; |
|
1032 |
bRight = sP[0+6]; |
|
1033 |
aRight = sP[0+7]; |
|
1034 |
||
1035 |
if (_sR < _oldH) { |
|
1036 |
rBelow = sP[0+_width4]; |
|
1037 |
gBelow = sP[1+_width4]; |
|
1038 |
bBelow = sP[2+_width4]; |
|
1039 |
aBelow = sP[3+_width4]; |
|
1040 |
rRightBelow = sP[4+_width4]; |
|
1041 |
gRightBelow = sP[5+_width4]; |
|
1042 |
bRightBelow = sP[6+_width4]; |
|
8264 | 1043 |
aRightBelow = sP[7+_width4]; |
8262 | 1044 |
} else { |
1045 |
rRightBelow = rHere; |
|
1046 |
gRightBelow = gHere; |
|
1047 |
bRightBelow = bHere; |
|
1048 |
aRightBelow = aHere; |
|
1049 |
rBelow = rHere; |
|
1050 |
gBelow = gHere; |
|
1051 |
bBelow = bHere; |
|
1052 |
aBelow = aHere; |
|
1053 |
} |
|
1054 |
} else { |
|
1055 |
rRight = rRightBelow = rHere; |
|
1056 |
gRight = gRightBelow = gHere; |
|
1057 |
bRight = bRightBelow = bHere; |
|
1058 |
aRight = aRightBelow = aHere; |
|
1059 |
if (_sR < _oldH) { |
|
1060 |
rBelow = sP[0+_width4]; |
|
1061 |
gBelow = sP[1+_width4]; |
|
1062 |
bBelow = sP[2+_width4]; |
|
8264 | 1063 |
aBelow = sP[3+_width4]; |
8262 | 1064 |
} else { |
1065 |
rBelow = rHere; |
|
1066 |
gBelow = gHere; |
|
1067 |
bBelow = bHere; |
|
1068 |
aBelow = aHere; |
|
1069 |
} |
|
1070 |
} |
|
1071 |
||
1072 |
wHere = (1.0 - _dX) * (1.0 - _dY); |
|
1073 |
wRight = _dX * (1.0 - _dY); |
|
1074 |
wBelow = _dY * (1.0 - _dX); |
|
1075 |
wRightBelow = _dX * _dY; |
|
1076 |
sumW = wHere + wRight + wBelow + wRightBelow; |
|
1077 |
||
1078 |
_r = ((rHere * wHere) + (rRight * wRight) + (rBelow * wBelow) + (rRightBelow * wRightBelow)) / sumW; |
|
1079 |
_g = ((gHere * wHere) + (gRight * wRight) + (gBelow * wBelow) + (gRightBelow * wRightBelow)) / sumW; |
|
1080 |
_b = ((bHere * wHere) + (bRight * wRight) + (bBelow * wBelow) + (bRightBelow * wRightBelow)) / sumW; |
|
1081 |
_a = ((aHere * wHere) + (aRight * wRight) + (aBelow * wBelow) + (aRightBelow * wRightBelow)) / sumW; |
|
1082 |
||
1083 |
_dstP[0] = _r; |
|
1084 |
_dstP[1] = _g; |
|
1085 |
_dstP[2] = _b; |
|
1086 |
_dstP[3] = _a; |
|
1087 |
||
1088 |
_dstP += 4; |
|
1089 |
} |
|
1090 |
} |
|
1091 |
%}. |
|
1092 |
||
1093 |
^ newImage |
|
1094 |
||
1095 |
" |
|
1096 |
|i| |
|
1097 |
i := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'. |
|
1098 |
i := Depth32Image fromImage:i. |
|
1099 |
i hardAntiAliasedMagnifiedBy:2@2 |
|
1100 |
" |
|
1101 |
" |
|
1102 |
|i| |
|
1103 |
i := Depth32Image width:3 height:3 fromArray:#[ 0 0 0 127 0 0 0 127 0 0 0 127 |
|
1104 |
0 0 0 127 255 255 255 127 0 0 0 127 |
|
1105 |
0 0 0 127 0 0 0 127 0 0 0 127]. |
|
1106 |
i hardAntiAliasedMagnifiedBy:8@8 |
|
1107 |
" |
|
1108 |
||
1109 |
"Created: / 02-06-1997 / 13:18:53 / cg" |
|
1110 |
"Modified: / 30-08-2017 / 13:35:20 / cg" |
|
1111 |
! |
|
1112 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1113 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1114 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1115 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1116 |
"magnify a single pixel row - can only magnify by integer factors" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1117 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1118 |
%{ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1119 |
unsigned char *srcP, *dstP; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1120 |
int _mag; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1121 |
REGISTER int i; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1122 |
REGISTER unsigned char byte1, byte2, byte3, byte4; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1123 |
int _pixels; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1124 |
OBJ w = __INST(width); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1125 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1126 |
if (__bothSmallInteger(srcStart, dstStart) |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1127 |
&& __bothSmallInteger(w, mX) |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1128 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1129 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1130 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1131 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1132 |
_pixels = __intVal(w); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1133 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1134 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1135 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1136 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1137 |
byte3 = *(srcP+2); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1138 |
byte4 = *(srcP+3); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1139 |
srcP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1140 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1141 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1142 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1143 |
*(dstP+2) = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1144 |
*(dstP+3) = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1145 |
dstP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1146 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1147 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1148 |
RETURN (self); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1149 |
} |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1150 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1151 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1152 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
1153 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1154 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1155 |
"Created: / 28-05-2007 / 15:20:52 / cg" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1156 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
1157 |
|
1663 | 1158 |
!Depth32Image methodsFor:'queries'! |
1159 |
||
7122 | 1160 |
alphaBitsOf:pixel |
1161 |
"given a pixel-value, return the alpha component as byteValue (0..255)" |
|
1162 |
||
8085 | 1163 |
photometric == #argb ifTrue:[ |
8327 | 1164 |
"/ value is: aarrggbb |
1165 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
1166 |
]. |
|
1167 |
(photometric == #rgb) ifTrue:[ |
|
1168 |
"/ value is: 00rrggbb |
|
1169 |
^ 0 |
|
1170 |
]. |
|
1171 |
(photometric == #xrgb) ifTrue:[ |
|
1172 |
"/ value is: FFrrggbb |
|
1173 |
^ 255 |
|
8085 | 1174 |
]. |
7122 | 1175 |
photometric == #rgba ifTrue:[ |
8327 | 1176 |
"/ value is: rrggbbaa |
1177 |
^ pixel bitAnd:16rFF |
|
1178 |
]. |
|
1179 |
photometric == #rgb0 ifTrue:[ |
|
1180 |
"/ value is: rrggbb00 |
|
1181 |
^ 0 |
|
7122 | 1182 |
]. |
8327 | 1183 |
photometric == #rgbx ifTrue:[ |
1184 |
"/ value is: rrggbbFF |
|
1185 |
^ 255 |
|
1186 |
]. |
|
1187 |
||
1188 |
^ super alphaBitsOf:pixel. |
|
8002 | 1189 |
|
8085 | 1190 |
"Modified: / 22-08-2017 / 17:18:44 / cg" |
7122 | 1191 |
! |
1192 |
||
1193 |
alphaComponentOf:pixel |
|
1194 |
"given a pixel-value, return the alpha component in percent (0..100)" |
|
1195 |
||
1196 |
^ (self alphaBitsOf:pixel) * (100.0 / 255.0) |
|
1197 |
! |
|
1198 |
||
1199 |
alphaMaskForPixelValue |
|
7922 | 1200 |
"return the mask used with translation from pixelValues to alphaBits. |
1201 |
Determines the number of bits of alpha" |
|
7122 | 1202 |
|
1203 |
^ 16rFF |
|
7922 | 1204 |
|
1205 |
"Modified (comment): / 21-02-2017 / 16:37:31 / cg" |
|
7122 | 1206 |
! |
1207 |
||
1208 |
alphaShiftForPixelValue |
|
7922 | 1209 |
"return the shift amount used with translation from pixelValues to alphaBits. |
1210 |
That is the number of bits to shift the alpha value into the pixel value." |
|
7122 | 1211 |
|
8327 | 1212 |
((photometric == #argb) |
1213 |
or:[ (photometric == #rgb) |
|
1214 |
or:[ (photometric == #xrgb) ]]) |
|
1215 |
ifTrue:[ |
|
1216 |
"/ aarrggbb |
|
1217 |
^ -24. |
|
7122 | 1218 |
]. |
8327 | 1219 |
((photometric == #rgba) |
1220 |
or:[ (photometric == #rgbx) |
|
1221 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1222 |
"/ rrggbbaa |
|
1223 |
^ 0. |
|
1224 |
]. |
|
1225 |
^ super alphaShiftForPixelValue. |
|
7896 | 1226 |
|
8085 | 1227 |
"Modified: / 22-08-2017 / 17:19:36 / cg" |
7122 | 1228 |
! |
1229 |
||
1663 | 1230 |
bitsPerPixel |
1231 |
"return the number of bits per pixel" |
|
1232 |
||
1233 |
^ 32 |
|
1234 |
||
1235 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
1236 |
! |
|
1237 |
||
1238 |
bitsPerRow |
|
1239 |
"return the number of bits in one scanline of the image" |
|
1240 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
1241 |
^ width * 32 |
1663 | 1242 |
|
1243 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
1244 |
! |
|
1245 |
||
6841 | 1246 |
bitsPerSample |
1247 |
"return the number of bits per sample. |
|
1248 |
The return value is an array of bits-per-plane." |
|
1249 |
||
1250 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
|
7819 | 1251 |
^ #[8 8 8 8] |
1252 |
||
1253 |
"Modified: / 30-01-2017 / 19:23:31 / stefan" |
|
6841 | 1254 |
! |
1255 |
||
1256 |
blueBitsOf:pixel |
|
1257 |
"given a pixel-value, return the blue component as byteValue (0..255)" |
|
1258 |
||
8327 | 1259 |
((photometric == #argb) |
1260 |
or:[ (photometric == #rgb) |
|
1261 |
or:[ (photometric == #xrgb) ]]) |
|
1262 |
ifTrue:[ |
|
1263 |
"/ aarrggbb |
|
1264 |
^ pixel bitAnd:16rFF. |
|
7122 | 1265 |
]. |
8327 | 1266 |
((photometric == #rgba) |
1267 |
or:[ (photometric == #rgbx) |
|
1268 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1269 |
"/ rrggbbaa |
|
1270 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
1271 |
]. |
|
1272 |
^ super blueBitsOf:pixel. |
|
7922 | 1273 |
|
8089 | 1274 |
"Modified: / 22-08-2017 / 18:23:41 / cg" |
6841 | 1275 |
! |
1276 |
||
1277 |
blueComponentOf:pixel |
|
1278 |
"given a pixel-value, return the blue component in percent (0..100)" |
|
1279 |
||
7122 | 1280 |
^ (self blueBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1281 |
! |
1282 |
||
1283 |
blueMaskForPixelValue |
|
1284 |
"return the mask used with translation from pixelValues to blueBits" |
|
1285 |
||
1286 |
^ 16rFF |
|
1287 |
! |
|
1288 |
||
1289 |
blueShiftForPixelValue |
|
1290 |
"return the shift amount used with translation from pixelValues to blueBits" |
|
1291 |
||
8327 | 1292 |
((photometric == #argb) |
1293 |
or:[ (photometric == #rgb) |
|
1294 |
or:[ (photometric == #xrgb) ]]) |
|
1295 |
ifTrue:[ |
|
1296 |
"/ aarrggbb |
|
1297 |
^ 0. |
|
7122 | 1298 |
]. |
8327 | 1299 |
((photometric == #rgba) |
1300 |
or:[ (photometric == #rgbx) |
|
1301 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1302 |
"/ rrggbbaa |
|
1303 |
^ -8 |
|
1304 |
]. |
|
1305 |
^ super blueShiftForPixelValue |
|
7922 | 1306 |
|
8085 | 1307 |
"Modified: / 22-08-2017 / 17:19:55 / cg" |
6841 | 1308 |
! |
1309 |
||
1663 | 1310 |
bytesPerRow |
1311 |
"return the number of bytes in one scanline of the image" |
|
1312 |
||
1313 |
^ width * 4. |
|
1314 |
||
1315 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
5327 | 1316 |
! |
1317 |
||
6841 | 1318 |
greenBitsOf:pixel |
1319 |
"given a pixel-value, return the green component as byteValue (0..255)" |
|
1320 |
||
8327 | 1321 |
((photometric == #argb) |
1322 |
or:[ (photometric == #rgb) |
|
1323 |
or:[ (photometric == #xrgb) ]]) |
|
1324 |
ifTrue:[ |
|
1325 |
"/ aarrggbb |
|
1326 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
7122 | 1327 |
]. |
8327 | 1328 |
((photometric == #rgba) |
1329 |
or:[ (photometric == #rgbx) |
|
1330 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1331 |
"/ rrggbbaa |
|
1332 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
1333 |
]. |
|
1334 |
^ super greenBitsOf:pixel. |
|
7922 | 1335 |
|
8327 | 1336 |
"Modified: / 22-08-2017 / 18:23:41 / cg" |
6841 | 1337 |
! |
1338 |
||
1339 |
greenComponentOf:pixel |
|
1340 |
"given a pixel-value, return the green component in percent (0..100)" |
|
1341 |
||
7122 | 1342 |
^ (self greenBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1343 |
! |
1344 |
||
1345 |
greenMaskForPixelValue |
|
1346 |
"return the mask used with translation from pixelValues to redBits" |
|
1347 |
||
1348 |
^ 16rFF |
|
1349 |
! |
|
1350 |
||
1351 |
greenShiftForPixelValue |
|
1352 |
"return the shift amount used with translation from pixelValues to greenBits" |
|
1353 |
||
8327 | 1354 |
((photometric == #argb) |
1355 |
or:[ (photometric == #rgb) |
|
1356 |
or:[ (photometric == #xrgb) ]]) |
|
1357 |
ifTrue:[ |
|
1358 |
"/ aarrggbb |
|
1359 |
^ -8 |
|
7122 | 1360 |
]. |
8327 | 1361 |
((photometric == #rgba) |
1362 |
or:[ (photometric == #rgbx) |
|
1363 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1364 |
"/ rrggbbaa |
|
1365 |
^ -16. |
|
1366 |
]. |
|
1367 |
^ super greenShiftForPixelValue. |
|
6841 | 1368 |
! |
1369 |
||
5327 | 1370 |
hasAlphaChannel |
7922 | 1371 |
"could be #rgb in 32 bits..." |
1372 |
||
1373 |
^ (photometric == #argb) or:[photometric == #rgba] |
|
1374 |
||
1375 |
"Modified: / 21-02-2017 / 15:00:17 / cg" |
|
6841 | 1376 |
! |
1377 |
||
8085 | 1378 |
numAlphaBits |
1379 |
photometric == #argb ifTrue:[ |
|
1380 |
^ 8. |
|
1381 |
]. |
|
1382 |
photometric == #rgba ifTrue:[ |
|
1383 |
^ 8. |
|
1384 |
]. |
|
1385 |
^ 0 |
|
1386 |
||
1387 |
"Created: / 22-08-2017 / 17:38:59 / cg" |
|
1388 |
! |
|
1389 |
||
1390 |
numBlueBits |
|
1391 |
^ 8 |
|
1392 |
||
1393 |
"Created: / 22-08-2017 / 17:38:31 / cg" |
|
1394 |
! |
|
1395 |
||
1396 |
numGreenBits |
|
1397 |
^ 8 |
|
1398 |
||
1399 |
"Created: / 22-08-2017 / 17:38:28 / cg" |
|
1400 |
! |
|
1401 |
||
1402 |
numRedBits |
|
1403 |
^ 8 |
|
1404 |
||
1405 |
"Created: / 22-08-2017 / 17:38:25 / cg" |
|
1406 |
! |
|
1407 |
||
6841 | 1408 |
redBitsOf:pixel |
1409 |
"given a pixel-value, return the red component as byteValue (0..255)" |
|
1410 |
||
8327 | 1411 |
((photometric == #argb) |
1412 |
or:[ (photometric == #rgb) |
|
1413 |
or:[ (photometric == #xrgb) ]]) |
|
1414 |
ifTrue:[ |
|
1415 |
"/ aarrggbb |
|
1416 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
7122 | 1417 |
]. |
8327 | 1418 |
((photometric == #rgba) |
1419 |
or:[ (photometric == #rgbx) |
|
1420 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1421 |
"/ rrggbbaa |
|
1422 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
1423 |
]. |
|
1424 |
^ super redBitsOf:pixel. |
|
7922 | 1425 |
|
8327 | 1426 |
"Modified: / 22-08-2017 / 18:23:41 / cg" |
6841 | 1427 |
! |
1428 |
||
1429 |
redComponentOf:pixel |
|
1430 |
"given a pixel-value, return the red component in percent (0..100)" |
|
1431 |
||
7122 | 1432 |
^ (self redBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1433 |
! |
1434 |
||
1435 |
redMaskForPixelValue |
|
1436 |
"return the mask used with translation from pixelValues to redBits" |
|
1437 |
||
1438 |
^ 16rFF |
|
1439 |
! |
|
1440 |
||
1441 |
redShiftForPixelValue |
|
1442 |
"return the shift amount used with translation from pixelValues to redBits" |
|
1443 |
||
8327 | 1444 |
((photometric == #argb) |
1445 |
or:[ (photometric == #rgb) |
|
1446 |
or:[ (photometric == #xrgb) ]]) |
|
1447 |
ifTrue:[ |
|
1448 |
"/ aarrggbb |
|
1449 |
^ -16 |
|
7122 | 1450 |
]. |
8327 | 1451 |
((photometric == #rgba) |
1452 |
or:[ (photometric == #rgbx) |
|
1453 |
or:[ (photometric == #rgb0)]]) ifTrue:[ |
|
1454 |
"/ rrggbbaa |
|
1455 |
^ -24. |
|
1456 |
]. |
|
1457 |
^ super redShiftForPixelValue. |
|
7922 | 1458 |
|
8327 | 1459 |
"Modified: / 22-08-2017 / 18:23:41 / cg" |
6841 | 1460 |
! |
1461 |
||
1462 |
rgbFromValue:pixelValue |
|
1463 |
"given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB)." |
|
1464 |
||
8327 | 1465 |
((photometric == #argb) |
1466 |
or:[ (photometric == #rgb) |
|
1467 |
or:[ (photometric == #xrgb) ]]) |
|
1468 |
ifTrue:[ |
|
1469 |
"/ aarrggbb |
|
1470 |
^ pixelValue bitAnd:16rFFFFFF |
|
7922 | 1471 |
]. |
8327 | 1472 |
|
1473 |
((photometric == #rgba) |
|
1474 |
or:[ photometric == #rgbx |
|
1475 |
or:[ photometric == #rgb0]]) ifTrue:[ |
|
1476 |
"/ rrggbbaa |
|
1477 |
^ (pixelValue rightShift:8) bitAnd:16rFFFFFF |
|
7922 | 1478 |
]. |
8089 | 1479 |
^ super rgbFromValue:pixelValue. |
7922 | 1480 |
|
8089 | 1481 |
"Modified: / 22-08-2017 / 18:32:22 / cg" |
6841 | 1482 |
! |
1483 |
||
1484 |
samplesPerPixel |
|
1485 |
"return the number of samples per pixel in the image." |
|
1486 |
||
1487 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
|
1488 |
^ 4 |
|
1489 |
! |
|
1490 |
||
1491 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
|
8089 | 1492 |
(photometric == #rgba) ifTrue:[ |
7922 | 1493 |
"/ alpha in low byte |
1494 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:16rFF |
|
1495 |
]. |
|
1496 |
(photometric == #argb) ifTrue:[ |
|
1497 |
"/ alpha in high byte |
|
1498 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:16rFF000000 |
|
1499 |
]. |
|
8085 | 1500 |
(photometric == #rgb) ifTrue:[ |
8089 | 1501 |
"/ no alpha |
1502 |
^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits |
|
8085 | 1503 |
]. |
8089 | 1504 |
^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits. |
7922 | 1505 |
|
8089 | 1506 |
"Modified: / 22-08-2017 / 18:34:30 / cg" |
8166 | 1507 |
! |
1508 |
||
1509 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits alphaBits:alphaBits |
|
1510 |
(photometric == #rgba) ifTrue:[ |
|
1511 |
"/ alpha in low byte |
|
1512 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:alphaBits |
|
1513 |
]. |
|
1514 |
(photometric == #argb) ifTrue:[ |
|
1515 |
"/ alpha in high byte |
|
1516 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:(alphaBits bitShift:24) |
|
1517 |
]. |
|
1518 |
(photometric == #rgb) ifTrue:[ |
|
1519 |
"/ no alpha |
|
1520 |
^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits |
|
1521 |
]. |
|
1522 |
^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits. |
|
1523 |
||
1524 |
"Created: / 05-09-2017 / 14:31:38 / cg" |
|
1663 | 1525 |
! ! |
1526 |
||
1527 |
!Depth32Image class methodsFor:'documentation'! |
|
1528 |
||
1529 |
version |
|
7122 | 1530 |
^ '$Header$' |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1531 |
! |
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1532 |
|
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1533 |
version_CVS |
7122 | 1534 |
^ '$Header$' |
1663 | 1535 |
! ! |
6302 | 1536 |