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