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