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