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