125 Pixels start at x=0 , y=0 for upper left pixel, end at |
125 Pixels start at x=0 , y=0 for upper left pixel, end at |
126 x = width-1, y=height-1 for lower right pixel." |
126 x = width-1, y=height-1 for lower right pixel." |
127 |
127 |
128 |index "{ Class: SmallInteger }"| |
128 |index "{ Class: SmallInteger }"| |
129 |
129 |
130 ((photometric == #rgba) or:[photometric == #rgb]) ifTrue:[ |
130 (photometric == #rgb) ifTrue:[ |
131 index := 1 + (((width * y) + x) * 4). |
131 index := 1 + (((width * y) + x) * 4). |
132 bytes at:(index) put:(aColor redByte). |
132 bytes at:(index) put:(aColor redByte). |
133 bytes at:(index + 1) put:(aColor greenByte). |
133 bytes at:(index + 1) put:(aColor greenByte). |
134 bytes at:(index + 2) put:(aColor blueByte). |
134 bytes at:(index + 2) put:(aColor blueByte). |
135 bytes at:(index + 3) put:255. "alpha channel" |
135 bytes at:(index + 3) put:0. |
|
136 ^ self |
|
137 ]. |
|
138 (photometric == #rgba) ifTrue:[ |
|
139 index := 1 + (((width * y) + x) * 4). |
|
140 bytes at:(index) put:(aColor redByte). |
|
141 bytes at:(index + 1) put:(aColor greenByte). |
|
142 bytes at:(index + 2) put:(aColor blueByte). |
|
143 bytes at:(index + 3) put:(aColor alphaByte). "alpha channel" |
136 ^ self |
144 ^ self |
137 ]. |
145 ]. |
138 (photometric == #argb) ifTrue:[ |
146 (photometric == #argb) ifTrue:[ |
139 index := 1 + (((width * y) + x) * 4). |
147 index := 1 + (((width * y) + x) * 4). |
140 bytes at:(index) put:255. "alpha channel" |
148 bytes at:(index) put:255. "alpha channel" |
141 bytes at:(index + 1) put:(aColor redByte). |
149 bytes at:(index + 1) put:(aColor redByte). |
142 bytes at:(index + 2) put:(aColor greenByte). |
150 bytes at:(index + 2) put:(aColor greenByte). |
143 bytes at:(index + 3) put:(aColor blueByte). |
151 bytes at:(index + 3) put:(aColor blueByte). |
144 ^ self |
152 ^ self |
145 ]. |
153 ]. |
146 |
154 |
147 super colorAtX:x y:y put:aColor. |
155 super colorAtX:x y:y put:aColor. |
|
156 |
|
157 "Modified: / 21-02-2017 / 01:49:58 / cg" |
148 ! |
158 ! |
149 |
159 |
150 pixelAtX:x y:y |
160 pixelAtX:x y:y |
151 "retrieve a pixel at x/y; return a pixelValue. |
161 "retrieve a pixel at x/y; return a pixelValue. |
152 The interpretation of the returned value depends on the photometric |
162 The interpretation of the returned value depends on the photometric |
169 |
179 |
170 _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
180 _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*4; |
171 if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
181 if (((unsigned)(_idx+3)) < __byteArraySize(b)) { |
172 unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
182 unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
173 unsigned int _pix; |
183 unsigned int _pix; |
174 _pix = (((((pPix[0]<<8)+pPix[1])<<8)+pPix[2])<<8)+pPix[3]; |
184 unsigned int _r, _g, _b, _a; |
|
185 |
|
186 if (_INST(photometric) == @symbol(rgba)) { |
|
187 _r = pPix[0]; |
|
188 _g = pPix[1]; |
|
189 _b = pPix[2]; |
|
190 _a = pPix[3]; |
|
191 } else if (_INST(photometric) == @symbol(argb)) { |
|
192 _a = pPix[0]; |
|
193 _r = pPix[1]; |
|
194 _g = pPix[2]; |
|
195 _b = pPix[3]; |
|
196 } else { |
|
197 _r = pPix[0]; |
|
198 _g = pPix[1]; |
|
199 _b = pPix[2]; |
|
200 _a = 0; |
|
201 } |
|
202 _pix = (((((_a<<8)+_r)<<8)+_g)<<8)+_b; |
175 #if __POINTER_SIZE__ == 8 |
203 #if __POINTER_SIZE__ == 8 |
176 RETURN( __MKSMALLINT(_pix) ); |
204 RETURN( __MKSMALLINT(_pix) ); |
177 #else |
205 #else |
178 RETURN( __MKUINT(_pix) ); |
206 RETURN( __MKUINT(_pix) ); |
179 #endif |
207 #endif |
183 pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
211 pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
184 |
212 |
185 pixelIndex := 1 + (((width * y) + x) * 4). |
213 pixelIndex := 1 + (((width * y) + x) * 4). |
186 |
214 |
187 "left pixel in high bits" |
215 "left pixel in high bits" |
188 ^ bytes unsignedInt32At:pixelIndex MSB:true. |
216 ^ bytes unsignedInt32At:pixelIndex MSB:false "true". |
189 |
217 |
190 "Created: 24.4.1997 / 19:00:28 / cg" |
218 "Created: / 24-04-1997 / 19:00:28 / cg" |
191 "Modified: 24.4.1997 / 23:11:05 / cg" |
219 "Modified: / 21-02-2017 / 01:54:28 / cg" |
192 ! |
220 ! |
193 |
221 |
194 pixelAtX:x y:y put:aPixelValue |
222 pixelAtX:x y:y put:aPixelValue |
195 "set the pixel at x/y to aPixelValue. |
223 "set the pixel at x/y to aPixelValue. |
196 The interpretation of the pixelValue depends on the photometric |
224 The interpretation of the pixelValue depends on the photometric |
202 |
230 |
203 pixelIndex := 1 + (((width * y) + x) * 4). |
231 pixelIndex := 1 + (((width * y) + x) * 4). |
204 bytes isNil ifTrue:[ |
232 bytes isNil ifTrue:[ |
205 self createPixelStore |
233 self createPixelStore |
206 ]. |
234 ]. |
207 bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:true |
235 "/ pixelValue is aarrggbb |
|
236 photometric == #rgba ifTrue:[ |
|
237 bytes at:pixelIndex put:((aPixelValue bitShift:-16) bitAnd:16rFF). |
|
238 bytes at:pixelIndex+1 put:((aPixelValue bitShift:-8) bitAnd:16rFF). |
|
239 bytes at:pixelIndex+2 put:((aPixelValue) bitAnd:16rFF). |
|
240 bytes at:pixelIndex+3 put:((aPixelValue bitShift:-24) bitAnd:16rFF). |
|
241 ^ self |
|
242 ]. |
|
243 photometric == #rgb ifTrue:[ |
|
244 bytes at:pixelIndex put:((aPixelValue bitShift:-16) bitAnd:16rFF). |
|
245 bytes at:pixelIndex+1 put:((aPixelValue bitShift:-8) bitAnd:16rFF). |
|
246 bytes at:pixelIndex+2 put:((aPixelValue) bitAnd:16rFF). |
|
247 bytes at:pixelIndex+3 put:0. |
|
248 ^ self |
|
249 ]. |
|
250 photometric == #argb ifTrue:[ |
|
251 bytes unsignedInt32At:pixelIndex put:aPixelValue MSB:false. "/ true |
|
252 ^ self |
|
253 ]. |
208 |
254 |
209 "Created: / 24-04-1997 / 19:00:28 / cg" |
255 "Created: / 24-04-1997 / 19:00:28 / cg" |
210 "Modified: / 06-06-2007 / 12:20:57 / cg" |
256 "Modified: / 21-02-2017 / 01:58:42 / cg" |
211 ! |
257 ! |
212 |
258 |
213 rowAt:y putAll:pixelArray startingAt:startIndex |
259 rowAt:y putAll:pixelArray startingAt:startIndex |
214 "store a single rows bits from bits in the pixelArray argument; |
260 "store a single rows bits from bits in the pixelArray argument; |
215 Return the pixelArray. |
261 Return the pixelArray. |
222 dstIdx := (y * self bytesPerRow) + 1. |
268 dstIdx := (y * self bytesPerRow) + 1. |
223 w := width - 1. |
269 w := width - 1. |
224 |
270 |
225 0 to:w do:[:col | |
271 0 to:w do:[:col | |
226 pixel := pixelArray at:(startIndex + col). |
272 pixel := pixelArray at:(startIndex + col). |
227 bytes unsignedInt32At:dstIdx put:pixel MSB:true. |
273 bytes unsignedInt32At:dstIdx put:pixel MSB:false. "/ true. |
228 dstIdx := dstIdx + 4. |
274 dstIdx := dstIdx + 4. |
229 ]. |
275 ]. |
230 ^ pixelArray |
276 ^ pixelArray |
|
277 |
|
278 "Modified: / 21-02-2017 / 01:47:58 / cg" |
231 ! ! |
279 ! ! |
232 |
280 |
233 !Depth32Image methodsFor:'converting rgb images'! |
281 !Depth32Image methodsFor:'converting rgb images'! |
234 |
282 |
235 computeAlphaValuesFromMask:aMaskImage |
283 computeAlphaValuesFromMask:aMaskImage |