author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 03 Apr 2016 17:09:29 +0100 | |
branch | jv |
changeset 7286 | c3b4c3c664d4 |
parent 7226 | 78d9aa881c26 |
parent 7279 | 51d86b5b7883 |
child 7542 | 9e125aa140f9 |
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. |
|
210 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
7279 | 211 |
x = width-1, y=height-1 for lower right pixel. |
212 |
The pixel value contains r/g/b/a in msb order (i.e. r at high, a at low bits)" |
|
1663 | 213 |
|
1669 | 214 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 215 |
|
7274 | 216 |
%{ /* NOCONTEXT */ |
217 |
OBJ b = __INST(bytes); |
|
218 |
OBJ w = __INST(width); |
|
219 |
||
220 |
if (__isByteArrayLike(b) |
|
221 |
&& __bothSmallInteger(x, y) |
|
222 |
&& __isSmallInteger(w) |
|
223 |
&& (__INST(pixelFunction)==nil) ) { |
|
224 |
int _idx; |
|
225 |
||
226 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
|
227 |
if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
|
228 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
229 |
unsigned int _pix; |
|
230 |
_pix = (((((pPix[0]<<8)+pPix[1])<<8)+pPix[2])<<8)+pPix[3]; |
|
231 |
#if __POINTER_SIZE__ == 8 |
|
232 |
RETURN( __MKSMALLINT(_pix) ); |
|
233 |
#else |
|
234 |
RETURN( __MKUINT(_pix) ); |
|
235 |
#endif |
|
236 |
} |
|
237 |
} |
|
238 |
%}. |
|
6302 | 239 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
240 |
||
6841 | 241 |
pixelIndex := 1 + (((width * y) + x) * 4). |
1663 | 242 |
|
243 |
"left pixel in high bits" |
|
7225 | 244 |
^ bytes unsignedInt32At:pixelIndex MSB:true. |
1663 | 245 |
|
246 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
1669 | 247 |
"Modified: 24.4.1997 / 23:11:05 / cg" |
1663 | 248 |
! |
249 |
||
250 |
pixelAtX:x y:y put:aPixelValue |
|
251 |
"set the pixel at x/y to aPixelValue. |
|
252 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
253 |
x = width-1, y=height-1 for lower right pixel" |
|
254 |
||
1669 | 255 |
|pixelIndex "{ Class: SmallInteger }"| |
1663 | 256 |
|
6841 | 257 |
pixelIndex := 1 + (((width * y) + x) * 4). |
4790 | 258 |
bytes isNil ifTrue:[ |
6841 | 259 |
self createPixelStore |
4790 | 260 |
]. |
7225 | 261 |
bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true |
1663 | 262 |
|
4790 | 263 |
"Created: / 24-04-1997 / 19:00:28 / cg" |
264 |
"Modified: / 06-06-2007 / 12:20:57 / cg" |
|
6841 | 265 |
! |
266 |
||
267 |
rowAt:y putAll:pixelArray startingAt:startIndex |
|
268 |
"store a single rows bits from bits in the pixelArray argument; |
|
269 |
Return the pixelArray. |
|
270 |
Notice: row coordinate starts at 0." |
|
271 |
||
6846 | 272 |
|bytes dstIdx pixel |
273 |
w "{ Class: SmallInteger }"| |
|
6841 | 274 |
|
275 |
bytes := self bits. |
|
276 |
dstIdx := (y * self bytesPerRow) + 1. |
|
6846 | 277 |
w := width - 1. |
278 |
||
279 |
0 to:w do:[:col | |
|
6841 | 280 |
pixel := pixelArray at:(startIndex + col). |
7225 | 281 |
bytes unsignedInt32At:dstIdx put:pixel MSB:true. |
6841 | 282 |
dstIdx := dstIdx + 4. |
283 |
]. |
|
284 |
^ pixelArray |
|
1663 | 285 |
! ! |
286 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
287 |
!Depth32Image methodsFor:'converting rgb images'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
288 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
289 |
rgbImageAsTrueColorFormOn:aDevice |
7122 | 290 |
"return a truecolor form from the rgba or argb-picture." |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
291 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
292 |
|bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
293 |
myDepth form imageBits padd |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
294 |
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue| |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
295 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
296 |
bytes := self bits. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
297 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
298 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4763 | 299 |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
300 |
usedDeviceDepth := bestFormat at:#depth. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
301 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
302 |
usedDevicePadding := bestFormat at:#padding. |
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 |
rightShiftR := (8 - aDevice bitsRed). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
305 |
rightShiftG := (8 - aDevice bitsGreen). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
306 |
rightShiftB := (8 - aDevice bitsBlue). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
307 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
308 |
shiftRed := aDevice shiftRed. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
309 |
shiftGreen := aDevice shiftGreen. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
310 |
shiftBlue := aDevice shiftBlue. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
311 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
312 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
313 |
"/ for now, only a few formats are supported |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
314 |
"/ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
315 |
myDepth := self bitsPerPixel. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
316 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
7122 | 317 |
"/ |
318 |
"/ 24 bit/pixel |
|
319 |
"/ |
|
320 |
imageBits := ByteArray uninitializedNew:(width * height * 3). |
|
321 |
usedDevicePadding := 8. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
322 |
|
7122 | 323 |
"/ now, walk over the image and compose 24bit values from the r/g/b/a triples |
324 |
%{ |
|
325 |
unsigned char *srcPtr = 0; |
|
326 |
unsigned char *dstPtr = 0; |
|
327 |
int redOffs = 0; |
|
328 |
int greenOffs = 1; |
|
329 |
int blueOffs = 2; |
|
330 |
int alphaOffs = 3; |
|
331 |
||
332 |
if (__INST(photometric) == @symbol(argb)) { |
|
333 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
334 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
335 |
|
7122 | 336 |
if (__isByteArrayLike(bytes)) { |
337 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
338 |
} else { |
|
339 |
if (__isExternalBytesLike(bytes)) { |
|
340 |
srcPtr = __externalBytesAddress(bytes); |
|
341 |
} |
|
342 |
} |
|
343 |
if (__isByteArray(imageBits)) { |
|
344 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
345 |
} else { |
|
346 |
if (__isExternalBytesLike(imageBits)) { |
|
347 |
dstPtr = __externalBytesAddress(imageBits); |
|
348 |
} |
|
349 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
350 |
|
7122 | 351 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
352 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
353 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
354 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
355 |
&& srcPtr |
|
356 |
&& dstPtr) { |
|
357 |
int rShRed = __intVal(rightShiftR), |
|
358 |
rShGreen = __intVal(rightShiftG), |
|
359 |
rShBlue = __intVal(rightShiftB), |
|
360 |
lShRed = __intVal(shiftRed), |
|
361 |
lShGreen = __intVal(shiftGreen), |
|
362 |
lShBlue = __intVal(shiftBlue); |
|
363 |
int x, y, w; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
364 |
|
7122 | 365 |
w = __intVal(__INST(width)); |
366 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
367 |
if ((lShRed == 0) && (lShGreen == 8) && (lShBlue == 16)) { |
|
368 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
369 |
for (x=w; x > 0; x--) { |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
370 |
# ifdef __MSBFIRST |
7122 | 371 |
dstPtr[0] = srcPtr[redOffs]; |
372 |
dstPtr[1] = srcPtr[greenOffs]; |
|
373 |
dstPtr[2] = srcPtr[blueOffs]; |
|
5297
e1e2793072ad
32bit->24bit (win32) fix (rgb-bgr)
Claus Gittinger <cg@exept.de>
parents:
4790
diff
changeset
|
374 |
# else /* not MSB */ |
7122 | 375 |
dstPtr[0] = srcPtr[blueOffs]; |
376 |
dstPtr[1] = srcPtr[greenOffs]; |
|
377 |
dstPtr[2] = srcPtr[redOffs]; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
378 |
# endif /* not MSB */ |
7122 | 379 |
dstPtr += 3; |
380 |
srcPtr += 4; |
|
381 |
} |
|
382 |
} |
|
383 |
} else { |
|
384 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
385 |
for (x=w; x > 0; x--) { |
|
386 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
387 |
|
7122 | 388 |
v = srcPtr[redOffs] << lShRed; |
389 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
390 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
391 |
# ifdef __MSBFIRST |
7122 | 392 |
dstPtr[0] = (v) & 0xFF; |
393 |
dstPtr[1] = (v>>8) & 0xFF; |
|
394 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
395 |
# else /* not MSB */ |
7122 | 396 |
dstPtr[0] = (v>>16) & 0xFF; |
397 |
dstPtr[1] = (v>>8) & 0xFF; |
|
398 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
399 |
# endif /* not MSB */ |
7122 | 400 |
dstPtr += 3; |
401 |
srcPtr += 4; |
|
402 |
} |
|
403 |
} |
|
404 |
} |
|
405 |
} else { |
|
406 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
407 |
for (x=w; x > 0; x--) { |
|
408 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
409 |
|
7122 | 410 |
r = srcPtr[redOffs] >> rShRed; |
411 |
g = srcPtr[greenOffs] >> rShGreen; |
|
412 |
b = srcPtr[blueOffs] >> rShBlue; |
|
413 |
v = r << lShRed; |
|
414 |
v |= (g << lShGreen); |
|
415 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
416 |
# ifdef __MSBFIRST |
7122 | 417 |
dstPtr[0] = (v) & 0xFF; |
418 |
dstPtr[1] = (v>>8) & 0xFF; |
|
419 |
dstPtr[2] = (v>>16) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
420 |
# else /* not MSB */ |
7122 | 421 |
dstPtr[0] = (v>>16) & 0xFF; |
422 |
dstPtr[1] = (v>>8) & 0xFF; |
|
423 |
dstPtr[2] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
424 |
# endif /* not MSB */ |
7122 | 425 |
dstPtr += 3; |
426 |
srcPtr += 4; |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
431 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
432 |
] ifFalse:[ |
7122 | 433 |
"/ |
434 |
"/ 8, 16 or 32 bit/pixel ... |
|
435 |
"/ |
|
436 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
|
437 |
padd := width \\ (usedDevicePadding // 16). |
|
438 |
imageBits := ByteArray uninitializedNew:((width + padd) * height * 2). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
439 |
|
7122 | 440 |
"/ 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
|
441 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
442 |
%{ |
7122 | 443 |
unsigned char *srcPtr = 0; |
444 |
unsigned char *dstPtr = 0; |
|
445 |
int redOffs = 0; |
|
446 |
int greenOffs = 1; |
|
447 |
int blueOffs = 2; |
|
448 |
int alphaOffs = 3; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
449 |
|
7122 | 450 |
if (__INST(photometric) == @symbol(argb)) { |
451 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
452 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
453 |
|
7122 | 454 |
if (__isByteArrayLike(bytes)) { |
455 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
456 |
} else { |
|
457 |
if (__isExternalBytesLike(bytes)) { |
|
458 |
srcPtr = __externalBytesAddress(bytes); |
|
459 |
} |
|
460 |
} |
|
461 |
if (__isByteArray(imageBits)) { |
|
462 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
463 |
} else { |
|
464 |
if (__isExternalBytesLike(imageBits)) { |
|
465 |
dstPtr = __externalBytesAddress(imageBits); |
|
466 |
} |
|
467 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
468 |
|
7122 | 469 |
if (__bothSmallInteger(__INST(height),__INST(width)) |
470 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
471 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
472 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
473 |
&& srcPtr |
|
474 |
&& dstPtr) { |
|
475 |
int rShRed = __intVal(rightShiftR), |
|
476 |
rShGreen = __intVal(rightShiftG), |
|
477 |
rShBlue = __intVal(rightShiftB), |
|
478 |
lShRed = __intVal(shiftRed), |
|
479 |
lShGreen = __intVal(shiftGreen), |
|
480 |
lShBlue = __intVal(shiftBlue); |
|
481 |
int x, y, w; |
|
482 |
int p; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
483 |
|
7122 | 484 |
w = __intVal(__INST(width)); |
485 |
p = __intVal(padd) * 2; |
|
486 |
||
487 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
488 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
489 |
for (x=w; x > 0; x--) { |
|
490 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
491 |
|
7122 | 492 |
v = srcPtr[redOffs] << lShRed; |
493 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
494 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
495 |
# ifdef __MSBFIRST |
7122 | 496 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
497 |
# else /* not MSB */ |
7122 | 498 |
dstPtr[0] = (v>>8) & 0xFF; |
499 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
500 |
# endif /* not MSB */ |
7122 | 501 |
dstPtr += 2; |
502 |
srcPtr += 4; |
|
503 |
} |
|
504 |
dstPtr += p; |
|
505 |
} |
|
506 |
} else { |
|
507 |
if (p == 0) { |
|
508 |
int n = __intVal(__INST(height)) * w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
509 |
|
7122 | 510 |
while (n >= 2) { |
511 |
unsigned w, r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
512 |
|
7122 | 513 |
n -= 2; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
514 |
|
7122 | 515 |
r = srcPtr[redOffs]; |
516 |
g = srcPtr[greenOffs]; |
|
517 |
b = srcPtr[blueOffs]; |
|
518 |
v = (r >> rShRed) << lShRed; |
|
519 |
v |= ((g >> rShGreen) << lShGreen); |
|
520 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
521 |
# ifdef __MSBFIRST |
7122 | 522 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
523 |
# else |
7122 | 524 |
dstPtr[0] = (v>>8) & 0xFF; |
525 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
526 |
# endif /* not MSB */ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
527 |
|
7122 | 528 |
r = srcPtr[3+redOffs]; |
529 |
g = srcPtr[3+greenOffs]; |
|
530 |
b = srcPtr[3+blueOffs]; |
|
531 |
v = (r >> rShRed) << lShRed; |
|
532 |
v |= ((g >> rShGreen) << lShGreen); |
|
533 |
v |= ((b >> rShBlue) << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
534 |
# ifdef __MSBFIRST |
7122 | 535 |
((short *)dstPtr)[1] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
536 |
# else |
7122 | 537 |
dstPtr[2] = (v>>8) & 0xFF; |
538 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
539 |
# endif /* not MSB */ |
7122 | 540 |
dstPtr += 4; |
541 |
srcPtr += 8; |
|
542 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
543 |
|
7122 | 544 |
while (n--) { |
545 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
546 |
|
7122 | 547 |
r = srcPtr[redOffs] >> rShRed; |
548 |
g = srcPtr[greenOffs] >> rShGreen; |
|
549 |
b = srcPtr[blueOffs] >> rShBlue; |
|
550 |
v = r << lShRed; |
|
551 |
v |= (g << lShGreen); |
|
552 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
553 |
# ifdef __MSBFIRST |
7122 | 554 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
555 |
# else /* not MSB */ |
7122 | 556 |
dstPtr[0] = (v>>8) & 0xFF; |
557 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
558 |
# endif /* not MSB */ |
7122 | 559 |
dstPtr += 2; |
560 |
srcPtr += 4; |
|
561 |
} |
|
562 |
} else { |
|
563 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
564 |
for (x=w; x > 0; x--) { |
|
565 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
566 |
|
7122 | 567 |
r = srcPtr[redOffs] >> rShRed; |
568 |
g = srcPtr[greenOffs] >> rShGreen; |
|
569 |
b = srcPtr[blueOffs] >> rShBlue; |
|
570 |
v = r << lShRed; |
|
571 |
v |= (g << lShGreen); |
|
572 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
573 |
# ifdef __MSBFIRST |
7122 | 574 |
((short *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
575 |
# else /* not MSB */ |
7122 | 576 |
dstPtr[0] = (v>>8) & 0xFF; |
577 |
dstPtr[1] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
578 |
# endif /* not MSB */ |
7122 | 579 |
dstPtr += 2; |
580 |
srcPtr += 4; |
|
581 |
} |
|
582 |
dstPtr += p; |
|
583 |
} |
|
584 |
} |
|
585 |
} |
|
586 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
587 |
%}. |
7122 | 588 |
] ifFalse:[ |
589 |
"/ |
|
590 |
"/ 32 or 8 bits/pixel ... |
|
591 |
"/ |
|
592 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
|
593 |
usedDevicePadding := 8. |
|
594 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
595 |
|
7122 | 596 |
"/ 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
|
597 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
598 |
%{ |
7122 | 599 |
unsigned char *srcPtr = 0; |
600 |
unsigned char *dstPtr = 0; |
|
601 |
int redOffs = 0; |
|
602 |
int greenOffs = 1; |
|
603 |
int blueOffs = 2; |
|
604 |
int alphaOffs = 3; |
|
605 |
||
606 |
if (__INST(photometric) == @symbol(argb)) { |
|
607 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
608 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
609 |
|
7122 | 610 |
if (__isByteArrayLike(bytes)) { |
611 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
612 |
} else { |
|
613 |
if (__isExternalBytesLike(bytes)) { |
|
614 |
srcPtr = __externalBytesAddress(bytes); |
|
615 |
} |
|
616 |
} |
|
617 |
if (__isByteArray(imageBits)) { |
|
618 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
619 |
} else { |
|
620 |
if (__isExternalBytesLike(imageBits)) { |
|
621 |
dstPtr = __externalBytesAddress(imageBits); |
|
622 |
} |
|
623 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
624 |
|
7122 | 625 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
626 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
627 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
628 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
629 |
&& srcPtr |
|
630 |
&& dstPtr) { |
|
631 |
int rShRed = __intVal(rightShiftR), |
|
632 |
rShGreen = __intVal(rightShiftG), |
|
633 |
rShBlue = __intVal(rightShiftB), |
|
634 |
lShRed = __intVal(shiftRed), |
|
635 |
lShGreen = __intVal(shiftGreen), |
|
636 |
lShBlue = __intVal(shiftBlue); |
|
637 |
int x, y, w; |
|
638 |
||
639 |
w = __intVal(__INST(width)); |
|
640 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
641 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
642 |
for (x=w; x > 0; x--) { |
|
643 |
unsigned v; |
|
644 |
||
645 |
v = srcPtr[redOffs] << lShRed; |
|
646 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
647 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
648 |
# ifdef __MSBFIRST |
7122 | 649 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
650 |
# else /* not MSB */ |
7122 | 651 |
dstPtr[0] = (v>>24) & 0xFF; |
652 |
dstPtr[1] = (v>>16) & 0xFF; |
|
653 |
dstPtr[2] = (v>>8) & 0xFF; |
|
654 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
655 |
# endif /* not MSB */ |
7122 | 656 |
dstPtr += 4; |
657 |
srcPtr += 4; |
|
658 |
} |
|
659 |
} |
|
660 |
} else { |
|
661 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
662 |
for (x=w; x > 0; x--) { |
|
663 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
664 |
|
7122 | 665 |
r = srcPtr[redOffs] >> rShRed; |
666 |
g = srcPtr[greenOffs] >> rShGreen; |
|
667 |
b = srcPtr[blueOffs] >> rShBlue; |
|
668 |
v = r << lShRed; |
|
669 |
v |= (g << lShGreen); |
|
670 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
671 |
# ifdef __MSBFIRST |
7122 | 672 |
((int *)dstPtr)[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
673 |
# else /* not MSB */ |
7122 | 674 |
dstPtr[0] = (v>>24) & 0xFF; |
675 |
dstPtr[1] = (v>>16) & 0xFF; |
|
676 |
dstPtr[2] = (v>>8) & 0xFF; |
|
677 |
dstPtr[3] = (v) & 0xFF; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
678 |
# endif /* not MSB */ |
7122 | 679 |
dstPtr += 4; |
680 |
srcPtr += 4; |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
685 |
%}. |
7122 | 686 |
] ifFalse:[ |
687 |
"/ |
|
688 |
"/ 8 bits/pixel ... |
|
689 |
"/ |
|
690 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
691 |
usedDevicePadding := 8. |
|
692 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
693 |
|
7122 | 694 |
"/ 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
|
695 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
696 |
%{ |
7122 | 697 |
unsigned char *srcPtr = 0; |
698 |
unsigned char *dstPtr = 0; |
|
699 |
int redOffs = 0; |
|
700 |
int greenOffs = 1; |
|
701 |
int blueOffs = 2; |
|
702 |
int alphaOffs = 3; |
|
703 |
||
704 |
if (__INST(photometric) == @symbol(argb)) { |
|
705 |
redOffs = 1; greenOffs = 2; blueOffs = 3; alphaOffs = 0; |
|
706 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
707 |
|
7122 | 708 |
if (__isByteArrayLike(bytes)) { |
709 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
|
710 |
} else { |
|
711 |
if (__isExternalBytesLike(bytes)) { |
|
712 |
srcPtr = __externalBytesAddress(bytes); |
|
713 |
} |
|
714 |
} |
|
715 |
if (__isByteArray(imageBits)) { |
|
716 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
717 |
} else { |
|
718 |
if (__isExternalBytesLike(imageBits)) { |
|
719 |
dstPtr = __externalBytesAddress(imageBits); |
|
720 |
} |
|
721 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
722 |
|
7122 | 723 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
724 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
725 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
726 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
727 |
&& srcPtr |
|
728 |
&& dstPtr) { |
|
729 |
int rShRed = __intVal(rightShiftR), |
|
730 |
rShGreen = __intVal(rightShiftG), |
|
731 |
rShBlue = __intVal(rightShiftB), |
|
732 |
lShRed = __intVal(shiftRed), |
|
733 |
lShGreen = __intVal(shiftGreen), |
|
734 |
lShBlue = __intVal(shiftBlue); |
|
735 |
int x, y, w; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
736 |
|
7122 | 737 |
w = __intVal(__INST(width)); |
738 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
739 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
740 |
for (x=w; x > 0; x--) { |
|
741 |
unsigned v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
742 |
|
7122 | 743 |
v = srcPtr[redOffs] << lShRed; |
744 |
v |= (srcPtr[greenOffs] << lShGreen); |
|
745 |
v |= (srcPtr[blueOffs] << lShBlue); |
|
746 |
dstPtr[0] = v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
747 |
|
7122 | 748 |
dstPtr += 1; |
749 |
srcPtr += 4; |
|
750 |
} |
|
751 |
} |
|
752 |
} else { |
|
753 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
|
754 |
for (x=w; x > 0; x--) { |
|
755 |
unsigned r, g, b, v; |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
756 |
|
7122 | 757 |
r = srcPtr[redOffs] >> rShRed; |
758 |
g = srcPtr[greenOffs] >> rShGreen; |
|
759 |
b = srcPtr[blueOffs] >> rShBlue; |
|
760 |
v = r << lShRed; |
|
761 |
v |= (g << lShGreen); |
|
762 |
v |= (b << lShBlue); |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
763 |
|
7122 | 764 |
dstPtr[0] = v; |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
765 |
|
7122 | 766 |
dstPtr += 1; |
767 |
srcPtr += 4; |
|
768 |
} |
|
769 |
} |
|
770 |
} |
|
771 |
} |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
772 |
%}. |
7122 | 773 |
] |
774 |
]. |
|
775 |
] |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
776 |
]. |
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 |
imageBits isNil ifTrue:[ |
7122 | 779 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
780 |
usedDeviceBitsPerPixel errorPrintCR. |
|
781 |
^ self asMonochromeFormOn:aDevice |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
782 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
783 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
784 |
form := Form width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
785 |
form isNil ifTrue:[ |
7122 | 786 |
'Depth32Image [warning]: display bitmap creation failed' errorPrintCR. |
787 |
^ nil |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
788 |
]. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
789 |
form initGC. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
790 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
791 |
form |
7122 | 792 |
copyBitsFrom:imageBits |
793 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
794 |
depth:usedDeviceDepth |
|
795 |
padding:usedDevicePadding |
|
796 |
width:width height:height |
|
797 |
x:0 y:0 toX:0 y:0. |
|
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
798 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
799 |
^ form |
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 |
"Created: / 27-05-2007 / 16:54:19 / cg" |
4763 | 802 |
"Modified: / 29-05-2007 / 12:19:04 / cg" |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
803 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
804 |
|
6841 | 805 |
!Depth32Image methodsFor:'image manipulations'! |
806 |
||
807 |
negative |
|
808 |
|bytes index newImage newBytes nBytes r g b| |
|
809 |
||
810 |
photometric ~~ #rgb ifTrue:[ |
|
811 |
^ super negative. |
|
812 |
]. |
|
813 |
bytes := self bits. |
|
814 |
||
815 |
newImage := self copy. |
|
816 |
nBytes := bytes size. |
|
817 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
818 |
index := 1. |
|
819 |
[index < nBytes] whileTrue:[ |
|
820 |
r := bytes at:index. |
|
821 |
newBytes at:index put:(255-r). |
|
822 |
index := index + 1. |
|
823 |
g := bytes at:index. |
|
824 |
newBytes at:index put:(255-g). |
|
825 |
index := index + 1. |
|
826 |
b := bytes at:index. |
|
827 |
newBytes at:index put:(255-b). |
|
828 |
index := index + 1. |
|
829 |
b := bytes at:index. |
|
830 |
newBytes at:index put:b. |
|
831 |
index := index + 1. |
|
832 |
]. |
|
833 |
^ newImage |
|
834 |
! ! |
|
835 |
||
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
836 |
!Depth32Image methodsFor:'initialization'! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
837 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
838 |
initialize |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
839 |
super initialize. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
840 |
samplesPerPixel := 4. |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
841 |
bitsPerSample := #(8 8 8 8). |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
842 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
843 |
"Created: / 27-05-2007 / 14:09:16 / cg" |
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 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
846 |
!Depth32Image methodsFor:'magnification'! |
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 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
849 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
850 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
851 |
"magnify a single pixel row - can only magnify by integer factors" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
852 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
853 |
%{ |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
854 |
unsigned char *srcP, *dstP; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
855 |
int _mag; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
856 |
REGISTER int i; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
857 |
REGISTER unsigned char byte1, byte2, byte3, byte4; |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
858 |
int _pixels; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
859 |
OBJ w = __INST(width); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
860 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
861 |
if (__bothSmallInteger(srcStart, dstStart) |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
862 |
&& __bothSmallInteger(w, mX) |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
863 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
864 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
865 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
866 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
867 |
_pixels = __intVal(w); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
868 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
869 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
870 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
871 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
872 |
byte3 = *(srcP+2); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
873 |
byte4 = *(srcP+3); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
874 |
srcP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
875 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
876 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
877 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
878 |
*(dstP+2) = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
879 |
*(dstP+3) = byte4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
880 |
dstP += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
881 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
882 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
883 |
RETURN (self); |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
884 |
} |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
885 |
%}. |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
886 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
887 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5474
diff
changeset
|
888 |
into:dstBytes offset:dstStart factor:mX |
4761
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
889 |
|
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
890 |
"Created: / 28-05-2007 / 15:20:52 / cg" |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
891 |
! ! |
9672fbf6ad20
defaultPhotometric, magnification, conversion
Claus Gittinger <cg@exept.de>
parents:
3866
diff
changeset
|
892 |
|
1663 | 893 |
!Depth32Image methodsFor:'queries'! |
894 |
||
7122 | 895 |
alphaBitsOf:pixel |
896 |
"given a pixel-value, return the alpha component as byteValue (0..255)" |
|
897 |
||
898 |
photometric == #rgba ifTrue:[ |
|
899 |
"r,g,b,a" |
|
900 |
^ pixel bitAnd:16rFF. |
|
901 |
]. |
|
902 |
photometric == #argb ifTrue:[ |
|
903 |
"a,r,g,b" |
|
904 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
905 |
]. |
|
7167 | 906 |
photometric == #rgb ifTrue:[ |
907 |
^ 0 |
|
908 |
]. |
|
7122 | 909 |
self error:'unsupported photometric' |
910 |
! |
|
911 |
||
912 |
alphaComponentOf:pixel |
|
913 |
"given a pixel-value, return the alpha component in percent (0..100)" |
|
914 |
||
915 |
^ (self alphaBitsOf:pixel) * (100.0 / 255.0) |
|
916 |
! |
|
917 |
||
918 |
alphaMaskForPixelValue |
|
919 |
"return the mask used with translation from pixelValues to alphaBits" |
|
920 |
||
921 |
^ 16rFF |
|
922 |
! |
|
923 |
||
924 |
alphaShiftForPixelValue |
|
925 |
"return the shift amount used with translation from pixelValues to alphaBits" |
|
926 |
||
927 |
photometric == #rgba ifTrue:[ |
|
928 |
"r,g,b,a" |
|
929 |
^ 0 |
|
930 |
]. |
|
931 |
photometric == #argb ifTrue:[ |
|
932 |
"a,r,g,b" |
|
933 |
^ -24. |
|
934 |
]. |
|
935 |
self error:'unsupported photometric' |
|
936 |
! |
|
937 |
||
1663 | 938 |
bitsPerPixel |
939 |
"return the number of bits per pixel" |
|
940 |
||
941 |
^ 32 |
|
942 |
||
943 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
944 |
! |
|
945 |
||
946 |
bitsPerRow |
|
947 |
"return the number of bits in one scanline of the image" |
|
948 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
949 |
^ width * 32 |
1663 | 950 |
|
951 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
952 |
! |
|
953 |
||
6841 | 954 |
bitsPerSample |
955 |
"return the number of bits per sample. |
|
956 |
The return value is an array of bits-per-plane." |
|
957 |
||
958 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
|
959 |
^ #(8 8 8 8) |
|
960 |
! |
|
961 |
||
962 |
blueBitsOf:pixel |
|
963 |
"given a pixel-value, return the blue component as byteValue (0..255)" |
|
964 |
||
7185 | 965 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7122 | 966 |
"r,g,b,a" |
967 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
968 |
]. |
|
969 |
photometric == #argb ifTrue:[ |
|
970 |
"a,r,g,b" |
|
971 |
^ pixel bitAnd:16rFF. |
|
972 |
]. |
|
973 |
self error:'unsupported photometric' |
|
6841 | 974 |
! |
975 |
||
976 |
blueComponentOf:pixel |
|
977 |
"given a pixel-value, return the blue component in percent (0..100)" |
|
978 |
||
7122 | 979 |
^ (self blueBitsOf:pixel) * (100.0 / 255.0) |
6841 | 980 |
! |
981 |
||
982 |
blueMaskForPixelValue |
|
983 |
"return the mask used with translation from pixelValues to blueBits" |
|
984 |
||
985 |
^ 16rFF |
|
986 |
! |
|
987 |
||
988 |
blueShiftForPixelValue |
|
989 |
"return the shift amount used with translation from pixelValues to blueBits" |
|
990 |
||
7122 | 991 |
photometric == #rgba ifTrue:[ |
992 |
"r,g,b,a" |
|
993 |
^ -8 |
|
994 |
]. |
|
995 |
photometric == #argb ifTrue:[ |
|
996 |
"a,r,g,b" |
|
997 |
^ 0. |
|
998 |
]. |
|
999 |
self error:'unsupported photometric' |
|
6841 | 1000 |
! |
1001 |
||
1663 | 1002 |
bytesPerRow |
1003 |
"return the number of bytes in one scanline of the image" |
|
1004 |
||
1005 |
^ width * 4. |
|
1006 |
||
1007 |
"Created: 24.4.1997 / 19:00:28 / cg" |
|
5327 | 1008 |
! |
1009 |
||
6841 | 1010 |
greenBitsOf:pixel |
1011 |
"given a pixel-value, return the green component as byteValue (0..255)" |
|
1012 |
||
7185 | 1013 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7122 | 1014 |
"r,g,b,a" |
1015 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
1016 |
]. |
|
1017 |
photometric == #argb ifTrue:[ |
|
1018 |
"a,r,g,b" |
|
1019 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
1020 |
]. |
|
1021 |
self error:'unsupported photometric' |
|
6841 | 1022 |
! |
1023 |
||
1024 |
greenComponentOf:pixel |
|
1025 |
"given a pixel-value, return the green component in percent (0..100)" |
|
1026 |
||
7122 | 1027 |
^ (self greenBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1028 |
! |
1029 |
||
1030 |
greenMaskForPixelValue |
|
1031 |
"return the mask used with translation from pixelValues to redBits" |
|
1032 |
||
1033 |
^ 16rFF |
|
1034 |
! |
|
1035 |
||
1036 |
greenShiftForPixelValue |
|
1037 |
"return the shift amount used with translation from pixelValues to greenBits" |
|
1038 |
||
7122 | 1039 |
photometric == #rgba ifTrue:[ |
1040 |
"r,g,b,a" |
|
1041 |
^ -16 |
|
1042 |
]. |
|
1043 |
photometric == #argb ifTrue:[ |
|
1044 |
"a,r,g,b" |
|
1045 |
^ -8. |
|
1046 |
]. |
|
1047 |
self error:'unsupported photometric' |
|
6841 | 1048 |
! |
1049 |
||
5327 | 1050 |
hasAlphaChannel |
1051 |
^ true |
|
6841 | 1052 |
! |
1053 |
||
1054 |
redBitsOf:pixel |
|
1055 |
"given a pixel-value, return the red component as byteValue (0..255)" |
|
1056 |
||
7185 | 1057 |
((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
7122 | 1058 |
"r,g,b,a" |
1059 |
^ (pixel bitShift:-24) bitAnd:16rFF. |
|
1060 |
]. |
|
1061 |
photometric == #argb ifTrue:[ |
|
1062 |
"a,r,g,b" |
|
1063 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
1064 |
]. |
|
1065 |
self error:'unsupported photometric' |
|
6841 | 1066 |
! |
1067 |
||
1068 |
redComponentOf:pixel |
|
1069 |
"given a pixel-value, return the red component in percent (0..100)" |
|
1070 |
||
7122 | 1071 |
^ (self redBitsOf:pixel) * (100.0 / 255.0) |
6841 | 1072 |
! |
1073 |
||
1074 |
redMaskForPixelValue |
|
1075 |
"return the mask used with translation from pixelValues to redBits" |
|
1076 |
||
1077 |
^ 16rFF |
|
1078 |
! |
|
1079 |
||
1080 |
redShiftForPixelValue |
|
1081 |
"return the shift amount used with translation from pixelValues to redBits" |
|
1082 |
||
7122 | 1083 |
photometric == #rgba ifTrue:[ |
1084 |
"r,g,b,a" |
|
1085 |
^ -24 |
|
1086 |
]. |
|
1087 |
photometric == #argb ifTrue:[ |
|
1088 |
"a,r,g,b" |
|
1089 |
^ -16. |
|
1090 |
]. |
|
1091 |
self error:'unsupported photometric' |
|
6841 | 1092 |
! |
1093 |
||
1094 |
rgbFromValue:pixelValue |
|
1095 |
"given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB)." |
|
1096 |
||
1097 |
^ pixelValue rightShift:8 "lsb is alpha channel" |
|
1098 |
! |
|
1099 |
||
1100 |
samplesPerPixel |
|
1101 |
"return the number of samples per pixel in the image." |
|
1102 |
||
1103 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
|
1104 |
^ 4 |
|
1105 |
! |
|
1106 |
||
1107 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
|
1108 |
^ (((((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits) bitShift:8) bitOr:255 |
|
1663 | 1109 |
! ! |
1110 |
||
1111 |
!Depth32Image class methodsFor:'documentation'! |
|
1112 |
||
1113 |
version |
|
7122 | 1114 |
^ '$Header$' |
5474
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1115 |
! |
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1116 |
|
037b18c68ac9
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5327
diff
changeset
|
1117 |
version_CVS |
7122 | 1118 |
^ '$Header$' |
1663 | 1119 |
! ! |
6302 | 1120 |
|
7170
e5374bb05083
Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7167
diff
changeset
|
1121 |
|
e5374bb05083
Fixed bitsARGB32Into:startingAt:stride: to work with PNG image data.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
7167
diff
changeset
|
1122 |
Depth32Image initialize! |