author | Claus Gittinger <cg@exept.de> |
Tue, 21 Feb 2017 17:23:45 +0100 | |
changeset 7922 | 800a52cd955b |
parent 7917 | fb1dcd2edc4e |
child 8000 | 62ea15884e2b |
permissions | -rw-r--r-- |
1663 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
3 |
All Rights Reserved |
1663 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
3263 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
6841 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1663 | 16 |
Image subclass:#Depth32Image |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Graphics-Images' |
|
21 |
! |
|
22 |
||
23 |
!Depth32Image class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
28 |
All Rights Reserved |
1663 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
7902 | 41 |
this class represents 32 bit (eg. rgb+alpha) images. |
42 |
||
1663 | 43 |
Only the minimum protocol is implemented here; much more is |
44 |
needed for higher performance operations on depth32 images. |
|
7902 | 45 |
|
46 |
(however, 32bit images are currntly relatively seldom used, |
|
47 |
so falling back into the slow general methods from Image does not hurt too much. |
|
48 |
This situation will change, when more support for alpha channels is added and they |
|
49 |
are more heavily used in ST/X...) |
|
1663 | 50 |
|
51 |
[author:] |
|
7902 | 52 |
Claus Gittinger |
1663 | 53 |
|
54 |
[see also:] |
|
7902 | 55 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image |
56 |
ImageReader |
|
1663 | 57 |
" |
58 |
! ! |
|
59 |
||
60 |
!Depth32Image class methodsFor:'queries'! |
|
61 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
62 |
defaultPhotometric |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
63 |
"return the default photometric pixel interpretation" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
64 |
|
7903 | 65 |
"/ here we return #rgb - thus ignoring any alpha channel. |
66 |
"/ the reason is that many displays and graphics formats do use |
|
67 |
"/ 32bit per pixel, but provide an alpha value of 0, instead of 255. |
|
68 |
"/ Thus returning rgba here would make many images invisible (totally transparent) |
|
69 |
||
5324 | 70 |
^ #rgb |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
71 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
72 |
"Created: / 27-05-2007 / 14:03:59 / cg" |
7903 | 73 |
"Modified: / 16-02-2017 / 17:41:09 / cg" |
74 |
"Modified (comment): / 16-02-2017 / 19:00:25 / cg" |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
75 |
! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
76 |
|
1663 | 77 |
imageDepth |
78 |
"return the depth of images represented by instances of |
|
79 |
this class - here we return 32" |
|
80 |
||
81 |
^ 32 |
|
82 |
||
83 |
"Modified: 20.4.1996 / 23:40:01 / cg" |
|
84 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
85 |
! ! |
|
86 |
||
3263 | 87 |
!Depth32Image methodsFor:'accessing-pixels'! |
1663 | 88 |
|
6841 | 89 |
colorAtX:x y:y |
90 |
"retrieve a pixel at x/y; return a color. |
|
7124 | 91 |
Pixels start at x=0 , y=0 for upper left pixel, |
92 |
end at x = width-1, y=height-1 for lower right pixel" |
|
6841 | 93 |
|
94 |
|index "{ Class: SmallInteger }" |
|
7124 | 95 |
rVal gVal bVal aVal| |
6841 | 96 |
|
97 |
index := 1 + (((width * y) + x) * 4). |
|
7124 | 98 |
photometric == #rgb ifTrue:[ |
99 |
rVal := bytes at:(index). |
|
100 |
gVal := bytes at:(index + 1). |
|
101 |
bVal := bytes at:(index + 2). |
|
102 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal |
|
103 |
]. |
|
104 |
photometric == #rgba ifTrue:[ |
|
105 |
rVal := bytes at:(index). |
|
106 |
gVal := bytes at:(index + 1). |
|
107 |
bVal := bytes at:(index + 2). |
|
108 |
aVal := bytes at:(index + 3). |
|
109 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal |
|
110 |
]. |
|
111 |
photometric == #argb ifTrue:[ |
|
112 |
aVal := bytes at:(index). |
|
113 |
rVal := bytes at:(index + 1). |
|
114 |
gVal := bytes at:(index + 2). |
|
115 |
bVal := bytes at:(index + 3). |
|
116 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal alphaByte:aVal |
|
117 |
]. |
|
6841 | 118 |
|
7124 | 119 |
"/ the inherited method should handle all cases. |
120 |
^ super colorAtX:x y:y. |
|
6841 | 121 |
! |
122 |
||
123 |
colorAtX:x y:y put:aColor |
|
124 |
"set the pixel at x/y to aColor. |
|
125 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
126 |
x = width-1, y=height-1 for lower right pixel." |
|
127 |
||
128 |
|index "{ Class: SmallInteger }"| |
|
129 |
||
7917 | 130 |
(photometric == #rgb) ifTrue:[ |
7167 | 131 |
index := 1 + (((width * y) + x) * 4). |
132 |
bytes at:(index) put:(aColor redByte). |
|
133 |
bytes at:(index + 1) put:(aColor greenByte). |
|
134 |
bytes at:(index + 2) put:(aColor blueByte). |
|
7917 | 135 |
bytes at:(index + 3) put:0. |
136 |
^ self |
|
137 |
]. |
|
138 |
(photometric == #rgba) ifTrue:[ |
|
139 |
index := 1 + (((width * y) + x) * 4). |
|
140 |
bytes at:(index) put:(aColor redByte). |
|
141 |
bytes at:(index + 1) put:(aColor greenByte). |
|
142 |
bytes at:(index + 2) put:(aColor blueByte). |
|
143 |
bytes at:(index + 3) put:(aColor alphaByte). "alpha channel" |
|
7167 | 144 |
^ self |
145 |
]. |
|
146 |
(photometric == #argb) ifTrue:[ |
|
147 |
index := 1 + (((width * y) + x) * 4). |
|
7917 | 148 |
bytes at:(index) put:255. "alpha channel" |
7167 | 149 |
bytes at:(index + 1) put:(aColor redByte). |
150 |
bytes at:(index + 2) put:(aColor greenByte). |
|
151 |
bytes at:(index + 3) put:(aColor blueByte). |
|
152 |
^ self |
|
153 |
]. |
|
6841 | 154 |
|
7917 | 155 |
super colorAtX:x y:y put:aColor. |
156 |
||
157 |
"Modified: / 21-02-2017 / 01:49:58 / cg" |
|
6841 | 158 |
! |
159 |
||
1663 | 160 |
pixelAtX:x y:y |
161 |
"retrieve a pixel at x/y; return a pixelValue. |
|
7514 | 162 |
The interpretation of the returned value depends on the photometric |
163 |
and the colormap. See also Image>>atX:y:) |
|
1663 | 164 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
7279 | 165 |
x = width-1, y=height-1 for lower right pixel. |
7922 | 166 |
With rgba photometric, the pixel value contains r/g/b/a in msb order (i.e. r at high, a at low bits); |
167 |
with argb, alpha is in the high byte" |
|
1663 | 168 |
|
1669 | 169 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 170 |
|
7274 | 171 |
%{ /* NOCONTEXT */ |
172 |
OBJ b = __INST(bytes); |
|
173 |
OBJ w = __INST(width); |
|
174 |
||
175 |
if (__isByteArrayLike(b) |
|
176 |
&& __bothSmallInteger(x, y) |
|
177 |
&& __isSmallInteger(w) |
|
178 |
&& (__INST(pixelFunction)==nil) ) { |
|
179 |
int _idx; |
|
180 |
||
181 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
|
182 |
if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
|
183 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
184 |
unsigned int _pix; |
|
7917 | 185 |
|
7922 | 186 |
#ifdef __MSBFIRST__ |
187 |
_pix = ((int *)pPix)[0]; |
|
188 |
#else |
|
189 |
_pix = pPix[0] << 24; |
|
190 |
_pix |= pPix[1] << 16; |
|
191 |
_pix |= pPix[2] << 8; |
|
192 |
_pix |= pPix[3]; |
|
193 |
#endif |
|
194 |
||
7274 | 195 |
#if __POINTER_SIZE__ == 8 |
196 |
RETURN( __MKSMALLINT(_pix) ); |
|
197 |
#else |
|
198 |
RETURN( __MKUINT(_pix) ); |
|
199 |
#endif |
|
200 |
} |
|
201 |
} |
|
202 |
%}. |
|
6302 | 203 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
204 |
||
6841 | 205 |
pixelIndex := 1 + (((width * y) + x) * 4). |
1663 | 206 |
|
207 |
"left pixel in high bits" |
|
7922 | 208 |
^ bytes unsignedInt32At:pixelIndex MSB:true. |
1663 | 209 |
|
7917 | 210 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
7922 | 211 |
"Modified: / 21-02-2017 / 17:21:44 / cg" |
1663 | 212 |
! |
213 |
||
214 |
pixelAtX:x y:y put:aPixelValue |
|
215 |
"set the pixel at x/y to aPixelValue. |
|
7922 | 216 |
The interpretation of the pixelValue depends on the photometric. |
1663 | 217 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
218 |
x = width-1, y=height-1 for lower right pixel" |
|
219 |
||
1669 | 220 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 221 |
|
6841 | 222 |
pixelIndex := 1 + (((width * y) + x) * 4). |
4790 | 223 |
bytes isNil ifTrue:[ |
6841 | 224 |
self createPixelStore |
4790 | 225 |
]. |
7922 | 226 |
bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true. |
1663 | 227 |
|
4790 | 228 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
7922 | 229 |
"Modified: / 21-02-2017 / 14:59:35 / cg" |
6841 | 230 |
! |
231 |
||
232 |
rowAt:y putAll:pixelArray startingAt:startIndex |
|
233 |
"store a single rows bits from bits in the pixelArray argument; |
|
234 |
Return the pixelArray. |
|
235 |
Notice: row coordinate starts at 0." |
|
236 |
||
7922 | 237 |
|bytes pixel |
238 |
dstIdx "{ Class: SmallInteger }" |
|
6846 | 239 |
w "{ Class: SmallInteger }"| |
6841 | 240 |
|
241 |
bytes := self bits. |
|
242 |
dstIdx := (y * self bytesPerRow) + 1. |
|
6846 | 243 |
w := width - 1. |
244 |
||
245 |
0 to:w do:[:col | |
|
6841 | 246 |
pixel := pixelArray at:(startIndex + col). |
7922 | 247 |
bytes unsignedInt32At:dstIdx put:pixel MSB:true. |
6841 | 248 |
dstIdx := dstIdx + 4. |
249 |
]. |
|
250 |
^ pixelArray |
|
7917 | 251 |
|
7922 | 252 |
"Modified (comment): / 21-02-2017 / 15:03:24 / cg" |
1663 | 253 |
! ! |
254 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
255 |
!Depth32Image methodsFor:'converting rgb images'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
256 |
|
7492 | 257 |
computeAlphaValuesFromMask:aMaskImage |
258 |
"convert a mask into alpha values; |
|
7922 | 259 |
masked pixels get an alpha value of 0, unmasked of 255" |
7492 | 260 |
|
261 |
|alphaMask| |
|
262 |
||
7922 | 263 |
alphaMask := (self alphaMaskForPixelValue bitShift:self alphaShiftForPixelValue). |
7902 | 264 |
self |
265 |
valuesFromX:0 y:0 toX:(width-1) y:(height-1) |
|
266 |
do:[:x :y :pixelValue | |
|
267 |
(aMaskImage pixelAtX:x y:y) ~~ 0 ifTrue:[ |
|
268 |
self pixelAtX:x y:y put:(pixelValue bitOr:alphaMask). |
|
269 |
] ifFalse:[ |
|
270 |
self pixelAtX:x y:y put:(pixelValue bitClear:alphaMask). |
|
271 |
]. |
|
7492 | 272 |
]. |
273 |
photometric := #rgba |
|
7902 | 274 |
|
7922 | 275 |
"Modified: / 21-02-2017 / 16:41:02 / cg" |
7492 | 276 |
! |
277 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
278 |
rgbImageAsTrueColorFormOn:aDevice |
7122 | 279 |
"return a truecolor form from the rgba or argb-picture." |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
280 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
281 |
|bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
282 |
myDepth form imageBits padd |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
283 |
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue| |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
284 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
285 |
bytes := self bits. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
286 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
287 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4763 | 288 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
289 |
usedDeviceDepth := bestFormat at:#depth. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
290 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
291 |
usedDevicePadding := bestFormat at:#padding. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
292 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
293 |
rightShiftR := (8 - aDevice bitsRed). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
294 |
rightShiftG := (8 - aDevice bitsGreen). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
295 |
rightShiftB := (8 - aDevice bitsBlue). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
296 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
297 |
shiftRed := aDevice shiftRed. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
298 |
shiftGreen := aDevice shiftGreen. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
299 |
shiftBlue := aDevice shiftBlue. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
300 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
301 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
302 |
"/ for now, only a few formats are supported |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
303 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
304 |
myDepth := self bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
305 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
7122 | 306 |
"/ |
307 |
"/ 24 bit/pixel |
|
308 |
"/ |
|
309 |
imageBits := ByteArray uninitializedNew:(width * height * 3). |
|
310 |
usedDevicePadding := 8. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
311 |
|
7122 | 312 |
"/ now, walk over the image and compose 24bit values from the r/g/b/a triples |
313 |
%{ |
|
314 |
unsigned char *srcPtr = 0; |
|
315 |
unsigned char *dstPtr = 0; |
|
316 |
int redOffs = 0; |
|
317 |
int greenOffs = 1; |
|
318 |
int blueOffs = 2; |
|
319 |
int alphaOffs = 3; |
|
320 |
||
321 |
if (__INST(photometric) == @symbol(argb)) { |
|
322 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
323 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
324 |
|
7122 | 325 |
if (__isByteArrayLike(bytes)) { |
326 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
327 |
} else { |
|
328 |
if (__isExternalBytesLike(bytes)) { |
|
329 |
srcPtr = __externalBytesAddress(bytes); |
|
330 |
} |
|
331 |
} |
|
332 |
if (__isByteArray(imageBits)) { |
|
333 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
334 |
} else { |
|
335 |
if (__isExternalBytesLike(imageBits)) { |
|
336 |
dstPtr = __externalBytesAddress(imageBits); |
|
337 |
} |
|
338 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
339 |
|
7122 | 340 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
341 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
342 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
343 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
344 |
&& srcPtr |
|
345 |
&& dstPtr) { |
|
346 |
int rShRed = __intVal(rightShiftR), |
|
347 |
rShGreen = __intVal(rightShiftG), |
|
348 |
rShBlue = __intVal(rightShiftB), |
|
349 |
lShRed = __intVal(shiftRed), |
|
350 |
lShGreen = __intVal(shiftGreen), |
|
351 |
lShBlue = __intVal(shiftBlue); |
|
352 |
int x, y, w; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
353 |
|
7122 | 354 |
w = __intVal(__INST(width)); |
355 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
356 |
if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) { |
|
357 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
358 |
for (x=w; x > 0; x--) { |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
359 |
# ifdef __MSBFIRST |
7122 | 360 |
dstPtr[0] = srcPtr[redOffs]; |
361 |
dstPtr[1] = srcPtr[greenOffs]; |
|
362 |
dstPtr[2] = srcPtr[blueOffs]; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
363 |
# else /* not MSB */ |
7122 | 364 |
dstPtr[0] = srcPtr[blueOffs]; |
365 |
dstPtr[1] = srcPtr[greenOffs]; |
|
366 |
dstPtr[2] = srcPtr[redOffs]; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
367 |
# endif /* not MSB */ |
7122 | 368 |
dstPtr += 3; |
369 |
srcPtr += 4; |
|
370 |
} |
|
371 |
} |
|
372 |
} else { |
|
373 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
374 |
for (x=w; x > 0; x--) { |
|
375 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
376 |
|
7122 | 377 |
v = srcPtr[redOffs] << lShRed; |
378 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
379 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
380 |
# ifdef __MSBFIRST |
7122 | 381 |
dstPtr[0] = (v) & 0xFF; |
382 |
dstPtr[1] = (v>>8) & 0xFF; |
|
383 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
384 |
# else /* not MSB */ |
7122 | 385 |
dstPtr[0] = (v>>16) & 0xFF; |
386 |
dstPtr[1] = (v>>8) & 0xFF; |
|
387 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
388 |
# endif /* not MSB */ |
7122 | 389 |
dstPtr += 3; |
390 |
srcPtr += 4; |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
} else { |
|
395 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
396 |
for (x=w; x > 0; x--) { |
|
397 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
398 |
|
7122 | 399 |
r = srcPtr[redOffs] >> rShRed; |
400 |
g = srcPtr[greenOffs] >> rShGreen; |
|
401 |
b = srcPtr[blueOffs] >> rShBlue; |
|
402 |
v = r << lShRed; |
|
403 |
v |= (g << lShGreen); |
|
404 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
405 |
# ifdef __MSBFIRST |
7122 | 406 |
dstPtr[0] = (v) & 0xFF; |
407 |
dstPtr[1] = (v>>8) & 0xFF; |
|
408 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
409 |
# else /* not MSB */ |
7122 | 410 |
dstPtr[0] = (v>>16) & 0xFF; |
411 |
dstPtr[1] = (v>>8) & 0xFF; |
|
412 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
413 |
# endif /* not MSB */ |
7122 | 414 |
dstPtr += 3; |
415 |
srcPtr += 4; |
|
416 |
} |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
420 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
421 |
] ifFalse:[ |
7122 | 422 |
"/ |
423 |
"/ 8, 16 or 32 bit/pixel ... |
|
424 |
"/ |
|
425 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
|
426 |
padd := width \\ (usedDevicePadding // 16). |
|
427 |
imageBits := ByteArray uninitializedNew:((width + padd) * height * 2). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
428 |
|
7122 | 429 |
"/ 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
|
430 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
431 |
%{ |
7122 | 432 |
unsigned char *srcPtr = 0; |
433 |
unsigned char *dstPtr = 0; |
|
434 |
int redOffs = 0; |
|
435 |
int greenOffs = 1; |
|
436 |
int blueOffs = 2; |
|
437 |
int alphaOffs = 3; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
438 |
|
7122 | 439 |
if (__INST(photometric) == @symbol(argb)) { |
440 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
441 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
442 |
|
7122 | 443 |
if (__isByteArrayLike(bytes)) { |
444 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
445 |
} else { |
|
446 |
if (__isExternalBytesLike(bytes)) { |
|
447 |
srcPtr = __externalBytesAddress(bytes); |
|
448 |
} |
|
449 |
} |
|
450 |
if (__isByteArray(imageBits)) { |
|
451 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
452 |
} else { |
|
453 |
if (__isExternalBytesLike(imageBits)) { |
|
454 |
dstPtr = __externalBytesAddress(imageBits); |
|
455 |
} |
|
456 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
457 |
|
7122 | 458 |
if (__bothSmallInteger(__INST(height),__INST(width)) |
459 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
460 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
461 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
462 |
&& srcPtr |
|
463 |
&& dstPtr) { |
|
464 |
int rShRed = __intVal(rightShiftR), |
|
465 |
rShGreen = __intVal(rightShiftG), |
|
466 |
rShBlue = __intVal(rightShiftB), |
|
467 |
lShRed = __intVal(shiftRed), |
|
468 |
lShGreen = __intVal(shiftGreen), |
|
469 |
lShBlue = __intVal(shiftBlue); |
|
470 |
int x, y, w; |
|
471 |
int p; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
472 |
|
7122 | 473 |
w = __intVal(__INST(width)); |
474 |
p = __intVal(padd) * 2; |
|
475 |
||
476 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
477 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
478 |
for (x=w; x > 0; x--) { |
|
479 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
480 |
|
7122 | 481 |
v = srcPtr[redOffs] << lShRed; |
482 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
483 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
484 |
# ifdef __MSBFIRST |
7122 | 485 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
486 |
# else /* not MSB */ |
7122 | 487 |
dstPtr[0] = (v>>8) & 0xFF; |
488 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
489 |
# endif /* not MSB */ |
7122 | 490 |
dstPtr += 2; |
491 |
srcPtr += 4; |
|
492 |
} |
|
493 |
dstPtr += p; |
|
494 |
} |
|
495 |
} else { |
|
496 |
if (p == 0) { |
|
497 |
int n = __intVal(__INST(height)) * w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
498 |
|
7122 | 499 |
while (n >= 2) { |
500 |
unsigned w, r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
501 |
|
7122 | 502 |
n -= 2; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
503 |
|
7122 | 504 |
r = srcPtr[redOffs]; |
505 |
g = srcPtr[greenOffs]; |
|
506 |
b = srcPtr[blueOffs]; |
|
507 |
v = (r >> rShRed) << lShRed; |
|
508 |
v |= ((g >> rShGreen) << lShGreen); |
|
509 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
510 |
# ifdef __MSBFIRST |
7122 | 511 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
512 |
# else |
7122 | 513 |
dstPtr[0] = (v>>8) & 0xFF; |
514 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
515 |
# endif /* not MSB */ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
516 |
|
7122 | 517 |
r = srcPtr[3+redOffs]; |
518 |
g = srcPtr[3+greenOffs]; |
|
519 |
b = srcPtr[3+blueOffs]; |
|
520 |
v = (r >> rShRed) << lShRed; |
|
521 |
v |= ((g >> rShGreen) << lShGreen); |
|
522 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
523 |
# ifdef __MSBFIRST |
7122 | 524 |
((short *)dstPtr)[1] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
525 |
# else |
7122 | 526 |
dstPtr[2] = (v>>8) & 0xFF; |
527 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
528 |
# endif /* not MSB */ |
7122 | 529 |
dstPtr += 4; |
530 |
srcPtr += 8; |
|
531 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
532 |
|
7122 | 533 |
while (n--) { |
534 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
535 |
|
7122 | 536 |
r = srcPtr[redOffs] >> rShRed; |
537 |
g = srcPtr[greenOffs] >> rShGreen; |
|
538 |
b = srcPtr[blueOffs] >> rShBlue; |
|
539 |
v = r << lShRed; |
|
540 |
v |= (g << lShGreen); |
|
541 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
542 |
# ifdef __MSBFIRST |
7122 | 543 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
544 |
# else /* not MSB */ |
7122 | 545 |
dstPtr[0] = (v>>8) & 0xFF; |
546 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
547 |
# endif /* not MSB */ |
7122 | 548 |
dstPtr += 2; |
549 |
srcPtr += 4; |
|
550 |
} |
|
551 |
} else { |
|
552 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
553 |
for (x=w; x > 0; x--) { |
|
554 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
555 |
|
7122 | 556 |
r = srcPtr[redOffs] >> rShRed; |
557 |
g = srcPtr[greenOffs] >> rShGreen; |
|
558 |
b = srcPtr[blueOffs] >> rShBlue; |
|
559 |
v = r << lShRed; |
|
560 |
v |= (g << lShGreen); |
|
561 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
562 |
# ifdef __MSBFIRST |
7122 | 563 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
564 |
# else /* not MSB */ |
7122 | 565 |
dstPtr[0] = (v>>8) & 0xFF; |
566 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
567 |
# endif /* not MSB */ |
7122 | 568 |
dstPtr += 2; |
569 |
srcPtr += 4; |
|
570 |
} |
|
571 |
dstPtr += p; |
|
572 |
} |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
576 |
%}. |
7122 | 577 |
] ifFalse:[ |
578 |
"/ |
|
579 |
"/ 32 or 8 bits/pixel ... |
|
580 |
"/ |
|
581 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
|
582 |
usedDevicePadding := 8. |
|
583 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
584 |
|
7122 | 585 |
"/ 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
|
586 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
587 |
%{ |
7122 | 588 |
unsigned char *srcPtr = 0; |
589 |
unsigned char *dstPtr = 0; |
|
590 |
int redOffs = 0; |
|
591 |
int greenOffs = 1; |
|
592 |
int blueOffs = 2; |
|
593 |
int alphaOffs = 3; |
|
594 |
||
595 |
if (__INST(photometric) == @symbol(argb)) { |
|
596 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
597 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
598 |
|
7122 | 599 |
if (__isByteArrayLike(bytes)) { |
600 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
601 |
} else { |
|
602 |
if (__isExternalBytesLike(bytes)) { |
|
603 |
srcPtr = __externalBytesAddress(bytes); |
|
604 |
} |
|
605 |
} |
|
606 |
if (__isByteArray(imageBits)) { |
|
607 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
608 |
} else { |
|
609 |
if (__isExternalBytesLike(imageBits)) { |
|
610 |
dstPtr = __externalBytesAddress(imageBits); |
|
611 |
} |
|
612 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
613 |
|
7122 | 614 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
615 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
616 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
617 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
618 |
&& srcPtr |
|
619 |
&& dstPtr) { |
|
620 |
int rShRed = __intVal(rightShiftR), |
|
621 |
rShGreen = __intVal(rightShiftG), |
|
622 |
rShBlue = __intVal(rightShiftB), |
|
623 |
lShRed = __intVal(shiftRed), |
|
624 |
lShGreen = __intVal(shiftGreen), |
|
625 |
lShBlue = __intVal(shiftBlue); |
|
626 |
int x, y, w; |
|
627 |
||
628 |
w = __intVal(__INST(width)); |
|
629 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
630 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
631 |
for (x=w; x > 0; x--) { |
|
632 |
unsigned v; |
|
633 |
||
634 |
v = srcPtr[redOffs] << lShRed; |
|
635 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
636 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
637 |
# ifdef __MSBFIRST |
7122 | 638 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
639 |
# else /* not MSB */ |
7122 | 640 |
dstPtr[0] = (v>>24) & 0xFF; |
641 |
dstPtr[1] = (v>>16) & 0xFF; |
|
642 |
dstPtr[2] = (v>>8) & 0xFF; |
|
643 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
644 |
# endif /* not MSB */ |
7122 | 645 |
dstPtr += 4; |
646 |
srcPtr += 4; |
|
647 |
} |
|
648 |
} |
|
649 |
} else { |
|
650 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
651 |
for (x=w; x > 0; x--) { |
|
652 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
653 |
|
7122 | 654 |
r = srcPtr[redOffs] >> rShRed; |
655 |
g = srcPtr[greenOffs] >> rShGreen; |
|
656 |
b = srcPtr[blueOffs] >> rShBlue; |
|
657 |
v = r << lShRed; |
|
658 |
v |= (g << lShGreen); |
|
659 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
660 |
# ifdef __MSBFIRST |
7122 | 661 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
662 |
# else /* not MSB */ |
7122 | 663 |
dstPtr[0] = (v>>24) & 0xFF; |
664 |
dstPtr[1] = (v>>16) & 0xFF; |
|
665 |
dstPtr[2] = (v>>8) & 0xFF; |
|
666 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
667 |
# endif /* not MSB */ |
7122 | 668 |
dstPtr += 4; |
669 |
srcPtr += 4; |
|
670 |
} |
|
671 |
} |
|
672 |
} |
|
673 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
674 |
%}. |
7122 | 675 |
] ifFalse:[ |
676 |
"/ |
|
677 |
"/ 8 bits/pixel ... |
|
678 |
"/ |
|
679 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
680 |
usedDevicePadding := 8. |
|
681 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
682 |
|
7122 | 683 |
"/ 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
|
684 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
685 |
%{ |
7122 | 686 |
unsigned char *srcPtr = 0; |
687 |
unsigned char *dstPtr = 0; |
|
688 |
int redOffs = 0; |
|
689 |
int greenOffs = 1; |
|
690 |
int blueOffs = 2; |
|
691 |
int alphaOffs = 3; |
|
692 |
||
693 |
if (__INST(photometric) == @symbol(argb)) { |
|
694 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
695 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
696 |
|
7122 | 697 |
if (__isByteArrayLike(bytes)) { |
698 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
699 |
} else { |
|
700 |
if (__isExternalBytesLike(bytes)) { |
|
701 |
srcPtr = __externalBytesAddress(bytes); |
|
702 |
} |
|
703 |
} |
|
704 |
if (__isByteArray(imageBits)) { |
|
705 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
706 |
} else { |
|
707 |
if (__isExternalBytesLike(imageBits)) { |
|
708 |
dstPtr = __externalBytesAddress(imageBits); |
|
709 |
} |
|
710 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
711 |
|
7122 | 712 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
713 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
714 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
715 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
716 |
&& srcPtr |
|
717 |
&& dstPtr) { |
|
718 |
int rShRed = __intVal(rightShiftR), |
|
719 |
rShGreen = __intVal(rightShiftG), |
|
720 |
rShBlue = __intVal(rightShiftB), |
|
721 |
lShRed = __intVal(shiftRed), |
|
722 |
lShGreen = __intVal(shiftGreen), |
|
723 |
lShBlue = __intVal(shiftBlue); |
|
724 |
int x, y, w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
725 |
|
7122 | 726 |
w = __intVal(__INST(width)); |
727 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
728 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
729 |
for (x=w; x > 0; x--) { |
|
730 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
731 |
|
7122 | 732 |
v = srcPtr[redOffs] << lShRed; |
733 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
734 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
735 |
dstPtr[0] = v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
736 |
|
7122 | 737 |
dstPtr += 1; |
738 |
srcPtr += 4; |
|
739 |
} |
|
740 |
} |
|
741 |
} else { |
|
742 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
743 |
for (x=w; x > 0; x--) { |
|
744 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
745 |
|
7122 | 746 |
r = srcPtr[redOffs] >> rShRed; |
747 |
g = srcPtr[greenOffs] >> rShGreen; |
|
748 |
b = srcPtr[blueOffs] >> rShBlue; |
|
749 |
v = r << lShRed; |
|
750 |
v |= (g << lShGreen); |
|
751 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
752 |
|
7122 | 753 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
754 |
|
7122 | 755 |
dstPtr += 1; |
756 |
srcPtr += 4; |
|
757 |
} |
|
758 |
} |
|
759 |
} |
|
760 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
761 |
%}. |
7122 | 762 |
] |
763 |
]. |
|
764 |
] |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
765 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
766 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
767 |
imageBits isNil ifTrue:[ |
7122 | 768 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
769 |
usedDeviceBitsPerPixel errorPrintCR. |
|
770 |
^ self asMonochromeFormOn:aDevice |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
771 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
772 |
|
7497 | 773 |
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
|
774 |
form isNil ifTrue:[ |
7122 | 775 |
'Depth32Image [warning]: display bitmap creation failed' errorPrintCR. |
776 |
^ nil |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
777 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
778 |
form initGC. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
779 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
780 |
form |
7122 | 781 |
copyBitsFrom:imageBits |
782 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
783 |
depth:usedDeviceDepth |
|
784 |
padding:usedDevicePadding |
|
785 |
width:width height:height |
|
786 |
x:0 y:0 toX:0 y:0. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
787 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
788 |
^ form |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
789 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
790 |
"Created: / 27-05-2007 / 16:54:19 / cg" |
4763 | 791 |
"Modified: / 29-05-2007 / 12:19:04 / cg" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
792 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
793 |
|
6841 | 794 |
!Depth32Image methodsFor:'image manipulations'! |
795 |
||
796 |
negative |
|
7922 | 797 |
|bytes |
798 |
index "{ Class: SmallInteger }" |
|
799 |
newImage newBytes nBytes r g b a| |
|
6841 | 800 |
|
801 |
photometric ~~ #rgb ifTrue:[ |
|
802 |
^ super negative. |
|
803 |
]. |
|
804 |
bytes := self bits. |
|
805 |
||
806 |
newImage := self copy. |
|
807 |
nBytes := bytes size. |
|
808 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
809 |
index := 1. |
|
810 |
[index < nBytes] whileTrue:[ |
|
811 |
r := bytes at:index. |
|
812 |
newBytes at:index put:(255-r). |
|
813 |
index := index + 1. |
|
814 |
g := bytes at:index. |
|
815 |
newBytes at:index put:(255-g). |
|
816 |
index := index + 1. |
|
817 |
b := bytes at:index. |
|
818 |
newBytes at:index put:(255-b). |
|
819 |
index := index + 1. |
|
7922 | 820 |
a := bytes at:index. |
821 |
newBytes at:index put:a. |
|
6841 | 822 |
index := index + 1. |
823 |
]. |
|
824 |
^ newImage |
|
7922 | 825 |
|
826 |
"Modified (comment): / 21-02-2017 / 17:09:03 / cg" |
|
6841 | 827 |
! ! |
828 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
829 |
!Depth32Image methodsFor:'initialization'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
830 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
831 |
initialize |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
832 |
super initialize. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
833 |
samplesPerPixel := 4. |
7819 | 834 |
bitsPerSample := #[8 8 8 8]. |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
835 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
836 |
"Created: / 27-05-2007 / 14:09:16 / cg" |
7819 | 837 |
"Modified: / 30-01-2017 / 19:32:13 / stefan" |
4761
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 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
840 |
!Depth32Image methodsFor:'magnification'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
841 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
842 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
843 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
844 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
845 |
"magnify a single pixel row - can only magnify by integer factors" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
846 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
847 |
%{ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
848 |
unsigned char *srcP, *dstP; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
849 |
int _mag; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
850 |
REGISTER int i; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
851 |
REGISTER unsigned char byte1, byte2, byte3, byte4; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
852 |
int _pixels; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
853 |
OBJ w = __INST(width); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
854 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
855 |
if (__bothSmallInteger(srcStart, dstStart) |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
856 |
&& __bothSmallInteger(w, mX) |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
857 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
858 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
859 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
860 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
861 |
_pixels = __intVal(w); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
862 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
863 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
864 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
865 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
866 |
byte3 = *(srcP+2); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
867 |
byte4 = *(srcP+3); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
868 |
srcP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
869 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
870 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
871 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
872 |
*(dstP+2) = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
873 |
*(dstP+3) = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
874 |
dstP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
875 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
876 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
877 |
RETURN (self); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
878 |
} |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
879 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
880 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
881 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
882 |
into:dstBytes offset:dstStart factor:mX |
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 |
"Created: / 28-05-2007 / 15:20:52 / cg" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
885 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
886 |
|
1663 | 887 |
!Depth32Image methodsFor:'queries'! |
888 |
||
7122 | 889 |
alphaBitsOf:pixel |
890 |
"given a pixel-value, return the alpha component as byteValue (0..255)" |
|
891 |
||
892 |
photometric == #rgba ifTrue:[ |
|
893 |
"r,g,b,a" |
|
894 |
^ pixel bitAnd:16rFF. |
|
895 |
]. |
|
896 |
photometric == #argb ifTrue:[ |
|
897 |
"a,r,g,b" |
|
898 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
899 |
]. |
|
7167 | 900 |
photometric == #rgb ifTrue:[ |
901 |
^ 0 |
|
902 |
]. |
|
7122 | 903 |
self error:'unsupported photometric' |
904 |
! |
|
905 |
||
906 |
alphaComponentOf:pixel |
|
907 |
"given a pixel-value, return the alpha component in percent (0..100)" |
|
908 |
||
909 |
^ (self alphaBitsOf:pixel) * (100.0 / 255.0) |
|
910 |
! |
|
911 |
||
912 |
alphaMaskForPixelValue |
|
7922 | 913 |
"return the mask used with translation from pixelValues to alphaBits. |
914 |
Determines the number of bits of alpha" |
|
7122 | 915 |
|
916 |
^ 16rFF |
|
7922 | 917 |
|
918 |
"Modified (comment): / 21-02-2017 / 16:37:31 / cg" |
|
7122 | 919 |
! |
920 |
||
921 |
alphaShiftForPixelValue |
|
7922 | 922 |
"return the shift amount used with translation from pixelValues to alphaBits. |
923 |
That is the number of bits to shift the alpha value into the pixel value." |
|
7122 | 924 |
|
925 |
photometric == #rgba ifTrue:[ |
|
7922 | 926 |
"/ alpha in low byte |
7122 | 927 |
"r,g,b,a" |
928 |
^ 0 |
|
929 |
]. |
|
930 |
photometric == #argb ifTrue:[ |
|
7922 | 931 |
"/ alpha in high byte |
7122 | 932 |
"a,r,g,b" |
7922 | 933 |
^ 24. |
7122 | 934 |
]. |
7896 | 935 |
photometric == #rgb ifTrue:[ |
7922 | 936 |
"r,g,b - no alpha" |
937 |
"/ Logger warning:'oops - image has depth 32, but photometric is #rgb'. |
|
7896 | 938 |
^ 0. |
939 |
]. |
|
940 |
self error:'unsupported photometric: ',(photometric printString) |
|
941 |
||
7922 | 942 |
"Modified (format): / 21-02-2017 / 16:42:42 / cg" |
7122 | 943 |
! |
944 |
||
1663 | 945 |
bitsPerPixel |
946 |
"return the number of bits per pixel" |
|
947 |
||
948 |
^ 32 |
|
949 |
||
950 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
951 |
! |
|
952 |
||
953 |
bitsPerRow |
|
954 |
"return the number of bits in one scanline of the image" |
|
955 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
956 |
^ width * 32 |
1663 | 957 |
|
958 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
959 |
! |
|
960 |
||
6841 | 961 |
bitsPerSample |
962 |
"return the number of bits per sample. |
|
963 |
The return value is an array of bits-per-plane." |
|
964 |
||
965 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
|
7819 | 966 |
^ #[8 8 8 8] |
967 |
||
968 |
"Modified: / 30-01-2017 / 19:23:31 / stefan" |
|
6841 | 969 |
! |
970 |
||
971 |
blueBitsOf:pixel |
|
972 |
"given a pixel-value, return the blue component as byteValue (0..255)" |
|
973 |
||
7185 | 974 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7922 | 975 |
"r,g,b,a or r,g,b,0" |
7122 | 976 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
977 |
]. |
|
978 |
photometric == #argb ifTrue:[ |
|
979 |
"a,r,g,b" |
|
980 |
^ pixel bitAnd:16rFF. |
|
981 |
]. |
|
982 |
self error:'unsupported photometric' |
|
7922 | 983 |
|
984 |
"Modified: / 21-02-2017 / 16:45:12 / cg" |
|
6841 | 985 |
! |
986 |
||
987 |
blueComponentOf:pixel |
|
988 |
"given a pixel-value, return the blue component in percent (0..100)" |
|
989 |
||
7122 | 990 |
^ (self blueBitsOf:pixel) * (100.0 / 255.0) |
6841 | 991 |
! |
992 |
||
993 |
blueMaskForPixelValue |
|
994 |
"return the mask used with translation from pixelValues to blueBits" |
|
995 |
||
996 |
^ 16rFF |
|
997 |
! |
|
998 |
||
999 |
blueShiftForPixelValue |
|
1000 |
"return the shift amount used with translation from pixelValues to blueBits" |
|
1001 |
||
7922 | 1002 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
1003 |
"r,g,b,a or r,g,b,0" |
|
7122 | 1004 |
^ -8 |
1005 |
]. |
|
1006 |
photometric == #argb ifTrue:[ |
|
1007 |
"a,r,g,b" |
|
1008 |
^ 0. |
|
1009 |
]. |
|
1010 |
self error:'unsupported photometric' |
|
7922 | 1011 |
|
1012 |
"Modified: / 21-02-2017 / 17:03:36 / cg" |
|
6841 | 1013 |
! |
1014 |
||
1663 | 1015 |
bytesPerRow |
1016 |
"return the number of bytes in one scanline of the image" |
|
1017 |
||
1018 |
^ width * 4. |
|
1019 |
||
1020 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
5327 | 1021 |
! |
1022 |
||
6841 | 1023 |
greenBitsOf:pixel |
1024 |
"given a pixel-value, return the green component as byteValue (0..255)" |
|
1025 |
||
7185 | 1026 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7922 | 1027 |
"r,g,b,a or r,g,b,0" |
7122 | 1028 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
1029 |
]. |
|
1030 |
photometric == #argb ifTrue:[ |
|
1031 |
"a,r,g,b" |
|
1032 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
1033 |
]. |
|
1034 |
self error:'unsupported photometric' |
|
7922 | 1035 |
|
1036 |
"Modified (format): / 21-02-2017 / 16:44:50 / cg" |
|
6841 | 1037 |
! |
1038 |
||
1039 |
greenComponentOf:pixel |
|
1040 |
"given a pixel-value, return the green component in percent (0..100)" |
|
1041 |
||
7122 | 1042 |
^ (self greenBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1043 |
! |
1044 |
||
1045 |
greenMaskForPixelValue |
|
1046 |
"return the mask used with translation from pixelValues to redBits" |
|
1047 |
||
1048 |
^ 16rFF |
|
1049 |
! |
|
1050 |
||
1051 |
greenShiftForPixelValue |
|
1052 |
"return the shift amount used with translation from pixelValues to greenBits" |
|
1053 |
||
7922 | 1054 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
1055 |
"r,g,b,a or r,g,b,0" |
|
7122 | 1056 |
^ -16 |
1057 |
]. |
|
1058 |
photometric == #argb ifTrue:[ |
|
1059 |
"a,r,g,b" |
|
1060 |
^ -8. |
|
1061 |
]. |
|
1062 |
self error:'unsupported photometric' |
|
7922 | 1063 |
|
1064 |
"Modified: / 21-02-2017 / 17:03:47 / cg" |
|
6841 | 1065 |
! |
1066 |
||
5327 | 1067 |
hasAlphaChannel |
7922 | 1068 |
"could be #rgb in 32 bits..." |
1069 |
||
1070 |
^ (photometric == #argb) or:[photometric == #rgba] |
|
1071 |
||
1072 |
"Modified: / 21-02-2017 / 15:00:17 / cg" |
|
6841 | 1073 |
! |
1074 |
||
1075 |
redBitsOf:pixel |
|
1076 |
"given a pixel-value, return the red component as byteValue (0..255)" |
|
1077 |
||
7185 | 1078 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7922 | 1079 |
"r,g,b,a or r,g,b,0" |
7122 | 1080 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
1081 |
]. |
|
1082 |
photometric == #argb ifTrue:[ |
|
1083 |
"a,r,g,b" |
|
1084 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
1085 |
]. |
|
1086 |
self error:'unsupported photometric' |
|
7922 | 1087 |
|
1088 |
"Modified (format): / 21-02-2017 / 16:45:18 / cg" |
|
6841 | 1089 |
! |
1090 |
||
1091 |
redComponentOf:pixel |
|
1092 |
"given a pixel-value, return the red component in percent (0..100)" |
|
1093 |
||
7122 | 1094 |
^ (self redBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1095 |
! |
1096 |
||
1097 |
redMaskForPixelValue |
|
1098 |
"return the mask used with translation from pixelValues to redBits" |
|
1099 |
||
1100 |
^ 16rFF |
|
1101 |
! |
|
1102 |
||
1103 |
redShiftForPixelValue |
|
1104 |
"return the shift amount used with translation from pixelValues to redBits" |
|
1105 |
||
7922 | 1106 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
1107 |
"r,g,b,a or r,g,b,0" |
|
7122 | 1108 |
^ -24 |
1109 |
]. |
|
1110 |
photometric == #argb ifTrue:[ |
|
1111 |
"a,r,g,b" |
|
1112 |
^ -16. |
|
1113 |
]. |
|
1114 |
self error:'unsupported photometric' |
|
7922 | 1115 |
|
1116 |
"Modified: / 21-02-2017 / 17:04:04 / cg" |
|
6841 | 1117 |
! |
1118 |
||
1119 |
rgbFromValue:pixelValue |
|
1120 |
"given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB)." |
|
1121 |
||
7922 | 1122 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
1123 |
^ pixelValue rightShift:8 "lsb is alpha channel" |
|
1124 |
]. |
|
1125 |
(photometric == #argb) ifTrue:[ |
|
1126 |
^ pixelValue bitAnd:16rFFFFFF "msb is alpha channel" |
|
1127 |
]. |
|
1128 |
self error:'unsupported photometric' |
|
1129 |
||
1130 |
"Modified: / 21-02-2017 / 17:05:13 / cg" |
|
6841 | 1131 |
! |
1132 |
||
1133 |
samplesPerPixel |
|
1134 |
"return the number of samples per pixel in the image." |
|
1135 |
||
1136 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
|
1137 |
^ 4 |
|
1138 |
! |
|
1139 |
||
1140 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
|
7922 | 1141 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
1142 |
"/ alpha in low byte |
|
1143 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:16rFF |
|
1144 |
]. |
|
1145 |
(photometric == #argb) ifTrue:[ |
|
1146 |
"/ alpha in high byte |
|
1147 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits)) bitOr:16rFF000000 |
|
1148 |
]. |
|
1149 |
self error:'unsupported photometric' |
|
1150 |
||
1151 |
"Modified: / 21-02-2017 / 17:07:11 / cg" |
|
1663 | 1152 |
! ! |
1153 |
||
1154 |
!Depth32Image class methodsFor:'documentation'! |
|
1155 |
||
1156 |
version |
|
7122 | 1157 |
^ '$Header$' |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1158 |
! |
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1159 |
|
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1160 |
version_CVS |
7122 | 1161 |
^ '$Header$' |
1663 | 1162 |
! ! |
6302 | 1163 |