author | Claus Gittinger <cg@exept.de> |
Sun, 04 Aug 2019 22:18:05 +0200 | |
changeset 8758 | c8ffbed1d428 |
parent 8743 | 140d90ad0ec1 |
child 8967 | 0a8df312e486 |
permissions | -rw-r--r-- |
8440 | 1 |
"{ Encoding: utf8 }" |
2 |
||
3 | 3 |
" |
4 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 5 |
All Rights Reserved |
3 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3263 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
6795 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Image subclass:#Depth24Image |
579 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Graphics-Images' |
|
1 | 23 |
! |
24 |
||
1167 | 25 |
!Depth24Image class methodsFor:'documentation'! |
46 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 30 |
All Rights Reserved |
3 | 31 |
|
46 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
3 | 40 |
|
46 | 41 |
documentation |
42 |
" |
|
43 |
this class represents true-color (24 bit / pixel) images. |
|
44 |
It mainly consists of methods already implemented in Image, |
|
45 |
reimplemented here for more performance. |
|
611 | 46 |
|
798 | 47 |
Only the #rgb format is supported here. |
48 |
||
8325 | 49 |
with #rgb, pixels are internally stored byte-wise in rgb order |
50 |
(i.e. r at low byte, b at high byte). |
|
51 |
||
52 |
When reading pixel values, these are returned as rrggbb, |
|
53 |
both on LSB and on MSB machines. |
|
54 |
(red in high bits of the returned 24bit integer) |
|
55 |
Thus, pixelValues and rgbValues are identical, simulating MSB on all |
|
56 |
architectures (this should be transparent, if you use the rgbValueAt |
|
57 |
accessors; however, some old code uses pixelValueAt:, assuming that the |
|
58 |
returned pixel value is rrggbb (which it would not be without this hack). |
|
59 |
||
611 | 60 |
[author:] |
8325 | 61 |
Claus Gittinger |
611 | 62 |
|
63 |
[see also:] |
|
8325 | 64 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image |
65 |
ImageReader |
|
46 | 66 |
" |
67 |
! ! |
|
3 | 68 |
|
1167 | 69 |
!Depth24Image class methodsFor:'queries'! |
89 | 70 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
71 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
72 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
73 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
74 |
^ #rgb |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
75 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
76 |
"Created: 10.6.1996 / 18:08:25 / cg" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
77 |
! |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
78 |
|
89 | 79 |
imageDepth |
579 | 80 |
"return the depth of images represented by instances of |
81 |
this class - here we return 24" |
|
82 |
||
89 | 83 |
^ 24 |
579 | 84 |
|
85 |
"Modified: 20.4.1996 / 23:39:50 / cg" |
|
89 | 86 |
! ! |
87 |
||
3263 | 88 |
!Depth24Image methodsFor:'accessing-pixels'! |
1 | 89 |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
90 |
colorAtX:x y:y |
1 | 91 |
"retrieve a pixel at x/y; return a color. |
7538 | 92 |
Pixels start at x=0 , y=0 for upper left pixel, |
7125 | 93 |
end at x = width-1, y=height-1 for lower right pixel" |
1 | 94 |
|
7550 | 95 |
|rgbVal| |
96 |
||
8325 | 97 |
rgbVal := self rgbValueAtX:x y:y. |
98 |
^ Color rgbValue:rgbVal. |
|
1 | 99 |
! |
100 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
101 |
colorAtX:x y:y put:aColor |
89 | 102 |
"set the pixel at x/y to aColor. |
103 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
104 |
x = width-1, y=height-1 for lower right pixel." |
|
105 |
||
8325 | 106 |
self rgbValueAtX:x y:y put:(aColor rgbValue). |
8155 | 107 |
|
108 |
"Created: / 24-04-1997 / 17:32:59 / cg" |
|
109 |
"Modified (format): / 31-08-2017 / 12:01:01 / cg" |
|
89 | 110 |
! |
111 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
112 |
pixelAtX:x y:y |
8325 | 113 |
"retrieve a pixel at x/y; |
114 |
return a pixel value (0..16rFFFFFF) which is 24 bits RGB. |
|
115 |
In theory, the interpretation of the pixel value depends on the photometric, |
|
116 |
however as the only one supported here is #rgb, the returned value |
|
117 |
is always rrggbb (with r in high bits, b in low 8 bits). |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
118 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
8325 | 119 |
x = width-1, y=height-1 for lower right pixel." |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
120 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
121 |
|index "{ Class: SmallInteger }" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
122 |
rVal "{ Class: SmallInteger }" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
123 |
gVal "{ Class: SmallInteger }" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
124 |
bVal "{ Class: SmallInteger }"| |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
125 |
|
7273 | 126 |
%{ /* NOCONTEXT */ |
127 |
OBJ b = __INST(bytes); |
|
128 |
OBJ w = __INST(width); |
|
129 |
||
130 |
if (__isByteArrayLike(b) |
|
131 |
&& __bothSmallInteger(x, y) |
|
132 |
&& __isSmallInteger(w) |
|
133 |
&& (__INST(pixelFunction)==nil) ) { |
|
8325 | 134 |
int _idx; |
135 |
||
136 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*3; |
|
137 |
if (((unsigned)(_idx+2)) < __byteArraySize(b)) { |
|
138 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
139 |
unsigned int _pix; |
|
140 |
_pix = (pPix[0]<<16) + (pPix[1] << 8) + pPix[2]; |
|
141 |
RETURN( __MKSMALLINT(_pix) ); |
|
142 |
} |
|
7273 | 143 |
} |
144 |
%}. |
|
6301 | 145 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
146 |
||
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
147 |
index := 1 + (((width * y) + x) * 3). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
148 |
rVal := bytes at:(index). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
149 |
gVal := bytes at:(index + 1). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
150 |
bVal := bytes at:(index + 2). |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
151 |
^ (((rVal bitShift:8) bitOr:gVal) bitShift:8) bitOr:bVal |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
152 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
153 |
"Created: 24.4.1997 / 16:06:34 / cg" |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
154 |
! |
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
155 |
|
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
156 |
pixelAtX:x y:y put:aPixelValue |
8325 | 157 |
"set a pixel at x/y to aPixelValue, (0..16rFFFFFF) which is 24 bits RGB. |
158 |
In theory, the interpretation of the pixel value depends on the photometric, |
|
159 |
however as the only one supported here is #rgb, the expected value |
|
160 |
is always rrggbb (with r in high bits, b in low 8 bits). |
|
1 | 161 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
162 |
x = width-1, y=height-1 for lower right pixel" |
|
163 |
||
164 |
|index "{ Class: SmallInteger }" |
|
7512 | 165 |
val "{ Class: SmallInteger }"| |
166 |
||
167 |
%{ /* NOCONTEXT */ |
|
168 |
OBJ b = __INST(bytes); |
|
169 |
OBJ w = __INST(width); |
|
170 |
||
171 |
if (__isByteArrayLike(b) |
|
172 |
&& __bothSmallInteger(x, y) |
|
173 |
&& __bothSmallInteger(w, aPixelValue) |
|
174 |
&& (__INST(pixelFunction)==nil) ) { |
|
8197 | 175 |
int _idx; |
176 |
||
177 |
_idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*3; |
|
178 |
if (((unsigned)(_idx+2)) < __byteArraySize(b)) { |
|
179 |
unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]); |
|
180 |
unsigned int _pix = __intVal(aPixelValue); |
|
8325 | 181 |
pPix[0] = (_pix>>16) & 0xFF; // r |
182 |
pPix[1] = (_pix>>8) & 0xFF; // g |
|
183 |
pPix[2] = (_pix) & 0xFF; // b |
|
8197 | 184 |
RETURN( self ); |
185 |
} |
|
7512 | 186 |
} |
187 |
%}. |
|
8197 | 188 |
bytes isNil ifTrue:[ self createPixelStore ]. |
189 |
||
1 | 190 |
index := 1 + (((width * y) + x) * 3). |
191 |
val := aPixelValue. |
|
192 |
bytes at:(index + 2) put:(val bitAnd:16rFF). |
|
193 |
val := val bitShift:-8. |
|
194 |
bytes at:(index + 1) put:(val bitAnd:16rFF). |
|
195 |
val := val bitShift:-8. |
|
196 |
bytes at:(index) put:val. |
|
197 |
! |
|
198 |
||
4118 | 199 |
rgbValueAtX:x y:y |
8121 | 200 |
"retrieve a pixel's rgb value at x/y; |
201 |
return a 24bit rgbValue (rrggbb, red is MSB). |
|
202 |
Pixels start at 0@0 for the upper left pixel, |
|
203 |
and end at (width-1)@(height-1) for the lower right pixel." |
|
4118 | 204 |
|
8325 | 205 |
photometric == #rgb ifTrue:[ |
206 |
^ self pixelAtX:x y:y |
|
8170 | 207 |
]. |
208 |
^ super rgbValueAtX:x y:y |
|
209 |
||
210 |
"Modified: / 10-09-2017 / 16:21:25 / cg" |
|
211 |
! |
|
212 |
||
8325 | 213 |
rgbValueAtX:x y:y put:rgbValue |
8170 | 214 |
"store a pixel's rgb value at x/y; |
215 |
return a 24bit rgbValue (rrggbb, red is MSB). |
|
216 |
Pixels start at 0@0 for the upper left pixel, |
|
217 |
and end at (width-1)@(height-1) for the lower right pixel." |
|
218 |
||
8325 | 219 |
photometric == #rgb ifTrue:[ |
220 |
self pixelAtX:x y:y put:rgbValue |
|
221 |
] ifFalse:[ |
|
222 |
super rgbValueAtX:x y:y put:rgbValue |
|
8170 | 223 |
]. |
224 |
||
225 |
"Created: / 10-09-2017 / 16:21:50 / cg" |
|
4118 | 226 |
! |
227 |
||
3872 | 228 |
rowAt:y putAll:pixelArray startingAt:startIndex |
8170 | 229 |
"store a single row's bits from bits in the pixelArray argument; |
8325 | 230 |
The interpretation of the pixel values depends on the photometric. |
3872 | 231 |
Return the pixelArray. |
232 |
Notice: row coordinate starts at 0." |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
233 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
234 |
|bytes dstIdx pixel| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
235 |
|
8325 | 236 |
photometric == #rgb ifTrue:[ |
237 |
bytes := self bits. |
|
238 |
dstIdx := (y * self bytesPerRow) + 1. |
|
239 |
0 to:width-1 do:[:col | |
|
240 |
pixel := pixelArray at:(startIndex + col). |
|
241 |
"/ msbFirst |
|
242 |
bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF). |
|
243 |
bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF). |
|
244 |
bytes at:dstIdx+2 put:(pixel bitAnd:16rFF). |
|
245 |
dstIdx := dstIdx + 3. |
|
246 |
]. |
|
247 |
^ self |
|
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
248 |
]. |
8325 | 249 |
super rowAt:y putAll:pixelArray startingAt:startIndex. |
1657
f3d8ceac748a
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
1629
diff
changeset
|
250 |
|
8170 | 251 |
"Created: / 24-04-1997 / 15:50:27 / cg" |
252 |
"Modified (comment): / 10-09-2017 / 16:22:39 / cg" |
|
1 | 253 |
! ! |
254 |
||
255 |
!Depth24Image methodsFor:'converting rgb images'! |
|
256 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
257 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
258 |
"return a grey form from the receiver. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
259 |
Redefined to use special code when converting to 8-bit |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
260 |
greyScale displays." |
1 | 261 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
262 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8098 | 263 |
aDevice depth == 8 ifTrue:[ |
264 |
^ self |
|
265 |
makeDeviceGrayPixmapOn:aDevice depth:aDevice depth |
|
266 |
fromArray:(self threshold8BitGrayBits) |
|
267 |
]. |
|
1 | 268 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
269 |
^ super asGrayFormOn:aDevice |
1 | 270 |
|
8098 | 271 |
"Created: / 10-06-1996 / 19:00:45 / cg" |
272 |
"Modified: / 10-06-1996 / 20:10:19 / cg" |
|
273 |
"Modified (format): / 24-08-2017 / 15:18:31 / cg" |
|
1 | 274 |
! |
275 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
276 |
asThresholdGrayImageDepth:depth |
808 | 277 |
"return an 8-bit grey image from the rgb picture. |
278 |
Pixel values are reduced to a 0..255 grey level." |
|
1 | 279 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
280 |
depth == 8 ifTrue:[ |
8127 | 281 |
photometric == #rgb ifTrue:[ |
282 |
^ (Depth8Image |
|
283 |
width:width height:height fromArray:(self threshold8BitGrayBits)) |
|
284 |
photometric:#blackIs0 |
|
285 |
] |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
286 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
287 |
^ super asThresholdGrayImageDepth:depth |
808 | 288 |
|
289 |
" |
|
290 |
|i| |
|
291 |
||
292 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
293 |
(i asThresholdGrayImageDepth:8) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
294 |
(i asThresholdGrayImageDepth:4) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
295 |
(i asThresholdGrayImageDepth:2) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
296 |
(i asThresholdGrayImageDepth:1) inspect. |
808 | 297 |
" |
1 | 298 |
|
808 | 299 |
" |
300 |
|i| |
|
301 |
||
302 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
303 |
((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:2) inspect |
808 | 304 |
" |
305 |
||
306 |
" |
|
307 |
|i| |
|
1 | 308 |
|
808 | 309 |
i := Image fromFile:'bitmaps/granite.tiff'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
310 |
((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:4) inspect |
808 | 311 |
" |
312 |
||
313 |
" |
|
314 |
|i| |
|
315 |
||
316 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
317 |
(i asThresholdGrayImageDepth:8) asOrderedDitheredMonochromeImage inspect |
808 | 318 |
" |
319 |
||
8127 | 320 |
"Created: / 08-06-1996 / 13:58:46 / cg" |
321 |
"Modified: / 29-08-2017 / 22:28:55 / cg" |
|
1 | 322 |
! |
323 |
||
282 | 324 |
rgbImageAsDitheredPseudoFormOn:aDevice |
325 |
"return a dithered pseudocolor form from the rgb-picture. |
|
326 |
This method depends on fixColors being allocated (see Color>>getColors*)" |
|
327 |
||
1607 | 328 |
|ditherColors| |
329 |
||
330 |
(ditherColors := aDevice fixColors) notNil ifTrue:[ |
|
4719 | 331 |
^ self |
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
332 |
rgbImageAsDitheredPseudoFormOn:aDevice |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
333 |
colors:ditherColors |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
334 |
nRed:aDevice numFixRed |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
335 |
nGreen:aDevice numFixGreen |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
336 |
nBlue:aDevice numFixBlue |
1607 | 337 |
]. |
338 |
||
339 |
ditherColors := Set new. |
|
340 |
ditherColors addAll:(aDevice ditherColors). |
|
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
341 |
ditherColors addAll:(aDevice deviceColors). |
1607 | 342 |
ditherColors := ditherColors asArray. |
4719 | 343 |
^ self |
344 |
rgbImageAsDitheredPseudoFormOn:aDevice |
|
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
345 |
colors:ditherColors. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
346 |
|
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
347 |
"Modified: 22.4.1997 / 11:59:44 / cg" |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
348 |
! |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
349 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
350 |
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
351 |
"return a dithered 8-bit pseudocolor form from the rgb-picture, using |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
352 |
arbitrary fix colors in fixColors." |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
353 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
354 |
|pseudoBits f |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
355 |
h "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
356 |
w "{ Class: SmallInteger }" |
4778
799620f24088
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4760
diff
changeset
|
357 |
numFix "{Class: SmallInteger }" deviceDepth |
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
358 |
fixIds fixRed fixGreen fixBlue failed cache idsUsed usedColors |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
359 |
fixColorArray| |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
360 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
361 |
numFix := fixColors size. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
362 |
numFix == 256 ifTrue:[ |
7753 | 363 |
"/ algorithm below only handles 255 colors. |
364 |
numFix := 255. |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
365 |
]. |
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
366 |
|
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
367 |
fixColorArray := fixColors asArray. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
368 |
fixIds := (fixColorArray collect:[:clr | clr colorId]) asByteArray. |
1607 | 369 |
|
2773
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
370 |
fixRed := (fixColorArray collect:[:clr | clr redByte]) asByteArray. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
371 |
fixGreen := (fixColorArray collect:[:clr | clr greenByte]) asByteArray. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
372 |
fixBlue := (fixColorArray collect:[:clr | clr blueByte]) asByteArray. |
8aefa2576a50
a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents:
2535
diff
changeset
|
373 |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
374 |
cache := ByteArray new:(1 bitShift:14). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
375 |
cache atAllPut:16rFF. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
376 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
377 |
deviceDepth := aDevice depth. |
2529
637a5979a3d0
use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
378 |
deviceDepth == 8 ifFalse:[ |
7753 | 379 |
(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[ |
380 |
^ nil |
|
381 |
] |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
382 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
383 |
|
1607 | 384 |
idsUsed := ByteArray new:(fixIds size). |
385 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
386 |
'Depth24Image [info]: dithering ...' infoPrintCR. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
387 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
388 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
389 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
390 |
h := height. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
391 |
w := width. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
392 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
393 |
%{ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
394 |
int __x, __y, __numFix; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
395 |
int __eR, __eG, __eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
396 |
unsigned char *srcP, *dstP; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
397 |
int pix; |
1607 | 398 |
unsigned char *idP, *usedIdP, *redP, *greenP, *blueP, *cacheP; |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
399 |
int __w = __intVal(w); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
400 |
|
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
401 |
if (__isByteArrayLike(__INST(bytes)) |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
402 |
&& __isSmallInteger(numFix) |
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
403 |
&& __isByteArrayLike(pseudoBits) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
404 |
&& __isByteArrayLike(cache) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
405 |
&& __isByteArrayLike(fixIds) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
406 |
&& __isByteArrayLike(idsUsed) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
407 |
&& __isByteArrayLike(fixRed) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
408 |
&& __isByteArrayLike(fixGreen) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
409 |
&& __isByteArrayLike(fixBlue) ) { |
7753 | 410 |
failed = false; |
411 |
||
412 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
413 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
414 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
415 |
usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element; |
|
416 |
redP = __ByteArrayInstPtr(fixRed)->ba_element; |
|
417 |
greenP = __ByteArrayInstPtr(fixGreen)->ba_element; |
|
418 |
blueP = __ByteArrayInstPtr(fixBlue)->ba_element; |
|
419 |
cacheP = __ByteArrayInstPtr(cache)->ba_element; |
|
420 |
__numFix = __intVal(numFix); |
|
421 |
||
422 |
for (__y=__intVal(h); __y>0; __y--) { |
|
423 |
__eR = __eG = __eB = 0; |
|
424 |
for (__x=__w; __x>0; __x--) { |
|
425 |
int cacheIdx, clrIdx; |
|
426 |
int __wantR, __wantG, __wantB; |
|
427 |
||
428 |
__wantR = srcP[0] + __eR; |
|
429 |
if (__wantR > 255) __wantR = 255; |
|
430 |
else if (__wantR < 0) __wantR = 0; |
|
431 |
||
432 |
__wantG = srcP[1] + __eG; |
|
433 |
if (__wantG > 255) __wantG = 255; |
|
434 |
else if (__wantG < 0) __wantG = 0; |
|
435 |
||
436 |
__wantB = srcP[2] + __eB; |
|
437 |
if (__wantB > 255) __wantB = 255; |
|
438 |
else if (__wantB < 0) __wantB = 0; |
|
439 |
||
440 |
/* |
|
441 |
* compute cache index |
|
442 |
*/ |
|
443 |
cacheIdx = ((__wantR & 0xF8) >> 3); |
|
444 |
cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3); |
|
445 |
cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4); |
|
446 |
||
447 |
clrIdx = cacheP[cacheIdx]; |
|
448 |
if (clrIdx == 0xFF) { /* invalid slot */ |
|
449 |
unsigned minErr, minIdx; |
|
450 |
int i; |
|
451 |
||
452 |
/* |
|
453 |
* must search ... |
|
454 |
*/ |
|
455 |
minErr = 0x7FFFFFF; minIdx = 0; |
|
456 |
for (i=0; i<__numFix; i++) { |
|
457 |
unsigned cR, cG, cB, e; |
|
458 |
int eR, eG, eB; |
|
459 |
||
460 |
cR = redP[i]; cG = greenP[i]; cB = blueP[i]; |
|
461 |
eR = cR - __wantR; |
|
462 |
if (eR < 0) eR = -eR; |
|
463 |
||
464 |
eG = cG - __wantG; |
|
465 |
if (eG < 0) eG = -eG; |
|
466 |
||
467 |
eB = cB - __wantB; |
|
468 |
if (eB < 0) eB = -eB; |
|
469 |
||
470 |
e = eR + eG + eB; |
|
471 |
if (e < minErr) { |
|
472 |
minErr = e; |
|
473 |
minIdx = i; |
|
474 |
if (e < 7) { |
|
475 |
break; |
|
476 |
} |
|
477 |
} |
|
478 |
} |
|
479 |
||
480 |
/* |
|
481 |
* minIdx is now index into fixColors |
|
482 |
*/ |
|
483 |
cacheP[cacheIdx] = clrIdx = minIdx; |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
484 |
/* |
4721 | 485 |
console_fprintf(stderr, "want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]); |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
486 |
*/ |
7753 | 487 |
} |
488 |
||
489 |
/* |
|
490 |
* store the corresponding dither colorId |
|
491 |
*/ |
|
492 |
*dstP++ = idP[clrIdx]; |
|
493 |
usedIdP[clrIdx] = 1; |
|
494 |
||
495 |
srcP += 3; |
|
496 |
||
497 |
/* |
|
498 |
* the new error: |
|
499 |
*/ |
|
500 |
__eR = __wantR - redP[clrIdx]; |
|
501 |
__eG = __wantG - greenP[clrIdx]; |
|
502 |
__eB = __wantB - blueP[clrIdx]; |
|
503 |
} |
|
504 |
} |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
505 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
506 |
%}. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
507 |
failed ifTrue:[ |
7753 | 508 |
self primitiveFailed. |
509 |
^ nil |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
510 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
511 |
|
1607 | 512 |
"/ not all colors may be really in use ... |
513 |
usedColors := fixColors copy. |
|
514 |
idsUsed keysAndValuesDo:[:idx :flag | |
|
7753 | 515 |
flag == 0 ifTrue:[ |
516 |
usedColors at:idx put:nil |
|
517 |
] |
|
1607 | 518 |
]. |
519 |
||
7495 | 520 |
f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
521 |
f isNil ifTrue:[^ nil]. |
1607 | 522 |
f colorMap:usedColors. |
4719 | 523 |
aDevice |
7753 | 524 |
drawBits:pseudoBits |
525 |
bitsPerPixel:8 |
|
526 |
depth:aDevice depth |
|
527 |
padding:8 |
|
528 |
width:width height:height |
|
529 |
x:0 y:0 |
|
530 |
into:(f id) |
|
531 |
x:0 y:0 |
|
532 |
width:width height:height |
|
533 |
with:(f initGC). |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
534 |
^ f |
282 | 535 |
! |
536 |
||
537 |
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
538 |
"return a dithered pseudocolor form from the rgb-picture, |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
539 |
using colors from a colorCube for dithering." |
282 | 540 |
|
541 |
|pseudoBits f |
|
542 |
h "{ Class: SmallInteger }" |
|
543 |
w "{ Class: SmallInteger }" |
|
544 |
"/ eR "{Class: SmallInteger }" |
|
545 |
"/ eG "{Class: SmallInteger }" |
|
546 |
"/ eB "{Class: SmallInteger }" |
|
547 |
"/ wantR "{Class: SmallInteger }" |
|
548 |
"/ wantG "{Class: SmallInteger }" |
|
549 |
"/ wantB "{Class: SmallInteger }" |
|
550 |
fixR "{Class: SmallInteger }" |
|
551 |
fixG "{Class: SmallInteger }" |
|
552 |
fixB "{Class: SmallInteger }" |
|
2529
637a5979a3d0
use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
553 |
deviceDepth |
1607 | 554 |
fixIds idsUsed failed usedColors| |
282 | 555 |
|
556 |
fixR := nRed. |
|
557 |
fixR == 0 ifTrue:[ ^ nil]. |
|
558 |
fixG := nGreen. |
|
559 |
fixG == 0 ifTrue:[ ^ nil]. |
|
560 |
fixB := nBlue. |
|
561 |
fixB == 0 ifTrue:[ ^ nil]. |
|
562 |
"/ simple check |
|
563 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
7753 | 564 |
self error:'invalid color array passed'. |
565 |
^ nil |
|
282 | 566 |
]. |
567 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
1607 | 568 |
idsUsed := ByteArray new:(fixIds size). |
282 | 569 |
|
570 |
deviceDepth := aDevice depth. |
|
2529
637a5979a3d0
use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents:
2401
diff
changeset
|
571 |
deviceDepth == 8 ifFalse:[ |
7753 | 572 |
(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[ |
573 |
^ nil |
|
574 |
] |
|
282 | 575 |
]. |
576 |
||
1167 | 577 |
'Depth24Image [info]: dithering ...' infoPrintCR. |
282 | 578 |
|
579 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
580 |
||
581 |
h := height. |
|
582 |
w := width. |
|
583 |
||
584 |
%{ |
|
585 |
int __x, __y; |
|
586 |
int __eR, __eG, __eB; |
|
587 |
int __wantR, __wantG, __wantB; |
|
588 |
unsigned char *srcP, *dstP; |
|
589 |
unsigned char *redP, *greenP, *blueP; |
|
590 |
int pix; |
|
591 |
unsigned char *idP; |
|
1607 | 592 |
unsigned char *usedIdP; |
282 | 593 |
int __fR, __fG, __fB; |
594 |
int iR, iG, iB; |
|
595 |
int idx; |
|
858 | 596 |
int __w = __intVal(w); |
1817 | 597 |
int leftToRight; |
282 | 598 |
|
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
599 |
if (__isByteArrayLike(__INST(bytes)) |
282 | 600 |
&& __isByteArray(pseudoBits) |
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
601 |
&& __isByteArrayLike(fixIds) |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
602 |
&& __isByteArrayLike(idsUsed) |
282 | 603 |
&& __bothSmallInteger(fixR, fixG) |
604 |
&& __isSmallInteger(fixB)) { |
|
7753 | 605 |
failed = false; |
606 |
||
607 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
608 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
609 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
610 |
usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element; |
|
611 |
__fR = __intVal(fixR)-1; |
|
612 |
__fG = __intVal(fixG)-1; |
|
613 |
__fB = __intVal(fixB)-1; |
|
614 |
||
615 |
__eR = __eG = __eB = 0; |
|
616 |
||
617 |
leftToRight = 1; |
|
618 |
for (__y=__intVal(h); __y>0; __y--) { |
|
619 |
if (leftToRight) { |
|
620 |
for (__x=__w; __x>0; __x--) { |
|
621 |
int __want; |
|
622 |
||
623 |
/* |
|
624 |
* wR, wG and wB is the wanted r/g/b value; |
|
625 |
* compute the index into the dId table .. |
|
626 |
* values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1 |
|
627 |
* |
|
628 |
* bad kludge: knows how to index into FixColor table |
|
629 |
*/ |
|
630 |
__wantR = __want = srcP[0] + __eR; |
|
631 |
||
632 |
if (__want > 255) __want = 255; |
|
633 |
else if (__want < 0) __want = 0; |
|
634 |
||
635 |
iR = __want * __fR / 128; |
|
636 |
iR = (iR / 2) + (iR & 1); |
|
637 |
||
638 |
__wantG = __want = srcP[1] + __eG; |
|
639 |
if (__want > 255) __want = 255; |
|
640 |
else if (__want < 0) __want = 0; |
|
641 |
||
642 |
iG = __want * __fG / 128; |
|
643 |
iG = (iG / 2) + (iG & 1); |
|
644 |
||
645 |
__wantB = __want = srcP[2] + __eB; |
|
646 |
if (__want > 255) __want = 255; |
|
647 |
else if (__want < 0) __want = 0; |
|
648 |
||
649 |
iB = __want * __fB / 128; |
|
650 |
iB = (iB / 2) + (iB & 1); |
|
651 |
||
652 |
idx = iR * (__fG+1); |
|
653 |
idx = (idx + iG) * (__fB+1); |
|
654 |
idx = idx + iB; |
|
655 |
||
656 |
/* |
|
657 |
* store the corresponding dither colorId |
|
658 |
*/ |
|
659 |
*dstP++ = idP[idx]; |
|
660 |
usedIdP[idx] = 1; |
|
661 |
||
662 |
srcP += 3; |
|
663 |
||
664 |
/* |
|
665 |
* the new error: |
|
666 |
*/ |
|
667 |
__eR = __wantR - (iR * 256 / __fR); |
|
668 |
__eG = __wantG - (iG * 256 / __fG); |
|
669 |
__eB = __wantB - (iB * 256 / __fB); |
|
670 |
} |
|
671 |
leftToRight = 0; |
|
672 |
} else { |
|
673 |
srcP += (__w*3); |
|
674 |
dstP += __w; |
|
675 |
for (__x=__w; __x>0; __x--) { |
|
676 |
int __want; |
|
677 |
||
678 |
/* |
|
679 |
* wR, wG and wB is the wanted r/g/b value; |
|
680 |
* compute the index into the dId table .. |
|
681 |
* values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1 |
|
682 |
* |
|
683 |
* bad kludge: knows how to index into FixColor table |
|
684 |
*/ |
|
685 |
srcP -= 3; |
|
686 |
__wantR = __want = srcP[0] + __eR; |
|
687 |
||
688 |
if (__want > 255) __want = 255; |
|
689 |
else if (__want < 0) __want = 0; |
|
690 |
||
691 |
iR = __want * __fR / 128; |
|
692 |
iR = (iR / 2) + (iR & 1); |
|
693 |
||
694 |
__wantG = __want = srcP[1] + __eG; |
|
695 |
if (__want > 255) __want = 255; |
|
696 |
else if (__want < 0) __want = 0; |
|
697 |
||
698 |
iG = __want * __fG / 128; |
|
699 |
iG = (iG / 2) + (iG & 1); |
|
700 |
||
701 |
__wantB = __want = srcP[2] + __eB; |
|
702 |
if (__want > 255) __want = 255; |
|
703 |
else if (__want < 0) __want = 0; |
|
704 |
||
705 |
iB = __want * __fB / 128; |
|
706 |
iB = (iB / 2) + (iB & 1); |
|
707 |
||
708 |
idx = iR * (__fG+1); |
|
709 |
idx = (idx + iG) * (__fB+1); |
|
710 |
idx = idx + iB; |
|
711 |
||
712 |
/* |
|
713 |
* store the corresponding dither colorId |
|
714 |
*/ |
|
715 |
*--dstP = idP[idx]; |
|
716 |
usedIdP[idx] = 1; |
|
717 |
||
718 |
/* |
|
719 |
* the new error: |
|
720 |
*/ |
|
721 |
__eR = __wantR - (iR * 256 / __fR); |
|
722 |
__eG = __wantG - (iG * 256 / __fG); |
|
723 |
__eB = __wantB - (iB * 256 / __fB); |
|
724 |
} |
|
725 |
srcP += (__w*3); |
|
726 |
dstP += __w; |
|
727 |
leftToRight = 1; |
|
728 |
} |
|
729 |
} |
|
282 | 730 |
} |
731 |
%}. |
|
732 |
failed ifTrue:[ |
|
7753 | 733 |
self primitiveFailed. |
734 |
^ nil |
|
282 | 735 |
|
736 |
"/ for non-C programmers: |
|
1218
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
737 |
"/ the above code is (roughly) equivalent to: |
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
738 |
"/ (but it is just as ugly looking as the above ;-) |
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
739 |
"/ |
282 | 740 |
"/ srcIndex := 1. |
741 |
"/ dstIndex := 1. |
|
742 |
"/ 1 to:h do:[:y | |
|
743 |
"/ eR := eG := eB := 0. |
|
744 |
"/ 1 to:w do:[:x | |
|
745 |
"/ |pixel "{ Class: SmallInteger }" |
|
4719 | 746 |
"/ clr |
282 | 747 |
"/ idx "{ Class: SmallInteger }" |
748 |
"/ iR "{ Class: SmallInteger }" |
|
749 |
"/ iG "{ Class: SmallInteger }" |
|
750 |
"/ iB "{ Class: SmallInteger }" |
|
751 |
"/ wR "{ Class: SmallInteger }" |
|
752 |
"/ wG "{ Class: SmallInteger }" |
|
753 |
"/ wB "{ Class: SmallInteger }" | |
|
754 |
"/ |
|
755 |
"/ wantR := ((bytes at:srcIndex) + eR). srcIndex := srcIndex + 1. |
|
756 |
"/ wantG := ((bytes at:srcIndex) + eG). srcIndex := srcIndex + 1. |
|
757 |
"/ wantB := ((bytes at:srcIndex) + eB). srcIndex := srcIndex + 1. |
|
758 |
"/ wR := wantR. |
|
759 |
"/ wR > 255 ifTrue:[wR := 255] ifFalse:[wR < 0 ifTrue:[wR := 0]]. |
|
760 |
"/ wG := wantG. |
|
761 |
"/ wG > 255 ifTrue:[wG := 255] ifFalse:[wG < 0 ifTrue:[wG := 0]]. |
|
762 |
"/ wB := wantB. |
|
763 |
"/ wB > 255 ifTrue:[wB := 255] ifFalse:[wB < 0 ifTrue:[wB := 0]]. |
|
764 |
"/ |
|
765 |
"/ iR := wR * (fixR-1) // 128. |
|
766 |
"/ iR := (iR // 2) + (iR bitAnd:1). |
|
767 |
"/ iG := wG * (fixG-1) // 128. |
|
768 |
"/ iG := (iG // 2) + (iG bitAnd:1). |
|
769 |
"/ iB := wB * (fixB-1) // 128. |
|
770 |
"/ iB := (iB // 2) + (iB bitAnd:1). |
|
771 |
"/ idx := (iR * fixR + iG) * fixB + iB + 1. |
|
772 |
"/ |
|
773 |
"/ clr := fixColors at:idx. |
|
774 |
"/ |
|
775 |
"/ eR := wantR - (clr red * 2) asInteger. |
|
776 |
"/ eG := wantG - (clr green * 2) asInteger. |
|
777 |
"/ eB := wantB - (clr blue * 2) asInteger. |
|
778 |
"/ |
|
779 |
"/ pixel := clr colorId. |
|
780 |
"/ pseudoBits at:dstIndex put:pixel. |
|
781 |
"/ |
|
782 |
"/ dstIndex := dstIndex + 1 |
|
783 |
"/ ]. |
|
784 |
]. |
|
785 |
||
1607 | 786 |
"/ not all colors may be really in use ... |
787 |
usedColors := fixColors copy. |
|
788 |
idsUsed keysAndValuesDo:[:idx :flag | |
|
7753 | 789 |
flag == 0 ifTrue:[ |
790 |
usedColors at:idx put:nil |
|
791 |
] |
|
1607 | 792 |
]. |
793 |
||
7495 | 794 |
f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice. |
282 | 795 |
f isNil ifTrue:[^ nil]. |
1607 | 796 |
f colorMap:usedColors. |
4719 | 797 |
aDevice |
7753 | 798 |
drawBits:pseudoBits |
799 |
bitsPerPixel:8 |
|
800 |
depth:aDevice depth |
|
801 |
padding:8 |
|
802 |
width:width height:height |
|
803 |
x:0 y:0 |
|
804 |
into:(f id) |
|
805 |
x:0 y:0 |
|
806 |
width:width height:height |
|
807 |
with:(f initGC). |
|
282 | 808 |
^ f |
809 |
! |
|
810 |
||
1 | 811 |
rgbImageAsPseudoFormOn:aDevice |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
812 |
"return a pseudocolor form from the rgb-picture. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
813 |
If a colorCube is used, pass the work on to the cube-dither |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
814 |
code. Otherwise, allocate as many colors as possible, then |
4719 | 815 |
use those for dithering. |
1607 | 816 |
Could be improved, by searching for (& allocating) |
817 |
heavily used colors and/or min-max colors first." |
|
1 | 818 |
|
819 |
|pseudoBits f |
|
820 |
r "{ Class: SmallInteger }" |
|
821 |
g "{ Class: SmallInteger }" |
|
822 |
b "{ Class: SmallInteger }" |
|
823 |
srcIndex "{ Class: SmallInteger }" |
|
824 |
dstIndex "{ Class: SmallInteger }" |
|
825 |
rMask "{ Class: SmallInteger }" |
|
826 |
gMask "{ Class: SmallInteger }" |
|
827 |
bMask "{ Class: SmallInteger }" |
|
828 |
redArray greenArray blueArray |
|
829 |
dataSize "{ Class: SmallInteger }" |
|
830 |
nColors "{ Class: SmallInteger }" |
|
4778
799620f24088
Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents:
4760
diff
changeset
|
831 |
fit fitMap colors color fast |
1 | 832 |
colorIndex "{ Class: SmallInteger }" |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
833 |
depth nColorCells deep nColorsNeeded bytes| |
89 | 834 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
835 |
aDevice fixColors notNil ifTrue:[ |
7753 | 836 |
"/ no need to look for used colors - dithering anyway ... |
837 |
||
838 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice. |
|
839 |
f notNil ifTrue:[^ f]. |
|
89 | 840 |
]. |
1 | 841 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
842 |
bytes := self bits. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
843 |
|
1 | 844 |
"find used colors; build color-tree" |
845 |
||
4719 | 846 |
fit := false. |
1 | 847 |
fitMap := false. |
848 |
depth := aDevice depth. |
|
849 |
nColorCells := aDevice ncells. |
|
850 |
||
89 | 851 |
deep := (depth > 8). |
852 |
||
1 | 853 |
rMask := 2r11111111. |
854 |
gMask := 2r11111111. |
|
855 |
bMask := 2r11111111. |
|
856 |
||
1167 | 857 |
'Depth24Image [info]: allocating colors ...' infoPrintCR. |
66 | 858 |
|
1 | 859 |
[fit] whileFalse:[ |
7753 | 860 |
[fitMap] whileFalse:[ |
861 |
srcIndex := 1. |
|
862 |
redArray := Array new:256. |
|
863 |
||
864 |
" |
|
865 |
find used colors, build [r][g][b] 3-dimensional array |
|
866 |
containing true for used colors |
|
867 |
" |
|
868 |
nColors := 0. |
|
869 |
srcIndex := 1. |
|
870 |
dataSize := bytes size. |
|
871 |
[(srcIndex < dataSize) |
|
872 |
and:[nColors <= nColorCells]] whileTrue:[ |
|
1 | 873 |
%{ |
7753 | 874 |
if (__isByteArrayLike(bytes)) { |
875 |
int sI = __intVal(srcIndex); |
|
876 |
unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element; |
|
877 |
||
878 |
r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1); |
|
879 |
g = __MKSMALLINT((cp[sI] & __intVal(gMask)) + 1); |
|
880 |
b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1); |
|
881 |
srcIndex = __MKSMALLINT(sI + 3); |
|
882 |
fast = true; |
|
883 |
} else { |
|
884 |
fast = false; |
|
885 |
} |
|
1 | 886 |
%} |
887 |
. |
|
7753 | 888 |
fast ifFalse:[ |
889 |
r := bytes at:srcIndex. |
|
890 |
r := (r bitAnd:rMask) + 1. |
|
891 |
srcIndex := srcIndex + 1. |
|
892 |
g := bytes at:srcIndex. |
|
893 |
g := (g bitAnd:gMask) + 1. |
|
894 |
srcIndex := srcIndex + 1. |
|
895 |
b := bytes at:srcIndex. |
|
896 |
b := (b bitAnd:bMask) + 1. |
|
897 |
srcIndex := srcIndex + 1 |
|
898 |
]. |
|
899 |
||
900 |
greenArray := redArray at:r. |
|
901 |
greenArray isNil ifTrue:[ |
|
902 |
greenArray := Array new:256. |
|
903 |
redArray at:r put:greenArray |
|
904 |
]. |
|
905 |
blueArray := greenArray at:g. |
|
906 |
blueArray isNil ifTrue:[ |
|
907 |
deep ifTrue:[blueArray := Array new:256] |
|
908 |
ifFalse:[blueArray := ByteArray new:256]. |
|
909 |
greenArray at:g put:blueArray |
|
910 |
]. |
|
911 |
(blueArray at:b) == 0 ifTrue:[ |
|
912 |
blueArray at:b put:1. |
|
913 |
nColors := nColors + 1. |
|
914 |
(nColors > nColorCells) ifTrue:[ |
|
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
915 |
"/ 'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR. |
7753 | 916 |
srcIndex := dataSize + 1 |
917 |
] |
|
918 |
] |
|
919 |
]. |
|
920 |
nColorsNeeded isNil ifTrue:[ |
|
921 |
nColorsNeeded := nColors |
|
922 |
]. |
|
923 |
||
924 |
"again with less color bits if it does not fit colormap" |
|
925 |
||
926 |
(nColors <= nColorCells) ifTrue:[ |
|
927 |
fitMap := true |
|
928 |
] ifFalse:[ |
|
929 |
"/ must try again - cutting off some bits |
|
930 |
"/ blue bits are snipped off faster. |
|
931 |
(bMask == 2r11111111) ifTrue:[ |
|
932 |
bMask := 2r11111100 |
|
933 |
] ifFalse:[ |
|
934 |
(bMask == 2r11111100) ifTrue:[ |
|
935 |
bMask := 2r11110000 |
|
936 |
] ifFalse:[ |
|
937 |
(rMask == 2r11111111) ifTrue:[ |
|
938 |
rMask := 2r11111100. |
|
939 |
gMask := 2r11111100. |
|
940 |
] ifFalse:[ |
|
941 |
rMask := (rMask bitShift:1) bitAnd:2r11111111. |
|
942 |
gMask := (gMask bitShift:1) bitAnd:2r11111111. |
|
943 |
bMask := (bMask bitShift:1) bitAnd:2r11111111 |
|
944 |
] |
|
945 |
] |
|
946 |
]. |
|
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
947 |
"/ 'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR. |
38 | 948 |
" |
1 | 949 |
'masks:' print. rMask print. ' ' print. gMask print. ' ' print. |
950 |
bMask printNewline |
|
38 | 951 |
" |
7753 | 952 |
] |
953 |
]. |
|
1 | 954 |
|
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
955 |
"/ 'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR. |
89 | 956 |
|
7753 | 957 |
colors := Array new:nColors. |
958 |
colorIndex := 1. |
|
959 |
||
960 |
" |
|
961 |
now, we have reduced things to the number of colors |
|
962 |
which are theoretically supported by the devices colormap. |
|
963 |
allocate all used colors in walking over true entries in |
|
964 |
the [r][g][b] table - this may still fail, |
|
965 |
if we run out of device colors. |
|
966 |
" |
|
967 |
fit := true. |
|
968 |
||
969 |
r := 0. |
|
970 |
redArray do:[:greenArray | |
|
971 |
(fit and:[greenArray notNil]) ifTrue:[ |
|
972 |
g := 0. |
|
973 |
greenArray do:[:blueArray | |
|
974 |
(fit and:[blueArray notNil]) ifTrue:[ |
|
975 |
b := 0. |
|
976 |
blueArray do:[:present | |
|
977 |
|id| |
|
978 |
||
979 |
(fit and:[present ~~ 0]) ifTrue:[ |
|
980 |
color := Color redByte:r |
|
981 |
greenByte:g |
|
982 |
blueByte:b. |
|
983 |
color := color onDevice:aDevice. |
|
984 |
(id := color colorId) isNil ifTrue:[ |
|
985 |
fit := false |
|
986 |
] ifFalse:[ |
|
987 |
colors at:colorIndex put:color. |
|
988 |
colorIndex := colorIndex + 1. |
|
989 |
blueArray at:(b + 1) put:id |
|
990 |
] |
|
991 |
]. |
|
992 |
b := b + 1 |
|
993 |
] |
|
994 |
]. |
|
995 |
g := g + 1 |
|
996 |
] |
|
997 |
]. |
|
998 |
r := r + 1 |
|
999 |
]. |
|
1000 |
||
1001 |
"again with less color bits if we did not get all colors" |
|
1002 |
||
1003 |
fit ifFalse:[ |
|
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1004 |
"/ 'Depth24Image [info]: could not allocate color(s)' infoPrintCR. |
1 | 1005 |
|
7753 | 1006 |
"free the allocated colors" |
1007 |
colors atAllPut:nil. |
|
1008 |
"a kludge - force immediate freeing of colors" |
|
1009 |
ObjectMemory scavenge; finalize. |
|
1010 |
||
1011 |
"cut off one more color-bit - cut off blue first" |
|
1012 |
(bMask == 2r11111111) ifTrue:[ |
|
1013 |
bMask := 2r11111100 |
|
1014 |
] ifFalse:[ |
|
1015 |
(bMask == 2r11111100) ifTrue:[ |
|
1016 |
bMask := 2r11110000 |
|
1017 |
] ifFalse:[ |
|
1018 |
(rMask == 2r11111111) ifTrue:[ |
|
1019 |
rMask := 2r11111100. |
|
1020 |
gMask := 2r11111100. |
|
1021 |
] ifFalse:[ |
|
1022 |
rMask := (rMask bitShift:1) bitAnd:2r11111111. |
|
1023 |
gMask := (gMask bitShift:1) bitAnd:2r11111111. |
|
1024 |
bMask := (bMask bitShift:1) bitAnd:2r11111111 |
|
1025 |
] |
|
1026 |
] |
|
1027 |
]. |
|
1028 |
fitMap := false. |
|
1029 |
redArray := nil |
|
1030 |
] |
|
1 | 1031 |
]. |
1032 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1033 |
(nColors ~~ nColorsNeeded) ifTrue:[ |
7753 | 1034 |
"/ mhmh - did not get all colors ... |
1035 |
"/ add existing colors and dither. |
|
1036 |
||
1037 |
'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint. |
|
1038 |
nColorsNeeded infoPrint. ' image colors.' infoPrintCR. |
|
1039 |
||
1040 |
"/ |
|
1041 |
"/ dither using those we got ... |
|
1042 |
"/ |
|
1043 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
|
1044 |
colors := colors asNewSet. |
|
1629
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
1045 |
"/ ditherColors := aDevice availableDitherColors. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
1046 |
"/ ditherColors notNil ifTrue:[ |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
1047 |
"/ colors addAll:ditherColors. |
7735e52e84f0
earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents:
1607
diff
changeset
|
1048 |
"/ ]. |
1923
cdd2c4e199df
if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
1049 |
"/ colors addAll:aDevice deviceColors. |
7753 | 1050 |
colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]). |
1051 |
colors := (colors select:[:c | c colorId notNil]) asOrderedCollection. |
|
1052 |
colors size > 256 ifTrue:[ |
|
1053 |
colors := colors copyTo:256 |
|
1054 |
]. |
|
1055 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors. |
|
1056 |
f notNil ifTrue:[^ f]. |
|
1057 |
]. |
|
2535 | 1058 |
]. |
1059 |
||
1060 |
"/ the device ought to support 8-bit images ... |
|
1061 |
(aDevice supportedImageFormatForDepth:8) isNil ifTrue:[ |
|
7753 | 1062 |
"/ cannot draw directly |
1063 |
^ nil |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1064 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
1065 |
|
1 | 1066 |
"create pseudocolor bits and translate" |
1067 |
||
1068 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
1069 |
||
1070 |
srcIndex := 1. |
|
1071 |
dstIndex := 1. |
|
1072 |
||
89 | 1073 |
(rMask == 2r11111111 |
1074 |
and:[gMask == 2r11111111 |
|
1075 |
and:[bMask == 2r11111111]]) ifTrue:[ |
|
7753 | 1076 |
[srcIndex < dataSize] whileTrue:[ |
1077 |
r := bytes at:srcIndex. |
|
1078 |
srcIndex := srcIndex + 1. |
|
1079 |
g := bytes at:srcIndex. |
|
1080 |
srcIndex := srcIndex + 1. |
|
1081 |
b := bytes at:srcIndex. |
|
1082 |
srcIndex := srcIndex + 1. |
|
1083 |
greenArray := redArray at:(r + 1). |
|
1084 |
blueArray := greenArray at:(g + 1). |
|
1085 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)). |
|
1086 |
dstIndex := dstIndex + 1 |
|
1087 |
] |
|
89 | 1088 |
] ifFalse:[ |
7753 | 1089 |
[srcIndex < dataSize] whileTrue:[ |
1090 |
r := bytes at:srcIndex. |
|
1091 |
r := r bitAnd:rMask. |
|
1092 |
srcIndex := srcIndex + 1. |
|
1093 |
g := bytes at:srcIndex. |
|
1094 |
g := g bitAnd:gMask. |
|
1095 |
srcIndex := srcIndex + 1. |
|
1096 |
b := bytes at:srcIndex. |
|
1097 |
b := b bitAnd:bMask. |
|
1098 |
srcIndex := srcIndex + 1. |
|
1099 |
greenArray := redArray at:(r + 1). |
|
1100 |
blueArray := greenArray at:(g + 1). |
|
1101 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)). |
|
1102 |
dstIndex := dstIndex + 1 |
|
1103 |
] |
|
1 | 1104 |
]. |
1105 |
||
7495 | 1106 |
f := Form imageForm width:width height:height depth:depth onDevice:aDevice. |
1 | 1107 |
f isNil ifTrue:[^ nil]. |
1108 |
f colorMap:colors. |
|
4719 | 1109 |
aDevice |
7753 | 1110 |
drawBits:pseudoBits |
1111 |
bitsPerPixel:8 |
|
1112 |
depth:depth |
|
1113 |
padding:8 |
|
1114 |
width:width height:height |
|
1115 |
x:0 y:0 |
|
1116 |
into:(f id) |
|
1117 |
x:0 y:0 |
|
1118 |
width:width height:height |
|
1119 |
with:(f initGC). |
|
1 | 1120 |
^ f |
194 | 1121 |
! |
1122 |
||
1123 |
rgbImageAsTrueColorFormOn:aDevice |
|
1124 |
"return a truecolor form from the rgb-picture." |
|
1125 |
||
4805 | 1126 |
| bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding form imageBits| |
1127 |
||
1128 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
1129 |
usedDeviceDepth := bestFormat at:#depth. |
|
1130 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
|
1131 |
usedDevicePadding := bestFormat at:#padding. |
|
1132 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1133 |
imageBits := self |
7538 | 1134 |
rgbImageBitsOn:aDevice |
1135 |
bestFormat: bestFormat |
|
1136 |
returnUsedDevicePattingIn:[:arg | usedDevicePadding := arg]. |
|
4813
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1137 |
|
4805 | 1138 |
imageBits isNil ifTrue:[ |
7538 | 1139 |
^ self asMonochromeFormOn:aDevice |
4805 | 1140 |
]. |
1141 |
||
7495 | 1142 |
form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
4805 | 1143 |
form isNil ifTrue:[ |
7538 | 1144 |
'Depth24Image [warning]: display bitmap creation failed' errorPrintCR. |
1145 |
^ nil |
|
4805 | 1146 |
]. |
5836
877ff039d6f6
changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents:
5480
diff
changeset
|
1147 |
form id isNil ifTrue:[ |
7538 | 1148 |
"/ usually happens if the image is too big (out of memory) |
1149 |
'Depth24Image [warning]: display bitmap creation failed' errorPrintCR. |
|
1150 |
^ nil |
|
5836
877ff039d6f6
changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents:
5480
diff
changeset
|
1151 |
]. |
877ff039d6f6
changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents:
5480
diff
changeset
|
1152 |
|
4805 | 1153 |
form initGC. |
1154 |
||
1155 |
form |
|
7538 | 1156 |
copyBitsFrom:imageBits |
1157 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
1158 |
depth:usedDeviceDepth |
|
1159 |
padding:usedDevicePadding |
|
1160 |
width:width height:height |
|
1161 |
x:0 y:0 toX:0 y:0. |
|
4805 | 1162 |
|
1163 |
^ form |
|
1164 |
||
5836
877ff039d6f6
changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents:
5480
diff
changeset
|
1165 |
"Modified (format): / 30-12-2011 / 12:54:26 / cg" |
4805 | 1166 |
! |
1167 |
||
1168 |
rgbImageBitsOn:aDevice bestFormat: bestFormat |
|
1169 |
"return rgb bits from the rgb-picture." |
|
1170 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1171 |
^ self |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1172 |
rgbImageBitsOn:aDevice |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1173 |
bestFormat:bestFormat |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1174 |
returnUsedDevicePattingIn:[:usedPadding | ] |
4813
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1175 |
|
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1176 |
"Modified: / 30-10-2007 / 20:56:45 / cg" |
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1177 |
! |
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1178 |
|
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1179 |
rgbImageBitsOn:aDevice bestFormat:bestFormat returnUsedDevicePattingIn:aValueHolder |
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1180 |
"return rgb bits from the rgb-picture. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1181 |
Sorry (sigh) - this might decide to use a different padding; |
4813
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1182 |
this information is returned in aValueHolder" |
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1183 |
|
4805 | 1184 |
|bytes usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding |
1185 |
myDepth imageBits padd |
|
856 | 1186 |
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue| |
194 | 1187 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1188 |
bytes := self bits. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1189 |
|
236 | 1190 |
usedDeviceDepth := bestFormat at:#depth. |
1191 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
|
2064 | 1192 |
usedDevicePadding := bestFormat at:#padding. |
194 | 1193 |
|
1194 |
rightShiftR := (8 - aDevice bitsRed). |
|
1195 |
rightShiftG := (8 - aDevice bitsGreen). |
|
1196 |
rightShiftB := (8 - aDevice bitsBlue). |
|
1197 |
||
1198 |
shiftRed := aDevice shiftRed. |
|
1199 |
shiftGreen := aDevice shiftGreen. |
|
1200 |
shiftBlue := aDevice shiftBlue. |
|
1201 |
||
1202 |
"/ |
|
1203 |
"/ for now, only a few formats are supported |
|
1204 |
"/ |
|
1205 |
myDepth := self bitsPerPixel. |
|
1206 |
myDepth == usedDeviceBitsPerPixel ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1207 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1208 |
"/ first, the trivial case, where the depths match |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1209 |
"/ 24 bit/pixel |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1210 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1211 |
imageBits := bytes. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1212 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1213 |
"/ however, the rgb-order could still be different |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1214 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1215 |
((shiftBlue == 0) and:[(shiftGreen == 8) and:[shiftRed == 16]]) ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1216 |
imageBits := ByteArray uninitializedNew:(width * height * 3). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1217 |
usedDevicePadding := 8. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1218 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1219 |
"/ now, walk over the image and compose 24bit values from the r/g/b triples |
2064 | 1220 |
%{ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1221 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1222 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1223 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1224 |
if (__isByteArrayLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1225 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1226 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1227 |
if (__isExternalBytesLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1228 |
srcPtr = __externalBytesAddress(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1229 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1230 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1231 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1232 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1233 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1234 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1235 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1236 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1237 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1238 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1239 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1240 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1241 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1242 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1243 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1244 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1245 |
int rShRed = __intVal(rightShiftR), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1246 |
rShGreen = __intVal(rightShiftG), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1247 |
rShBlue = __intVal(rightShiftB), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1248 |
lShRed = __intVal(shiftRed), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1249 |
lShGreen = __intVal(shiftGreen), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1250 |
lShBlue = __intVal(shiftBlue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1251 |
int x, y, w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1252 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1253 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1254 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1255 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1256 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1257 |
unsigned v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1258 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1259 |
v = srcPtr[0] << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1260 |
v |= (srcPtr[1] << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1261 |
v |= (srcPtr[2] << lShBlue); |
2401 | 1262 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1263 |
dstPtr[0] = (v) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1264 |
dstPtr[1] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1265 |
dstPtr[2] = (v>>16) & 0xFF; |
3357 | 1266 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1267 |
dstPtr[0] = (v>>16) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1268 |
dstPtr[1] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1269 |
dstPtr[2] = (v) & 0xFF; |
3357 | 1270 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1271 |
dstPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1272 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1273 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1274 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1275 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1276 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1277 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1278 |
unsigned r, g, b, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1279 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1280 |
r = srcPtr[0] >> rShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1281 |
g = srcPtr[1] >> rShGreen; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1282 |
b = srcPtr[2] >> rShBlue; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1283 |
v = r << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1284 |
v |= (g << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1285 |
v |= (b << lShBlue); |
2401 | 1286 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1287 |
dstPtr[0] = (v) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1288 |
dstPtr[1] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1289 |
dstPtr[2] = (v>>16) & 0xFF; |
3357 | 1290 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1291 |
dstPtr[0] = (v>>16) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1292 |
dstPtr[1] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1293 |
dstPtr[2] = (v) & 0xFF; |
3357 | 1294 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1295 |
dstPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1296 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1297 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1298 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1299 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1300 |
} |
2064 | 1301 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1302 |
] |
194 | 1303 |
] ifFalse:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1304 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1305 |
"/ 16 bit/pixel ... |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1306 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1307 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1308 |
padd := width \\ (usedDevicePadding // 16). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1309 |
imageBits := ByteArray uninitializedNew:((width + padd) * height * 2). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1310 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1311 |
"/ now, walk over the image and compose 16bit values from the r/g/b triples |
194 | 1312 |
|
856 | 1313 |
%{ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1314 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1315 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1316 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1317 |
if (__isByteArrayLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1318 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1319 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1320 |
if (__isExternalBytesLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1321 |
srcPtr = __externalBytesAddress(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1322 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1323 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1324 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1325 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1326 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1327 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1328 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1329 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1330 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1331 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1332 |
if (__bothSmallInteger(__INST(height),__INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1333 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1334 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1335 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1336 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1337 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1338 |
int rShRed = __intVal(rightShiftR), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1339 |
rShGreen = __intVal(rightShiftG), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1340 |
rShBlue = __intVal(rightShiftB), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1341 |
lShRed = __intVal(shiftRed), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1342 |
lShGreen = __intVal(shiftGreen), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1343 |
lShBlue = __intVal(shiftBlue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1344 |
int x, y, w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1345 |
int p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1346 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1347 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1348 |
p = __intVal(padd) * 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1349 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1350 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1351 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1352 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1353 |
unsigned v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1354 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1355 |
v = srcPtr[0] << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1356 |
v |= (srcPtr[1] << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1357 |
v |= (srcPtr[2] << lShBlue); |
3357 | 1358 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1359 |
((short *)dstPtr)[0] = v; |
3357 | 1360 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1361 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1362 |
dstPtr[1] = (v) & 0xFF; |
3357 | 1363 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1364 |
dstPtr += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1365 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1366 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1367 |
dstPtr += p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1368 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1369 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1370 |
if (p == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1371 |
int n = __intVal(__INST(height)) * w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1372 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1373 |
while (n >= 2) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1374 |
unsigned w, r, g, b, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1375 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1376 |
n -= 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1377 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1378 |
r = srcPtr[0]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1379 |
g = srcPtr[1]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1380 |
b = srcPtr[2]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1381 |
v = (r >> rShRed) << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1382 |
v |= ((g >> rShGreen) << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1383 |
v |= ((b >> rShBlue) << lShBlue); |
2401 | 1384 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1385 |
((short *)dstPtr)[0] = v; |
194 | 1386 |
# else |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1387 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1388 |
dstPtr[1] = (v) & 0xFF; |
3357 | 1389 |
# endif /* not MSB */ |
194 | 1390 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1391 |
r = srcPtr[3]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1392 |
g = srcPtr[4]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1393 |
b = srcPtr[5]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1394 |
v = (r >> rShRed) << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1395 |
v |= ((g >> rShGreen) << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1396 |
v |= ((b >> rShBlue) << lShBlue); |
3357 | 1397 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1398 |
((short *)dstPtr)[1] = v; |
3357 | 1399 |
# else |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1400 |
dstPtr[2] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1401 |
dstPtr[3] = (v) & 0xFF; |
3357 | 1402 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1403 |
dstPtr += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1404 |
srcPtr += 6; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1405 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1406 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1407 |
while (n--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1408 |
unsigned r, g, b, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1409 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1410 |
r = srcPtr[0] >> rShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1411 |
g = srcPtr[1] >> rShGreen; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1412 |
b = srcPtr[2] >> rShBlue; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1413 |
v = r << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1414 |
v |= (g << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1415 |
v |= (b << lShBlue); |
2401 | 1416 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1417 |
((short *)dstPtr)[0] = v; |
3357 | 1418 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1419 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1420 |
dstPtr[1] = (v) & 0xFF; |
3357 | 1421 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1422 |
dstPtr += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1423 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1424 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1425 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1426 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1427 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1428 |
unsigned r, g, b, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1429 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1430 |
r = srcPtr[0] >> rShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1431 |
g = srcPtr[1] >> rShGreen; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1432 |
b = srcPtr[2] >> rShBlue; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1433 |
v = r << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1434 |
v |= (g << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1435 |
v |= (b << lShBlue); |
3357 | 1436 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1437 |
((short *)dstPtr)[0] = v; |
3357 | 1438 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1439 |
dstPtr[0] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1440 |
dstPtr[1] = (v) & 0xFF; |
3357 | 1441 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1442 |
dstPtr += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1443 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1444 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1445 |
dstPtr += p; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1446 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1447 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1448 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1449 |
} |
194 | 1450 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1451 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1452 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1453 |
"/ 32 bits/pixel ... |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1454 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1455 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1456 |
usedDevicePadding := 8. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1457 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1458 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1459 |
"/ now, walk over the image and compose 32bit values from the r/g/b triples |
4719 | 1460 |
|
1461 |
%{ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1462 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1463 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1464 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1465 |
if (__isByteArrayLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1466 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1467 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1468 |
if (__isExternalBytesLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1469 |
srcPtr = __externalBytesAddress(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1470 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1471 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1472 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1473 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1474 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1475 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1476 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1477 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1478 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1479 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1480 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1481 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1482 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1483 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1484 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1485 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1486 |
int rShRed = __intVal(rightShiftR), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1487 |
rShGreen = __intVal(rightShiftG), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1488 |
rShBlue = __intVal(rightShiftB), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1489 |
lShRed = __intVal(shiftRed), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1490 |
lShGreen = __intVal(shiftGreen), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1491 |
lShBlue = __intVal(shiftBlue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1492 |
int x, y, w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1493 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1494 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1495 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1496 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1497 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1498 |
unsigned v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1499 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1500 |
v = srcPtr[0] << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1501 |
v |= (srcPtr[1] << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1502 |
v |= (srcPtr[2] << lShBlue); |
2401 | 1503 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1504 |
((int *)dstPtr)[0] = v; |
3357 | 1505 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1506 |
dstPtr[0] = (v>>24) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1507 |
dstPtr[1] = (v>>16) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1508 |
dstPtr[2] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1509 |
dstPtr[3] = (v) & 0xFF; |
3357 | 1510 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1511 |
dstPtr += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1512 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1513 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1514 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1515 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1516 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1517 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1518 |
unsigned r, g, b, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1519 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1520 |
r = srcPtr[0] >> rShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1521 |
g = srcPtr[1] >> rShGreen; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1522 |
b = srcPtr[2] >> rShBlue; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1523 |
v = r << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1524 |
v |= (g << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1525 |
v |= (b << lShBlue); |
2401 | 1526 |
# ifdef __MSBFIRST |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1527 |
((int *)dstPtr)[0] = v; |
3357 | 1528 |
# else /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1529 |
dstPtr[0] = (v>>24) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1530 |
dstPtr[1] = (v>>16) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1531 |
dstPtr[2] = (v>>8) & 0xFF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1532 |
dstPtr[3] = (v) & 0xFF; |
3357 | 1533 |
# endif /* not MSB */ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1534 |
dstPtr += 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1535 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1536 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1537 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1538 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1539 |
} |
194 | 1540 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1541 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1542 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1543 |
"/ 8 bits/pixel ... |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1544 |
"/ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1545 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1546 |
usedDevicePadding := 8. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1547 |
imageBits := ByteArray uninitializedNew:(width * height). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1548 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1549 |
"/ now, walk over the image and compose 8bit values from the r/g/b triples |
4719 | 1550 |
|
1551 |
%{ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1552 |
unsigned char *srcPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1553 |
unsigned char *dstPtr = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1554 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1555 |
if (__isByteArrayLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1556 |
srcPtr = __ByteArrayInstPtr(bytes)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1557 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1558 |
if (__isExternalBytesLike(bytes)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1559 |
srcPtr = __externalBytesAddress(bytes); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1560 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1561 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1562 |
if (__isByteArray(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1563 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1564 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1565 |
if (__isExternalBytesLike(imageBits)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1566 |
dstPtr = __externalBytesAddress(imageBits); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1567 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1568 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1569 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1570 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1571 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1572 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1573 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1574 |
&& srcPtr |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1575 |
&& dstPtr) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1576 |
int rShRed = __intVal(rightShiftR), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1577 |
rShGreen = __intVal(rightShiftG), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1578 |
rShBlue = __intVal(rightShiftB), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1579 |
lShRed = __intVal(shiftRed), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1580 |
lShGreen = __intVal(shiftGreen), |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1581 |
lShBlue = __intVal(shiftBlue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1582 |
int x, y, w; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1583 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1584 |
w = __intVal(__INST(width)); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1585 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1586 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1587 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1588 |
unsigned v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1589 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1590 |
v = srcPtr[0] << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1591 |
v |= (srcPtr[1] << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1592 |
v |= (srcPtr[2] << lShBlue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1593 |
dstPtr[0] = v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1594 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1595 |
dstPtr += 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1596 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1597 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1598 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1599 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1600 |
for (y=__intVal(__INST(height)); y > 0; y--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1601 |
for (x=w; x > 0; x--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1602 |
unsigned r, g, b, v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1603 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1604 |
r = srcPtr[0] >> rShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1605 |
g = srcPtr[1] >> rShGreen; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1606 |
b = srcPtr[2] >> rShBlue; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1607 |
v = r << lShRed; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1608 |
v |= (g << lShGreen); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1609 |
v |= (b << lShBlue); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1610 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1611 |
dstPtr[0] = v; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1612 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1613 |
dstPtr += 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1614 |
srcPtr += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1615 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1616 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1617 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1618 |
} |
856 | 1619 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1620 |
] |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1621 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1622 |
] |
194 | 1623 |
]. |
1624 |
||
4719 | 1625 |
imageBits isNil ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1626 |
'IMAGE: unimplemented trueColor depth in #rgbImageBitsOn: ' errorPrint. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1627 |
usedDeviceBitsPerPixel errorPrintCR. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
1628 |
^ nil |
194 | 1629 |
]. |
4813
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1630 |
aValueHolder value:usedDevicePadding. |
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1631 |
^ imageBits |
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1632 |
|
f03cd0880bd9
oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents:
4805
diff
changeset
|
1633 |
"Created: / 30-10-2007 / 20:54:53 / cg" |
3490 | 1634 |
! ! |
810 | 1635 |
|
1636 |
!Depth24Image methodsFor:'dither helpers'! |
|
1637 |
||
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1638 |
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1639 |
"return a floyd-steinberg dithered bitmap from the receiver picture, |
4719 | 1640 |
which must be a depth-24 image. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1641 |
This method expects an array of colors to be used for dithering |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1642 |
(which need not be a colorCubes colors)." |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1643 |
|
4719 | 1644 |
|pseudoBits |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1645 |
ditherRGBBytes ditherColors |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1646 |
w "{Class: SmallInteger }" |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1647 |
h "{Class: SmallInteger }" |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1648 |
index "{Class: SmallInteger }" |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1649 |
ditherIds failed lastColor qScramble |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1650 |
clrLookup lookupPos |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1651 |
error clr| |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1652 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1653 |
self depth ~~ 24 ifTrue:[^ nil]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1654 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1655 |
"/ collect valid ditherColors ... |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1656 |
aMapOrNil isNil ifTrue:[ |
7817 | 1657 |
ditherColors := colors select:[:clr | clr notNil]. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1658 |
] ifFalse:[ |
7817 | 1659 |
ditherColors := colors |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1660 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1661 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1662 |
"/ ... and sort by manhatten distance from black |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1663 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1664 |
qScramble := #( |
7817 | 1665 |
"/ 2rX00X00X00X00 |
1666 |
||
1667 |
2r000000000000 "/ 0 |
|
1668 |
2r000000000100 "/ 1 |
|
1669 |
2r000000100000 "/ 2 |
|
1670 |
2r000000100100 "/ 3 |
|
1671 |
2r000100000000 "/ 4 |
|
1672 |
2r000100000100 "/ 5 |
|
1673 |
2r000100100000 "/ 6 |
|
1674 |
2r000100100100 "/ 7 |
|
1675 |
2r100000000000 "/ 8 |
|
1676 |
2r100000000100 "/ 9 |
|
1677 |
2r100000100000 "/ a |
|
1678 |
2r100000100100 "/ b |
|
1679 |
2r100100000000 "/ c |
|
1680 |
2r100100000100 "/ d |
|
1681 |
2r100100100000 "/ e |
|
1682 |
2r100100100100 "/ f |
|
1683 |
). |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1684 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1685 |
ditherColors := ditherColors sort:[:a :b | |
7817 | 1686 |
|cr "{Class: SmallInteger }" |
1687 |
cg "{Class: SmallInteger }" |
|
1688 |
cb "{Class: SmallInteger }" |
|
1689 |
i1 "{Class: SmallInteger }" |
|
1690 |
i2 "{Class: SmallInteger }"| |
|
1691 |
||
1692 |
cr := a redByte. |
|
1693 |
cg := a greenByte. |
|
1694 |
cb := a blueByte. |
|
1695 |
i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
|
1696 |
i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
|
1697 |
i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
|
1698 |
||
1699 |
cr := b redByte. |
|
1700 |
cg := b greenByte. |
|
1701 |
cb := b blueByte. |
|
1702 |
i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1. |
|
1703 |
i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
|
1704 |
i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
|
1705 |
||
1706 |
i1 < i2 |
|
1707 |
]. |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1708 |
aMapOrNil isNil ifTrue:[ |
7817 | 1709 |
ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray. |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1710 |
] ifFalse:[ |
7817 | 1711 |
ditherIds := aMapOrNil asByteArray |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1712 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1713 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1714 |
"/ build an index table, for fast lookup from manhatten-r-g-b distance |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1715 |
"/ to the position in the colorList |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1716 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1717 |
clrLookup := ByteArray new:(4096). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1718 |
index := 0. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1719 |
ditherColors keysAndValuesDo:[:clrPosition :clr | |
7817 | 1720 |
|r g b i| |
1721 |
||
1722 |
r := clr redByte. |
|
1723 |
g := clr greenByte. |
|
1724 |
b := clr blueByte. |
|
1725 |
i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1. |
|
1726 |
i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1). |
|
1727 |
i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2). |
|
1728 |
lookupPos := i. |
|
1729 |
||
1730 |
index+1 to:lookupPos do:[:idx| |
|
1731 |
clrLookup at:idx put:(clrPosition-1-1). |
|
1732 |
]. |
|
1733 |
index := lookupPos. |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1734 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1735 |
clrLookup from:index+1 to:4096 put:(ditherColors size - 1). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1736 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1737 |
"/ [index <= (4095)] whileTrue:[ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1738 |
"/ clrLookup at:(index+1) put:(ditherColors size - 1). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1739 |
"/ index := index + 1. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1740 |
"/ ]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1741 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1742 |
"/ collect ditherColor components |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1743 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1744 |
lastColor := ditherColors size. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1745 |
ditherIds := ByteArray uninitializedNew:lastColor. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1746 |
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1747 |
index := 1. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1748 |
1 to:lastColor do:[:pix | |
7817 | 1749 |
clr := ditherColors at:pix. |
1750 |
ditherRGBBytes at:index put:(clr redByte). |
|
1751 |
ditherRGBBytes at:index+1 put:(clr greenByte). |
|
1752 |
ditherRGBBytes at:index+2 put:(clr blueByte). |
|
1753 |
aMapOrNil isNil ifTrue:[ |
|
1754 |
ditherIds at:pix put:clr colorId. |
|
1755 |
] ifFalse:[ |
|
1756 |
ditherIds at:pix put:(aMapOrNil at:pix). |
|
1757 |
]. |
|
1758 |
index := index + 3. |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1759 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1760 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1761 |
|
3907 | 1762 |
error := ByteArray uninitializedNew:(width + 2) * (3*2). |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1763 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1764 |
w := width. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1765 |
h := height. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1766 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1767 |
failed := true. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1768 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1769 |
%{ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1770 |
int __x, __y; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1771 |
unsigned char *srcP, *dstP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1772 |
unsigned char *idP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1773 |
unsigned char *__clrLookup; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1774 |
short *errP, *eP; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1775 |
int __w = __intVal(w); |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1776 |
int __h = __intVal(h); |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1777 |
int __nColors = __intVal(lastColor); |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1778 |
int __wR = -1, __wG, __wB; |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1779 |
static int __qScramble[16] = { |
7817 | 1780 |
0x000 /* 2r000000000000 0 */, |
1781 |
0x004 /* 2r000000000100 1 */, |
|
1782 |
0x020 /* 2r000000100000 2 */, |
|
1783 |
0x024 /* 2r000000100100 3 */, |
|
1784 |
0x100 /* 2r000100000000 4 */, |
|
1785 |
0x104 /* 2r000100000100 5 */, |
|
1786 |
0x120 /* 2r000100100000 6 */, |
|
1787 |
0x124 /* 2r000100100100 7 */, |
|
1788 |
0x800 /* 2r100000000000 8 */, |
|
1789 |
0x804 /* 2r100000000100 9 */, |
|
1790 |
0x820 /* 2r100000100000 a */, |
|
1791 |
0x824 /* 2r100000100100 b */, |
|
1792 |
0x900 /* 2r100100000000 c */, |
|
1793 |
0x904 /* 2r100100000100 d */, |
|
1794 |
0x920 /* 2r100100100000 e */, |
|
1795 |
0x924 /* 2r100100100100 f */, |
|
1796 |
}; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1797 |
|
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
1798 |
if (__isByteArrayLike(__INST(bytes)) |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1799 |
&& __isByteArray(pseudoBits) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1800 |
&& __isByteArray(ditherRGBBytes) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1801 |
&& __isByteArray(ditherIds) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1802 |
&& __isByteArray(clrLookup) |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1803 |
&& __isByteArray(error)) { |
7817 | 1804 |
failed = false; |
1805 |
||
1806 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1807 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
1808 |
idP = __ByteArrayInstPtr(ditherIds)->ba_element; |
|
1809 |
__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element; |
|
1810 |
errP = (short *) __ByteArrayInstPtr(error)->ba_element; |
|
1811 |
||
1812 |
/* |
|
1813 |
* clear error accumulator |
|
1814 |
*/ |
|
1815 |
eP = errP; |
|
1816 |
bzero(eP, (__w+2) * 2 * 3); |
|
1817 |
||
1818 |
for (__y=__h; __y>0; __y--) { |
|
1819 |
unsigned char *dp; |
|
1820 |
int __eR, __eG, __eB; |
|
1821 |
||
1822 |
__eR = __eG = __eB = 0; |
|
1823 |
||
1824 |
eP = &(errP[3]); |
|
1825 |
__eR = eP[0]; |
|
1826 |
__eG = eP[1]; |
|
1827 |
__eB = eP[2]; |
|
1828 |
||
1829 |
for (__x=__w; __x>0; __x--) { |
|
1830 |
int __want; |
|
1831 |
int pix; |
|
1832 |
int __wantR, __wantG, __wantB; |
|
1833 |
int idx; |
|
1834 |
int tR, tG, tB; |
|
1835 |
int nR, nG, nB; |
|
1836 |
int dR, dG, dB; |
|
1837 |
int minDelta, bestIdx; |
|
1838 |
int cnt; |
|
1839 |
||
1840 |
__wantR = srcP[0]; |
|
1841 |
__wantG = srcP[1]; |
|
1842 |
__wantB = srcP[2]; |
|
1843 |
srcP += 3; |
|
1844 |
||
1845 |
/* |
|
1846 |
* wI are the wanted r/g/b values; |
|
1847 |
* eI are the error values; |
|
1848 |
*/ |
|
1849 |
__wantR = __wantR + __eR; |
|
1850 |
__wantG = __wantG + __eG; |
|
1851 |
__wantB = __wantB + __eB; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1852 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1853 |
#define RED_SCALE 30 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1854 |
#define GREEN_SCALE 59 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1855 |
#define BLUE_SCALE 11 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1856 |
#define GOOD_DELTA 30 |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1857 |
|
3907 | 1858 |
#define FAST_LOOKUP /* */ |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1859 |
/* #define ONE_SHOT */ |
5343 | 1860 |
#define NPROBE 16 |
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1861 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1862 |
#ifndef FAST_LOOKUP |
7817 | 1863 |
if ((__wantR == __wR) |
1864 |
&& (__wantG == __wG) |
|
1865 |
&& (__wantB == __wB)) { |
|
1866 |
/* |
|
1867 |
* same color again - reuse last bestMatch |
|
1868 |
*/ |
|
1869 |
} else |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1870 |
#endif |
7817 | 1871 |
{ |
1872 |
__wR = __wantR; |
|
1873 |
__wG = __wantG; |
|
1874 |
__wB = __wantB; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1875 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1876 |
#ifdef FAST_LOOKUP |
7817 | 1877 |
if(__wR > 255) __wR = 255; |
1878 |
else if (__wR < 0) __wR = 0; |
|
1879 |
if(__wG > 255) __wG = 255; |
|
1880 |
else if (__wG < 0) __wG = 0; |
|
1881 |
if(__wB > 255) __wB = 255; |
|
1882 |
else if (__wB < 0) __wB = 0; |
|
1883 |
||
1884 |
{ |
|
1885 |
int lookupIndex; |
|
1886 |
int idx, idx0; |
|
1887 |
int d, delta; |
|
1888 |
unsigned char *dp0; |
|
1889 |
||
1890 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
1891 |
lookupIndex = __qScramble[((__wR & 0xF0)>>4)]; |
|
1892 |
lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1; |
|
1893 |
lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2; |
|
1894 |
idx = bestIdx =__clrLookup[lookupIndex]; |
|
1895 |
dp += (idx+idx+idx); |
|
1896 |
||
1897 |
/* try color at lookupIndex */ |
|
1898 |
||
1899 |
d = dp[0]; |
|
1900 |
delta = (__wR - d) * RED_SCALE; |
|
1901 |
if (delta < 0) delta = -delta; |
|
1902 |
||
1903 |
d = dp[1]; |
|
1904 |
if (__wG > d) |
|
1905 |
delta += (__wG - d) * GREEN_SCALE; |
|
1906 |
else |
|
1907 |
delta += (d - __wG) * GREEN_SCALE; |
|
1908 |
d = dp[2]; |
|
1909 |
if (__wB > d) |
|
1910 |
delta += (__wB - d) * BLUE_SCALE; |
|
1911 |
else |
|
1912 |
delta += (d - __wB) * BLUE_SCALE; |
|
1913 |
||
1914 |
if (delta <= GOOD_DELTA) { |
|
1915 |
goto foundBest; |
|
1916 |
} |
|
1917 |
minDelta = delta; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1918 |
# ifndef ONE_SHOT |
7817 | 1919 |
idx0 = idx; dp0 = dp; |
1920 |
cnt = 0; |
|
1921 |
while ((++cnt <= NPROBE) && (idx > 0)) { |
|
1922 |
/* try previous color(s) */ |
|
1923 |
||
1924 |
idx--; dp -= 3; |
|
1925 |
d = dp[0]; |
|
1926 |
delta = (__wR - d) * RED_SCALE; |
|
1927 |
if (delta < 0) delta = -delta; |
|
1928 |
d = dp[1]; |
|
1929 |
if (__wG > d) |
|
1930 |
delta += (__wG - d) * GREEN_SCALE; |
|
1931 |
else |
|
1932 |
delta += (d - __wG) * GREEN_SCALE; |
|
1933 |
d = dp[2]; |
|
1934 |
if (__wB > d) |
|
1935 |
delta += (__wB - d) * BLUE_SCALE; |
|
1936 |
else |
|
1937 |
delta += (d - __wB) * BLUE_SCALE; |
|
1938 |
||
1939 |
if (delta < minDelta) { |
|
1940 |
bestIdx = idx; |
|
1941 |
if (delta <= GOOD_DELTA) { |
|
1942 |
goto foundBest; |
|
1943 |
} |
|
1944 |
minDelta = delta; |
|
1945 |
} |
|
1946 |
} |
|
1947 |
||
1948 |
idx = idx0; dp = dp0; |
|
1949 |
cnt = 0; |
|
1950 |
while ((++cnt <= NPROBE) && (++idx < __nColors)) { |
|
1951 |
/* try next color */ |
|
1952 |
||
1953 |
dp += 3; |
|
1954 |
d = dp[0]; |
|
1955 |
delta = (__wR - d) * RED_SCALE; |
|
1956 |
if (delta < 0) delta = -delta; |
|
1957 |
d = dp[1]; |
|
1958 |
if (__wG > d) |
|
1959 |
delta += (__wG - d) * GREEN_SCALE; |
|
1960 |
else |
|
1961 |
delta += (d - __wG) * GREEN_SCALE; |
|
1962 |
d = dp[2]; |
|
1963 |
if (__wB > d) |
|
1964 |
delta += (__wB - d) * BLUE_SCALE; |
|
1965 |
else |
|
1966 |
delta += (d - __wB) * BLUE_SCALE; |
|
1967 |
||
1968 |
if (delta < minDelta) { |
|
1969 |
bestIdx = idx; |
|
1970 |
if (delta <= GOOD_DELTA) { |
|
1971 |
goto foundBest; |
|
1972 |
} |
|
1973 |
minDelta = delta; |
|
1974 |
} |
|
1975 |
} |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1976 |
# endif |
7817 | 1977 |
} |
1978 |
foundBest: ; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1979 |
#else |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1980 |
/* |
7817 | 1981 |
if(__wR > 255) __wR = 255; |
1982 |
else if (__wR < 0) __wR = 0; |
|
1983 |
if(__wG > 255) __wG = 255; |
|
1984 |
else if (__wG < 0) __wG = 0; |
|
1985 |
if(__wB > 255) __wB = 255; |
|
1986 |
else if (__wB < 0) __wB = 0; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1987 |
*/ |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
1988 |
|
7817 | 1989 |
/* find the best matching color */ |
1990 |
||
1991 |
minDelta = 99999; |
|
1992 |
bestIdx = -1; |
|
1993 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
1994 |
for (idx = 0; idx<__nColors; idx++) { |
|
1995 |
int d, delta; |
|
1996 |
||
1997 |
d = dp[0]; |
|
1998 |
delta = (__wR - d) * RED_SCALE; |
|
1999 |
if (delta < 0) delta = -delta; |
|
2000 |
if (delta < minDelta) { |
|
2001 |
d = dp[1]; |
|
2002 |
if (__wG > d) |
|
2003 |
delta += (__wG - d) * GREEN_SCALE; |
|
2004 |
else |
|
2005 |
delta += (d - __wG) * GREEN_SCALE; |
|
2006 |
if (delta < minDelta) { |
|
2007 |
d = dp[2]; |
|
2008 |
if (__wB > d) |
|
2009 |
delta += (__wB - d) * BLUE_SCALE; |
|
2010 |
else |
|
2011 |
delta += (d - __wB) * BLUE_SCALE; |
|
2012 |
||
2013 |
if (delta < minDelta) { |
|
2014 |
bestIdx = idx; |
|
2015 |
if (delta <= GOOD_DELTA) { |
|
2016 |
break; |
|
2017 |
} |
|
2018 |
minDelta = delta; |
|
2019 |
} |
|
2020 |
} |
|
2021 |
} |
|
2022 |
dp += 3; |
|
2023 |
} |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2024 |
#endif |
7817 | 2025 |
} |
2026 |
||
2027 |
dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element; |
|
2028 |
dp += bestIdx * 3; |
|
2029 |
dR = dp[0]; |
|
2030 |
dG = dp[1]; |
|
2031 |
dB = dp[2]; |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2032 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2033 |
/* |
4721 | 2034 |
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n", |
7817 | 2035 |
__wantR, __wantG, __wantB, |
2036 |
__wR, __wG, __wB, |
|
2037 |
dR, dG, dB); |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2038 |
*/ |
7817 | 2039 |
/* |
2040 |
* store the corresponding dither colors colorId |
|
2041 |
*/ |
|
2042 |
*dstP++ = idP[bestIdx]; |
|
2043 |
||
2044 |
/* |
|
2045 |
* the new error & distribute the error |
|
2046 |
*/ |
|
2047 |
__eR = __wantR - dR; |
|
2048 |
if (__eR) { |
|
2049 |
tR = __eR >> 4; /* 16th of error */ |
|
2050 |
nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */ |
|
2051 |
eP[0] = tR*5; /* 5/16th for (x / y+1) */ |
|
2052 |
eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */ |
|
2053 |
eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */ |
|
2054 |
__eR = nR; |
|
2055 |
} else { |
|
2056 |
__eR = eP[3]; |
|
2057 |
eP[0] = eP[-3] = eP[3] = 0; |
|
2058 |
} |
|
2059 |
||
2060 |
__eG = __wantG - dG; |
|
2061 |
if (__eG) { |
|
2062 |
tG = __eG >> 4; |
|
2063 |
nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */ |
|
2064 |
eP[1] = tG*5; |
|
2065 |
eP[-2] = tG*3; |
|
2066 |
eP[4] = __eG - (tG*15); |
|
2067 |
__eG = nG; |
|
2068 |
} else { |
|
2069 |
__eG = eP[4]; |
|
2070 |
eP[1] = eP[-2] = eP[4] = 0; |
|
2071 |
} |
|
2072 |
||
2073 |
__eB = __wantB - dB; |
|
2074 |
if (__eB) { |
|
2075 |
tB = __eB >> 4; |
|
2076 |
nB = eP[5] + (tB * 7); |
|
2077 |
eP[2] = tB*5; |
|
2078 |
eP[-1] = tB*3; |
|
2079 |
eP[5] = __eB - (tB*15); |
|
2080 |
__eB = nB; |
|
2081 |
} else { |
|
2082 |
__eB = eP[5]; |
|
2083 |
eP[2] = eP[-1] = eP[5] = 0; |
|
2084 |
} |
|
2085 |
||
2086 |
eP += 3; |
|
2087 |
} |
|
2088 |
} |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2089 |
} |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2090 |
%}. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2091 |
failed ifTrue:[ |
7817 | 2092 |
self primitiveFailed. |
2093 |
^ nil |
|
3906
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2094 |
]. |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2095 |
|
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2096 |
^ pseudoBits |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2097 |
! |
f77d3b42614a
dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents:
3872
diff
changeset
|
2098 |
|
1779 | 2099 |
floydSteinbergDitheredGrayBitsDepth:depth |
2100 |
"return the bits for dithering a depth gray bitmap from the image. |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2101 |
Redefined to make use of knowing that pixels are 24 bit r/g/b" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2102 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2103 |
|dstIndex "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2104 |
nextDst "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2105 |
bytesPerRow "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2106 |
bytesPerOutRow "{Class: SmallInteger }" |
4719 | 2107 |
outBits greyMap1 greyMap2 greyLevels |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2108 |
errorArray |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2109 |
errorArray1 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2110 |
e t v |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2111 |
w "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2112 |
h "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2113 |
bitCnt "{Class: SmallInteger }" |
4719 | 2114 |
byte "{Class: SmallInteger }" |
2115 |
grey dT |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2116 |
eR eRB eB eLB bytes| |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2117 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2118 |
(samplesPerPixel ~~ 3 |
7817 | 2119 |
or:[(#[8 8 8] isSameSequenceAs:bitsPerSample) not |
2120 |
or:[depth > 8]]) ifTrue:[ |
|
2121 |
^ super floydSteinbergDitheredGrayBitsDepth:depth |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2122 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2123 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2124 |
bytes := self bits. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2125 |
bytes isNil ifTrue:[ self error. ^ nil]. |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2126 |
w := width. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2127 |
h := height. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2128 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2129 |
bytesPerRow := self bytesPerRow. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2130 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2131 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2132 |
|
1932 | 2133 |
depth ~~ 8 ifTrue:[ |
7817 | 2134 |
greyLevels := (1 bitShift:depth) - 1. |
2135 |
greyMap1 := Array new:256. |
|
2136 |
greyMap2 := Array new:256. |
|
2137 |
1 to:256 do:[:i | |
|
2138 |
v := (greyLevels / 255 * (i-1)). |
|
2139 |
greyMap1 at:i put:v. |
|
2140 |
greyMap2 at:i put:v. |
|
2141 |
]. |
|
2142 |
greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray. |
|
2143 |
||
2144 |
greyMap2 := (greyMap2 collect:[:el | |
|
2145 |
((el - el truncated) "/ the error (0..1) |
|
2146 |
* 255) rounded]) asByteArray. |
|
2147 |
||
2148 |
errorArray := ByteArray new:(w + 2) * 2. |
|
2149 |
errorArray1 := ByteArray new:(w + 2) * 2. |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2150 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2151 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2152 |
%{ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2153 |
int __byte; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2154 |
int __dT, __err, __e16, __eR, __eB, __eRB, __eLB; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2155 |
int __depth = __intVal(depth); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2156 |
int __dstIdx = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2157 |
int __srcIdx = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2158 |
int __bitCnt; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2159 |
int __grey; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2160 |
int __w = __intVal(w); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2161 |
int __h = __intVal(h); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2162 |
int __x; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2163 |
int __y; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2164 |
int __nextDst; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2165 |
int __nextSrc; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2166 |
int __bytesPerRow = __intVal(bytesPerRow); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2167 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2168 |
int __pixel; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2169 |
int __greyLevels = __intVal(greyLevels); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2170 |
|
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
2171 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2172 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2173 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2174 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2175 |
short *__errorArray = (short *)(__ByteArrayInstPtr(errorArray)->ba_element); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2176 |
short *__errorArray1 = (short *)(__ByteArrayInstPtr(errorArray1)->ba_element); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2177 |
short *__t; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2178 |
|
1932 | 2179 |
if (__depth == 8) { |
7817 | 2180 |
/* |
2181 |
* special code for destination depth 8 |
|
2182 |
*/ |
|
2183 |
for (__y=0; __y<__h; __y++) { |
|
2184 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
2185 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
2186 |
for (__x=0; __x<__w; __x++) { |
|
2187 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
2188 |
+ (__bytes[__srcIdx+1] * 6) |
|
2189 |
+ __bytes[__srcIdx+2]; |
|
2190 |
__pixel = __grey / 10; /* 0 .. 255 */ |
|
2191 |
||
2192 |
__srcIdx += 3; |
|
2193 |
__outBits[__dstIdx] = __pixel; |
|
2194 |
__dstIdx++; |
|
2195 |
} |
|
2196 |
__srcIdx = __nextSrc; |
|
2197 |
__dstIdx = __nextDst; |
|
2198 |
} |
|
1932 | 2199 |
} else { |
7817 | 2200 |
bzero(errorArray1, (__w+2) * 2); |
2201 |
||
2202 |
__bitCnt = 8; |
|
2203 |
for (__y=0; __y<__h; __y++) { |
|
2204 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
2205 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
2206 |
||
2207 |
__byte = 0; |
|
2208 |
||
2209 |
__t = __errorArray; |
|
2210 |
__errorArray = __errorArray1; |
|
2211 |
__errorArray1 = __t; |
|
2212 |
bzero(errorArray1, (__w+2) * 2); |
|
2213 |
||
2214 |
for (__x=0; __x<__w; __x++) { |
|
2215 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
2216 |
+ (__bytes[__srcIdx+1] * 6) |
|
2217 |
+ __bytes[__srcIdx+2]; |
|
2218 |
__grey = __grey / 10; /* 0 .. 255 */ |
|
2219 |
||
2220 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
|
2221 |
__err = __greyMap2[__grey]; /* 0.. 255 - error) */ |
|
2222 |
__err += __errorArray[__x+1]; |
|
2223 |
||
2224 |
if (__err > 127) { /* dither says: next pixel */ |
|
2225 |
if ( __pixel != __greyLevels) |
|
2226 |
__pixel++; |
|
2227 |
__err = __err - 255; |
|
2228 |
} else { |
|
2229 |
} |
|
2230 |
if (__err) { |
|
2231 |
__e16 = __err >> 4; |
|
2232 |
__eR = __e16 * 7; /* 7/16 -> right pixel */ |
|
2233 |
__eRB = __e16 * 1; /* 1/16 -> right below */ |
|
2234 |
__eB = __e16 * 5; /* 5/16 -> below */ |
|
2235 |
__eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */ |
|
2236 |
||
2237 |
__errorArray [__x+1+1] += __eR; |
|
2238 |
__errorArray1[__x+1+1] += __eRB; |
|
2239 |
__errorArray1[__x+1 ] += __eB; |
|
2240 |
__errorArray1[__x+1-1] += __eLB; |
|
2241 |
} |
|
2242 |
||
2243 |
__srcIdx += 3; |
|
2244 |
||
2245 |
__byte = (__byte << __depth) | __pixel; |
|
2246 |
||
2247 |
__bitCnt = __bitCnt - __depth; |
|
2248 |
if (__bitCnt == 0) { |
|
2249 |
__outBits[__dstIdx] = __byte; |
|
2250 |
__dstIdx++; |
|
2251 |
__byte = 0; |
|
2252 |
__bitCnt = 8; |
|
2253 |
} |
|
2254 |
} |
|
2255 |
||
2256 |
if (__bitCnt != 8) { |
|
2257 |
__byte = __byte << __bitCnt; |
|
2258 |
__outBits[__dstIdx] = __byte; |
|
2259 |
__bitCnt = 8; |
|
2260 |
} |
|
2261 |
__srcIdx = __nextSrc; |
|
2262 |
__dstIdx = __nextDst; |
|
2263 |
} |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2264 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2265 |
%}. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2266 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2267 |
^ outBits |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2268 |
|
7817 | 2269 |
"Created: / 10-06-1996 / 13:28:22 / cg" |
2270 |
"Modified: / 10-06-1996 / 15:09:07 / cg" |
|
2271 |
"Modified: / 31-01-2017 / 12:39:31 / stefan" |
|
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2272 |
! |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2273 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2274 |
floydSteinbergDitheredMonochromeBits |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2275 |
"return the bitmap for a dithered monochrome bitmap from the image. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2276 |
Redefined to make use of knowing that pixels are 24 bit r/g/b" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2277 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2278 |
|
1779 | 2279 |
^ self floydSteinbergDitheredGrayBitsDepth:1 |
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2280 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2281 |
"Created: 10.6.1996 / 22:55:59 / cg" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2282 |
! |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
2283 |
|
1782 | 2284 |
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
810 | 2285 |
"return the bitmap for a dithered depth-bitmap from the image; |
2286 |
with a constant ditherMatrix, this can be used for thresholding. |
|
2287 |
Redefined to make use of knowing that pixels are 24-bit values." |
|
2288 |
||
4719 | 2289 |
|dH nDither v range bytes |
810 | 2290 |
greyMap1 greyMap2 greyLevels outBits |
2291 |
bytesPerOutRow "{Class: SmallInteger }" |
|
2292 |
bytesPerRow "{Class: SmallInteger }" |
|
2293 |
w "{Class: SmallInteger }" |
|
2294 |
h "{Class: SmallInteger }"| |
|
2295 |
||
2296 |
photometric ~~ #rgb ifTrue:[ |
|
4719 | 2297 |
self error:'invalid format'. |
2298 |
^ nil |
|
810 | 2299 |
]. |
2300 |
||
2301 |
nDither := ditherMatrix size. |
|
2302 |
dH := nDither / dW. |
|
2303 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2304 |
bytes := self bits. |
810 | 2305 |
w := width. |
2306 |
h := height. |
|
2307 |
||
2308 |
greyLevels := 1 bitShift:depth. |
|
2309 |
bytesPerRow := self bytesPerRow. |
|
2310 |
||
2311 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
2312 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2313 |
(outBits isNil or:[bytes isNil]) ifTrue:[ self error. ^ nil]. |
810 | 2314 |
|
2315 |
greyMap1 := Array new:256. |
|
2316 |
greyMap2 := Array new:256. |
|
2317 |
range := greyLevels-1. |
|
2318 |
1 to:256 do:[:i | |
|
4719 | 2319 |
v := (range / 255 * (i-1)). |
2320 |
greyMap1 at:i put:v. |
|
2321 |
greyMap2 at:i put:v. |
|
810 | 2322 |
]. |
2323 |
||
2324 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
4719 | 2325 |
0 |
2326 |
] ifFalse:[ |
|
2327 |
b truncated |
|
2328 |
] |
|
2329 |
]) asByteArray. |
|
2330 |
||
2331 |
greyMap2 := (greyMap2 collect:[:el | |
|
2332 |
el isNil ifTrue:[ |
|
2333 |
0 |
|
2334 |
] ifFalse:[ |
|
2335 |
((el - el truncated) "/ the error (0..1) |
|
2336 |
* nDither) rounded |
|
2337 |
]]) asByteArray. |
|
810 | 2338 |
%{ |
2339 |
int __dW = __intVal(dW); |
|
2340 |
int __dH = __intVal(dH); |
|
2341 |
int __byte; |
|
2342 |
int __nDither = __intVal(nDither); |
|
2343 |
int __dT, __dO; |
|
2344 |
int __depth = __intVal(depth); |
|
2345 |
int __dstIdx = 0; |
|
2346 |
int __srcIdx = 0; |
|
2347 |
int __bitCnt; |
|
2348 |
int __grey; |
|
2349 |
int __w = __intVal(w); |
|
2350 |
int __h = __intVal(h); |
|
2351 |
int __x; |
|
2352 |
int __y; |
|
2353 |
int __oX, __oY, __dY; |
|
2354 |
int __nextDst; |
|
2355 |
int __nextSrc; |
|
2356 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
2357 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
2358 |
int __pixel; |
|
2359 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
2360 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
810 | 2361 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2362 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
810 | 2363 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
2364 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
2365 |
||
2366 |
__oY = __dY = 0; |
|
2367 |
for (__y=0; __y<__h; __y++) { |
|
4719 | 2368 |
__nextDst = __dstIdx + __bytesPerOutRow; |
2369 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
2370 |
||
2371 |
__byte = 0; |
|
2372 |
__bitCnt = 8; |
|
2373 |
||
2374 |
__oX = 0; |
|
2375 |
||
2376 |
for (__x=0; __x<__w; __x++) { |
|
2377 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
2378 |
+ (__bytes[__srcIdx+1] * 6) |
|
2379 |
+ __bytes[__srcIdx+2]; |
|
2380 |
__grey = __grey / 10; /* 0 .. 255 */ |
|
2381 |
||
2382 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
|
2383 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
|
2384 |
__dT = __ditherMatrix[__dY + __oX]; |
|
2385 |
||
2386 |
if (__dO > __dT) /* dither says: next pixel */ |
|
2387 |
__pixel++; |
|
2388 |
||
2389 |
__srcIdx += 3; |
|
2390 |
||
2391 |
__oX++; |
|
2392 |
if (__oX == __dW) __oX = 0; |
|
2393 |
||
2394 |
__byte = (__byte << __depth) | __pixel; |
|
2395 |
||
2396 |
__bitCnt = __bitCnt - __depth; |
|
2397 |
if (__bitCnt == 0) { |
|
2398 |
__outBits[__dstIdx] = __byte; |
|
2399 |
__dstIdx++; |
|
2400 |
__byte = 0; |
|
2401 |
__bitCnt = 8; |
|
2402 |
} |
|
2403 |
} |
|
2404 |
||
2405 |
if (__bitCnt != 8) { |
|
2406 |
__byte = __byte << __bitCnt; |
|
2407 |
__outBits[__dstIdx] = __byte; |
|
2408 |
} |
|
2409 |
||
2410 |
__oY++; __dY += __dW; |
|
2411 |
if (__oY == __dH) { |
|
2412 |
__oY = 0; |
|
2413 |
__dY = 0; |
|
2414 |
} |
|
2415 |
||
2416 |
__srcIdx = __nextSrc; |
|
2417 |
__dstIdx = __nextDst; |
|
810 | 2418 |
} |
2419 |
%}. |
|
2420 |
||
2421 |
^ outBits |
|
2422 |
||
2423 |
" |
|
2424 |
|i| |
|
2425 |
||
2426 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
2427 |
i asOrderedDitheredMonochromeImage inspect. |
|
2428 |
i asOrderedDitheredDepth2GrayImage inspect. |
|
2429 |
i asOrderedDitheredDepth4GrayImage inspect. |
|
2430 |
i asOrderedDitheredDepth8GrayImage inspect. |
|
2431 |
" |
|
2432 |
||
2433 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
2434 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
808 | 2435 |
! |
2436 |
||
810 | 2437 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
2438 |
"return the dithered monochrome bits for the receiver image; |
|
2439 |
with a constant ditherMatrix, this can be used for thresholding. |
|
2440 |
Redefined to make use of knowing that pixels are 24-bit values." |
|
2441 |
||
4719 | 2442 |
|dH nDither bytes |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2443 |
monoBits |
810 | 2444 |
bytesPerMonoRow "{Class: SmallInteger }" |
2445 |
bytesPerRow "{Class: SmallInteger }" |
|
2446 |
w "{Class: SmallInteger }" |
|
2447 |
h "{Class: SmallInteger }"| |
|
2448 |
||
2449 |
photometric ~~ #rgb ifTrue:[ |
|
4719 | 2450 |
self error:'invalid format'. |
2451 |
^ nil |
|
810 | 2452 |
]. |
2453 |
||
2454 |
nDither := ditherMatrix size. |
|
2455 |
dH := nDither / dW. |
|
2456 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2457 |
bytes := self bits. |
810 | 2458 |
w := width. |
2459 |
h := height. |
|
2460 |
||
2461 |
bytesPerRow := self bytesPerRow. |
|
2462 |
||
2463 |
bytesPerMonoRow := w + 7 // 8. |
|
2464 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2465 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ self error. ^ nil]. |
810 | 2466 |
|
2467 |
%{ |
|
2468 |
int __dW = __intVal(dW); |
|
2469 |
int __dH = __intVal(dH); |
|
2470 |
int __byte; |
|
2471 |
int __nDither = __intVal(nDither); |
|
2472 |
int __dT; |
|
2473 |
int __dstIdx = 0; |
|
2474 |
int __srcIdx = 0; |
|
2475 |
int __bitCnt; |
|
2476 |
int __grey; |
|
2477 |
int __w = __intVal(w); |
|
2478 |
int __h = __intVal(h); |
|
2479 |
int __x; |
|
2480 |
int __y; |
|
2481 |
int __oX, __oY, __dY; |
|
2482 |
int __nextDst; |
|
2483 |
int __nextSrc; |
|
2484 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
2485 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
2486 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
2487 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
810 | 2488 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2489 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
810 | 2490 |
|
2491 |
__oY = __dY = 0; |
|
2492 |
for (__y=0; __y<__h; __y++) { |
|
4719 | 2493 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
2494 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
2495 |
||
2496 |
__byte = 0; |
|
2497 |
__bitCnt = 8; |
|
2498 |
||
2499 |
__oX = 0; |
|
2500 |
||
2501 |
for (__x=0; __x<__w; __x++) { |
|
2502 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
2503 |
+ (__bytes[__srcIdx+1] * 6) |
|
2504 |
+ __bytes[__srcIdx+2]; |
|
2505 |
__grey = __grey * (__nDither+1) / 2550; /* 0 .. nDither+1 */ |
|
2506 |
__srcIdx += 3; |
|
2507 |
||
2508 |
__dT = __ditherMatrix[__dY + __oX]; |
|
2509 |
||
2510 |
__oX++; |
|
2511 |
if (__oX == __dW) __oX = 0; |
|
2512 |
||
2513 |
__byte = __byte << 1; |
|
2514 |
if (__grey > __dT) { |
|
2515 |
__byte = __byte | 1; /* white */ |
|
2516 |
} |
|
2517 |
||
2518 |
__bitCnt--; |
|
2519 |
if (__bitCnt == 0) { |
|
2520 |
__monoBits[__dstIdx] = __byte; |
|
2521 |
__dstIdx++; |
|
2522 |
__byte = 0; |
|
2523 |
__bitCnt = 8; |
|
2524 |
} |
|
2525 |
} |
|
2526 |
||
2527 |
if (__bitCnt != 8) { |
|
2528 |
__byte = __byte << __bitCnt; |
|
2529 |
__monoBits[__dstIdx] = __byte; |
|
2530 |
} |
|
2531 |
||
2532 |
__oY++; __dY += __dW; |
|
2533 |
if (__oY == __dH) { |
|
2534 |
__oY = 0; |
|
2535 |
__dY = 0; |
|
2536 |
} |
|
2537 |
||
2538 |
__srcIdx = __nextSrc; |
|
2539 |
__dstIdx = __nextDst; |
|
810 | 2540 |
} |
2541 |
%}. |
|
2542 |
||
2543 |
^ monoBits |
|
2544 |
||
2545 |
" |
|
2546 |
|i f| |
|
2547 |
||
2548 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
2549 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
2550 |
" |
|
2551 |
||
2552 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
2553 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
2554 |
! |
|
2555 |
||
2556 |
threshold8BitGrayBits |
|
808 | 2557 |
"return the bits for an 8-bit grey image from the receiver. |
2558 |
Special code, since this is a common case." |
|
2559 |
||
2560 |
|greyBits |
|
2561 |
srcIndex "{ Class: SmallInteger }" |
|
2562 |
dstIndex "{ Class: SmallInteger }"| |
|
2563 |
||
2564 |
greyBits := ByteArray uninitializedNew:(width * height). |
|
2565 |
%{ |
|
2566 |
if ((__Class(__INST(bytes)) == ByteArray) |
|
2567 |
&& (__Class(greyBits) == ByteArray)) { |
|
7538 | 2568 |
unsigned char *srcPtr, *dstPtr; |
2569 |
int i; |
|
2570 |
||
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2571 |
srcPtr = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2572 |
dstPtr = __ByteArrayInstPtr(greyBits)->ba_element; |
808 | 2573 |
|
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2574 |
i = __intVal(__INST(height)) * __intVal(__INST(width)); |
808 | 2575 |
|
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2576 |
for (; i > 0; i--) { |
7538 | 2577 |
int __v; |
2578 |
||
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2579 |
__v = (srcPtr[0] * 3); /* 3*r + 6*g + b ; 0 .. 2550 */ |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2580 |
__v += (srcPtr[1] * 6); |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2581 |
__v += srcPtr[2]; |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2582 |
srcPtr += 3; |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2583 |
__v /= 10; /* 0..255 */ |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2584 |
*dstPtr++ = __v ; |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
2585 |
} |
808 | 2586 |
} |
2587 |
%}. |
|
2588 |
^ greyBits |
|
2589 |
||
1 | 2590 |
! ! |
2591 |
||
282 | 2592 |
!Depth24Image methodsFor:'enumerating'! |
1 | 2593 |
|
5142 | 2594 |
colorsAtX:x from:yLow to:yHigh do:aBlock |
2595 |
"perform aBlock for each pixel from y1 to y2 in col x. |
|
2596 |
The block is passed the color at each pixel. |
|
2597 |
This method allows slighly faster processing of an |
|
2598 |
image than using atX:y:, since some processing can be |
|
2599 |
avoided when going from pixel to pixel. However, for |
|
2600 |
real image processing, specialized methods should be written." |
|
2601 |
||
2602 |
|srcIndex "{ Class: SmallInteger }" |
|
2603 |
y1 "{ Class: SmallInteger }" |
|
2604 |
y2 "{ Class: SmallInteger }" |
|
2605 |
rVal "{ Class: SmallInteger }" |
|
2606 |
gVal "{ Class: SmallInteger }" |
|
2607 |
bVal "{ Class: SmallInteger }" |
|
2608 |
lastR lastG lastB lastColor bytes| |
|
2609 |
||
2610 |
photometric ~~ #rgb ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2611 |
^ super colorsAtX:x from:yLow to:yHigh do:aBlock. |
5142 | 2612 |
]. |
2613 |
||
2614 |
bytes := self bits. |
|
2615 |
||
2616 |
y1 := yLow. |
|
2617 |
y2 := yHigh. |
|
2618 |
||
2619 |
srcIndex := 1 + (((width * yLow) + x) * 3). |
|
2620 |
||
2621 |
y1 to:y2 do:[:y | |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2622 |
rVal := bytes at:(srcIndex). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2623 |
gVal := bytes at:(srcIndex + 1). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2624 |
bVal := bytes at:(srcIndex + 2). |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2625 |
srcIndex := srcIndex + width. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2626 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2627 |
(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2628 |
lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2629 |
lastR := rVal. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2630 |
lastG := gVal. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2631 |
lastB := bVal. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2632 |
]. |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
2633 |
aBlock value:y value:lastColor |
5142 | 2634 |
] |
2635 |
! |
|
2636 |
||
798 | 2637 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
282 | 2638 |
"perform aBlock for each pixel from x1 to x2 in row y. |
2639 |
The block is passed the color at each pixel. |
|
2640 |
This method allows slighly faster processing of an |
|
2641 |
image than using atX:y:, since some processing can be |
|
2642 |
avoided when going from pixel to pixel. However, for |
|
2643 |
real image processing, specialized methods should be written." |
|
1 | 2644 |
|
282 | 2645 |
|srcIndex "{ Class: SmallInteger }" |
2646 |
x1 "{ Class: SmallInteger }" |
|
2647 |
x2 "{ Class: SmallInteger }" |
|
2648 |
rVal "{ Class: SmallInteger }" |
|
2649 |
gVal "{ Class: SmallInteger }" |
|
2650 |
bVal "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2651 |
lastR lastG lastB lastColor bytes| |
282 | 2652 |
|
2653 |
photometric ~~ #rgb ifTrue:[ |
|
4719 | 2654 |
^ super colorsAtY:y from:xLow to:xHigh do:aBlock. |
282 | 2655 |
]. |
2656 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2657 |
bytes := self bits. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2658 |
|
282 | 2659 |
x1 := xLow. |
2660 |
x2 := xHigh. |
|
2661 |
||
2662 |
srcIndex := 1 + (((width * y) + x1) * 3). |
|
1 | 2663 |
|
282 | 2664 |
x1 to:x2 do:[:x | |
4719 | 2665 |
rVal := bytes at:(srcIndex). |
2666 |
gVal := bytes at:(srcIndex + 1). |
|
2667 |
bVal := bytes at:(srcIndex + 2). |
|
2668 |
srcIndex := srcIndex + 3. |
|
2669 |
||
2670 |
(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[ |
|
2671 |
lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal. |
|
2672 |
lastR := rVal. |
|
2673 |
lastG := gVal. |
|
2674 |
lastB := bVal. |
|
2675 |
]. |
|
2676 |
aBlock value:x value:lastColor |
|
282 | 2677 |
] |
798 | 2678 |
|
2190
ac8e972bb813
oops - bad color used in enumerator.
Claus Gittinger <cg@exept.de>
parents:
2067
diff
changeset
|
2679 |
"Created: / 7.6.1996 / 19:12:28 / cg" |
ac8e972bb813
oops - bad color used in enumerator.
Claus Gittinger <cg@exept.de>
parents:
2067
diff
changeset
|
2680 |
"Modified: / 27.7.1998 / 20:03:02 / cg" |
282 | 2681 |
! |
1 | 2682 |
|
798 | 2683 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
8121 | 2684 |
"WARNING: this enumerates pixel values which need photometric interpretation |
2685 |
Do not confuse with #rgbValuesAtY:from:to:do: |
|
2686 |
||
2687 |
Perform aBlock for each pixelValue from x1 to x2 in row y. |
|
2688 |
||
2689 |
Notice the difference between rgbValue and pixelValue: rgbValues are always |
|
2690 |
the rgb bytes; pixelvalues depend on the photometric interpretation, and may be |
|
2691 |
indices into a colormap or be non-byte-sized rgb values. |
|
2692 |
||
282 | 2693 |
The block is passed the pixelValue at each pixel. |
2694 |
This method allows slighly faster processing of an |
|
2695 |
image than using valueAtX:y:, since some processing can be |
|
2696 |
avoided when going from pixel to pixel. However, for |
|
2697 |
real image processing, specialized methods should be written. |
|
7278 | 2698 |
Notice that the pixelValue is the r/g/b value packed into an MSB integer |
2699 |
(r bitShift:16) bitOr:(g bitSHift:8) bitOr:b |
|
2700 |
i.e. r is the first byte, but high in the passed pixel value." |
|
282 | 2701 |
|
2702 |
|srcIndex "{ Class: SmallInteger }" |
|
2703 |
x1 "{ Class: SmallInteger }" |
|
2704 |
x2 "{ Class: SmallInteger }" |
|
2705 |
r "{ Class: SmallInteger }" |
|
2706 |
g "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2707 |
b "{ Class: SmallInteger }" |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2708 |
bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2709 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2710 |
bytes := self bits. |
282 | 2711 |
x1 := xLow. |
2712 |
x2 := xHigh. |
|
2713 |
||
2714 |
srcIndex := 1 + (((width * y) + x1) * 3). |
|
2715 |
||
2716 |
x1 to:x2 do:[:x | |
|
8121 | 2717 |
r := bytes at:(srcIndex). |
2718 |
g := bytes at:(srcIndex + 1). |
|
2719 |
b := bytes at:(srcIndex + 2). |
|
2720 |
srcIndex := srcIndex + 3. |
|
2721 |
aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b) |
|
282 | 2722 |
] |
798 | 2723 |
|
8121 | 2724 |
"Created: / 07-06-1996 / 19:09:40 / cg" |
2725 |
"Modified (comment): / 29-08-2017 / 14:53:14 / cg" |
|
7527 | 2726 |
! |
2727 |
||
2728 |
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock |
|
8121 | 2729 |
"WARNING: this enumerates pixel values which need photometric interpretation |
2730 |
Do not confuse with #rgbValuesAtY:from:to:do: |
|
2731 |
||
2732 |
Perform aBlock for each pixelValue in a rectangular area of the image. |
|
2733 |
||
2734 |
Notice the difference between rgbValue and pixelValue: rgbValues are always |
|
2735 |
the rgb bytes; pixelvalues depend on the photometric interpretation, and may be |
|
2736 |
indices into a colormap or be non-byte-sized rgb values. |
|
2737 |
||
7527 | 2738 |
The block is passed the pixelValue at each pixel. |
2739 |
This method allows slighly faster processing of an |
|
2740 |
image than using individual valueAtX:y: accesses, |
|
2741 |
since some processing can be avoided when going from pixel to pixel.. |
|
7530 | 2742 |
However, for real high performance image processing, specialized methods |
7527 | 2743 |
should be written which know how to deal with specific photometric interpretations." |
2744 |
||
2745 |
|srcIndex "{ Class: SmallInteger }" |
|
2746 |
srcNext "{ Class: SmallInteger }" |
|
2747 |
bytesPerRow "{ Class: SmallInteger }" |
|
2748 |
value "{ Class: SmallInteger }" |
|
2749 |
x1 "{ Class: SmallInteger }" |
|
2750 |
x2 "{ Class: SmallInteger }" |
|
2751 |
y1 "{ Class: SmallInteger }" |
|
2752 |
y2 "{ Class: SmallInteger }" |
|
2753 |
bytes| |
|
2754 |
||
2755 |
x1 := xStart. |
|
2756 |
x2 := xEnd. |
|
2757 |
y1 := yStart. |
|
2758 |
y2 := yEnd. |
|
2759 |
||
2760 |
srcIndex := (width * 3 * y1) + (x1 * 3) + 1 . |
|
2761 |
bytesPerRow := self bytesPerRow. |
|
2762 |
bytes := self bits. |
|
7528 | 2763 |
%{ |
2764 |
OBJFUNC codeVal; |
|
2765 |
||
2766 |
if (__bothSmallInteger(x1, x2) |
|
2767 |
&& __bothSmallInteger(y1, y2) |
|
2768 |
&& __bothSmallInteger(srcIndex, bytesPerRow) |
|
2769 |
&& __isByteArrayLike(bytes) |
|
2770 |
&& __isBlockLike(aBlock) |
|
2771 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(3)) |
|
2772 |
&& ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
|
2773 |
) { |
|
7549 | 2774 |
int c_x1 = __intVal(x1); |
2775 |
int c_x2 = __intVal(x2); |
|
2776 |
int c_y1 = __intVal(y1); |
|
2777 |
int c_y2 = __intVal(y2); |
|
2778 |
int c_w = __intVal(__INST(width)); |
|
2779 |
int c_h = __intVal(__INST(height)); |
|
2780 |
int c_srcIndex = __intVal(srcIndex)-1; |
|
2781 |
int c_bytesPerRow = __intVal(bytesPerRow); |
|
2782 |
int c_y, c_x; |
|
2783 |
OBJ c_rHome; |
|
2784 |
||
2785 |
c_rHome = __BlockInstPtr(aBlock)->b_home; |
|
2786 |
if ((c_rHome == nil) || (__qSpace(c_rHome) >= STACKSPACE)) { |
|
2787 |
if ((((unsigned)c_y1) < c_h) |
|
2788 |
&& (((unsigned)c_y2) < c_h) |
|
2789 |
&& (((unsigned)c_x1) < c_w) |
|
2790 |
&& (((unsigned)c_x2) < c_w)) { |
|
2791 |
unsigned char *c_bytes = (unsigned char*)__ByteArrayInstPtr(bytes)->ba_element; |
|
2792 |
||
2793 |
if ((c_srcIndex + (c_bytesPerRow * (c_y2-c_y1))) < __byteArraySize(bytes)) { |
|
2794 |
c_bytes += c_srcIndex; |
|
2795 |
for (c_y=c_y1; c_y<=c_y2; c_y++) { |
|
2796 |
unsigned char *c_next = c_bytes + c_bytesPerRow; |
|
2797 |
||
2798 |
for (c_x=c_x1; c_x<=c_x2; c_x++) { |
|
2799 |
int c_value; |
|
2800 |
||
2801 |
c_value = c_bytes[0]; |
|
2802 |
c_value = (c_value<<8) | c_bytes[1]; |
|
2803 |
c_value = (c_value<<8) | c_bytes[2]; |
|
2804 |
(*(__BlockInstPtr(aBlock)->b_code))(c_rHome, __mkSmallInteger(c_x), __mkSmallInteger(c_y), __mkSmallInteger(c_value)); |
|
2805 |
c_bytes += 3; |
|
2806 |
} |
|
2807 |
c_bytes = c_next; |
|
2808 |
} |
|
2809 |
RETURN(self); |
|
2810 |
} |
|
2811 |
} |
|
2812 |
} |
|
7528 | 2813 |
} |
2814 |
%}. |
|
7527 | 2815 |
|
2816 |
y1 to:y2 do:[:y | |
|
7549 | 2817 |
srcNext := srcIndex + bytesPerRow. |
2818 |
x1 to:x2 do:[:x | |
|
2819 |
value := bytes at:srcIndex. |
|
2820 |
value := (value bitShift:8) + (bytes at:srcIndex+1). |
|
2821 |
value := (value bitShift:8) + (bytes at:srcIndex+2). |
|
2822 |
srcIndex := srcIndex + 3. |
|
2823 |
||
2824 |
aBlock value:x value:y value:value |
|
2825 |
]. |
|
2826 |
srcIndex := srcNext. |
|
7527 | 2827 |
]. |
2828 |
||
8121 | 2829 |
"Created: / 11-07-1996 / 20:08:11 / cg" |
2830 |
"Modified (comment): / 29-08-2017 / 14:45:54 / cg" |
|
282 | 2831 |
! ! |
2832 |
||
1767 | 2833 |
!Depth24Image methodsFor:'image manipulations'! |
2834 |
||
7535 | 2835 |
easyRotateBitsInto:destinationImage angle:degrees |
7538 | 2836 |
"tuned helper for rotation - does the actual pixel shuffling, by degrees clockwise. |
2837 |
Here, only 90, 180 and 270 degrees are implemented. |
|
7535 | 2838 |
Hard angles are done in #hardRotate:. |
2839 |
The code here a tuned version of the inherited for more performance" |
|
2840 |
||
2841 |
|srcBytesPerRow dstBytesPerRow |
|
2842 |
srcWidth srcHeight |
|
2843 |
dstWidth dstHeight |
|
2844 |
srcBytes dstBytes| |
|
2845 |
||
2846 |
srcBytesPerRow := self bytesPerRow. |
|
2847 |
srcBytes := self bits. |
|
2848 |
srcWidth := width. |
|
2849 |
srcHeight := height. |
|
2850 |
||
2851 |
dstBytesPerRow := destinationImage bytesPerRow. |
|
2852 |
dstBytes := destinationImage bits. |
|
2853 |
dstWidth := destinationImage width. |
|
2854 |
dstHeight := destinationImage height. |
|
2855 |
%{ |
|
2856 |
if (__bothSmallInteger(srcWidth, srcHeight) |
|
2857 |
&& __bothSmallInteger(dstWidth, dstHeight) |
|
2858 |
&& __bothSmallInteger(dstBytesPerRow, srcBytesPerRow) |
|
2859 |
&& __isByteArrayLike(srcBytes) |
|
2860 |
&& __isByteArrayLike(dstBytes) |
|
2861 |
) { |
|
7538 | 2862 |
int c_srcW = __intVal(srcWidth); |
2863 |
int c_srcH = __intVal(srcHeight); |
|
2864 |
int c_dstW = __intVal(dstWidth); |
|
2865 |
int c_dstH = __intVal(dstHeight); |
|
2866 |
int c_srcBytesPerRow = __intVal(srcBytesPerRow); |
|
2867 |
int c_dstBytesPerRow = __intVal(dstBytesPerRow); |
|
2868 |
int c_srcW4 = c_srcW-4; |
|
2869 |
||
2870 |
// I tried three versions here; |
|
2871 |
// a) compute dstX/y inside the loop, |
|
2872 |
// b) precompute a transformation matrix and compute inside the loop w.o conditional branches |
|
2873 |
// (i.e. x*Mx + y*My...) |
|
2874 |
// c) precompute ptr-delta and use those to step to next destination pixel. |
|
2875 |
||
2876 |
// the funny result: |
|
2877 |
// all show roughly the same speed on a modern CPU. |
|
2878 |
// So the whole thing is mostly limited by memory-bandwidth, |
|
2879 |
// and there is not much to do, unless we move to a better memory fetch/store |
|
2880 |
// (eg. mmx or similar vector stuff) |
|
2881 |
// However, on slower cpus, algo c shpuld perform better, as it does not need multiplications in the loop. |
|
2882 |
// The version below orecomputes the delta, so it should run fast on older CPUs as well. |
|
2883 |
||
2884 |
{ |
|
2885 |
unsigned char *c_srcBytes = (unsigned char*)__ByteArrayInstPtr(srcBytes)->ba_element; |
|
2886 |
unsigned char *c_dstBytes = (unsigned char*)__ByteArrayInstPtr(dstBytes)->ba_element; |
|
2887 |
||
2888 |
int c_dstNextRowOffset; |
|
2889 |
int c_dstNextColOffset; |
|
2890 |
||
2891 |
if (degrees == __mkSmallInteger(90)) { |
|
2892 |
// destinationImage pixelAtX:(h-row) y:col put:pixel |
|
2893 |
c_dstNextRowOffset = -3; // going to previous column |
|
2894 |
c_dstNextColOffset = c_dstBytesPerRow; // going to next row |
|
2895 |
c_dstBytes += (c_dstW-1)*3; // start in the upper-right of dest |
|
2896 |
} else if (degrees == __mkSmallInteger(180)) { |
|
2897 |
// destinationImage pixelAtX:(w-col) y:(h-row) put:pixel |
|
2898 |
c_dstNextRowOffset = -c_dstBytesPerRow; // going to previous row |
|
2899 |
c_dstNextColOffset = -3; // going to prev col |
|
2900 |
c_dstBytes += (c_dstH-1)*c_dstBytesPerRow+(c_dstW-1)*3; // start in the lower-right of dest |
|
2901 |
} else { |
|
2902 |
// destinationImage pixelAtX:row y:(w-col) put:pixel |
|
2903 |
c_dstNextRowOffset = 3; // going to next col |
|
2904 |
c_dstNextColOffset = -c_dstBytesPerRow; // going to prev row |
|
2905 |
c_dstBytes += (c_dstH-1)*c_dstBytesPerRow; // start in the lower-left of dest |
|
2906 |
} |
|
2907 |
||
2908 |
if ((c_srcBytesPerRow * c_srcH) <= __byteArraySize(srcBytes)) { |
|
2909 |
int c_y; |
|
2910 |
||
2911 |
for (c_y=0; c_y<c_srcH; c_y++) { |
|
2912 |
unsigned char *c_srcNext = c_srcBytes + c_srcBytesPerRow; |
|
2913 |
unsigned char *c_dstNext = c_dstBytes + c_dstNextRowOffset; |
|
2914 |
int c_x; |
|
2915 |
||
2916 |
c_x = 0; |
|
7535 | 2917 |
#if 1 |
7538 | 2918 |
if (sizeof(int) == 4) { |
2919 |
for (c_x = 0; c_x < c_srcW4; c_x += 4) { |
|
2920 |
int c_value1, c_value2, c_value3; |
|
2921 |
||
2922 |
c_value1 = ((int *)c_srcBytes)[0]; |
|
2923 |
c_value2 = ((int *)c_srcBytes)[1]; |
|
2924 |
c_value3 = ((int *)c_srcBytes)[2]; |
|
2925 |
||
2926 |
c_dstBytes[0] = (c_value1) & 0xFF; |
|
2927 |
c_dstBytes[1] = (c_value1>>8) & 0xFF; |
|
2928 |
c_dstBytes[2] = (c_value1>>16) &0xFF; |
|
2929 |
c_dstBytes += c_dstNextColOffset; |
|
2930 |
||
2931 |
c_dstBytes[0] = (c_value1>>24) & 0xFF; |
|
2932 |
c_dstBytes[1] = (c_value2) & 0xFF; |
|
2933 |
c_dstBytes[2] = (c_value2>>8) &0xFF; |
|
2934 |
c_dstBytes += c_dstNextColOffset; |
|
2935 |
||
2936 |
c_dstBytes[0] = (c_value2>>16) & 0xFF; |
|
2937 |
c_dstBytes[1] = (c_value2>>24) & 0xFF; |
|
2938 |
c_dstBytes[2] = (c_value3) &0xFF; |
|
2939 |
c_dstBytes += c_dstNextColOffset; |
|
2940 |
||
2941 |
c_dstBytes[0] = (c_value3>>8) & 0xFF; |
|
2942 |
c_dstBytes[1] = (c_value3>>16) & 0xFF; |
|
2943 |
c_dstBytes[2] = (c_value3>>24) &0xFF; |
|
2944 |
c_dstBytes += c_dstNextColOffset; |
|
2945 |
||
2946 |
c_srcBytes += (3*4); |
|
2947 |
} |
|
2948 |
} |
|
7535 | 2949 |
#endif |
7538 | 2950 |
for (; c_x < c_srcW; c_x++) { |
2951 |
int c_rValue, c_gValue, c_bValue; |
|
2952 |
||
2953 |
c_rValue = c_srcBytes[0]; |
|
2954 |
c_gValue = c_srcBytes[1]; |
|
2955 |
c_bValue = c_srcBytes[2]; |
|
2956 |
||
2957 |
c_dstBytes[0] = c_rValue; |
|
2958 |
c_dstBytes[1] = c_gValue; |
|
2959 |
c_dstBytes[2] = c_bValue; |
|
2960 |
||
2961 |
c_srcBytes += 3; |
|
2962 |
c_dstBytes += c_dstNextColOffset; |
|
2963 |
} |
|
2964 |
c_srcBytes = c_srcNext; |
|
2965 |
c_dstBytes = c_dstNext; |
|
2966 |
} |
|
2967 |
RETURN(self); |
|
2968 |
} |
|
2969 |
} |
|
7535 | 2970 |
} |
2971 |
%}. |
|
2972 |
self breakPoint:#cg. |
|
2973 |
super easyRotateBitsInto:destinationImage angle:degrees |
|
2974 |
||
2975 |
" |
|
2976 |
|i| |
|
2977 |
||
2978 |
i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'. |
|
2979 |
i := Depth24Image fromImage:i. |
|
2980 |
i inspect. |
|
2981 |
(i rotated:45) inspect. |
|
2982 |
(i rotated:90) inspect. |
|
2983 |
(i rotated:180) inspect. |
|
2984 |
(i rotated:270) inspect. |
|
2985 |
" |
|
2986 |
! |
|
2987 |
||
1767 | 2988 |
negative |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2989 |
|bytes index newImage newBytes nBytes r g b| |
1767 | 2990 |
|
2991 |
photometric ~~ #rgb ifTrue:[ |
|
4719 | 2992 |
^ super negative. |
1767 | 2993 |
]. |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2994 |
bytes := self bits. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
2995 |
|
1767 | 2996 |
newImage := self copy. |
2997 |
nBytes := bytes size. |
|
2998 |
newImage bits:(newBytes := ByteArray new:nBytes). |
|
2999 |
index := 1. |
|
3000 |
[index < nBytes] whileTrue:[ |
|
4719 | 3001 |
r := bytes at:index. |
3002 |
newBytes at:index put:(255-r). |
|
3003 |
index := index + 1. |
|
3004 |
g := bytes at:index. |
|
3005 |
newBytes at:index put:(255-g). |
|
3006 |
index := index + 1. |
|
3007 |
b := bytes at:index. |
|
3008 |
newBytes at:index put:(255-b). |
|
3009 |
index := index + 1. |
|
1767 | 3010 |
]. |
3011 |
^ newImage |
|
3012 |
||
3013 |
"Modified: 23.6.1997 / 09:57:19 / cg" |
|
3014 |
! ! |
|
3015 |
||
4760 | 3016 |
!Depth24Image methodsFor:'initialization'! |
3017 |
||
3018 |
initialize |
|
3019 |
super initialize. |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3020 |
samplesPerPixel := 3. |
7817 | 3021 |
bitsPerSample := #[8 8 8]. |
4760 | 3022 |
|
3023 |
"Created: / 27-05-2007 / 14:09:34 / cg" |
|
7817 | 3024 |
"Modified: / 30-01-2017 / 18:29:01 / stefan" |
4760 | 3025 |
! ! |
3026 |
||
282 | 3027 |
!Depth24Image methodsFor:'magnification'! |
1 | 3028 |
|
8133 | 3029 |
hardAntiAliasedMagnifiedBy:scaleArg |
1738 | 3030 |
"return a new image magnified by scalePoint, aPoint. |
6795 | 3031 |
This interpolates pixels and is therefore much slower, |
3032 |
but generates nicer looking magnifications." |
|
1738 | 3033 |
|
8133 | 3034 |
|scalePoint mX |
4719 | 3035 |
mY |
1738 | 3036 |
newWidth "{ Class: SmallInteger }" |
3037 |
newHeight "{ Class: SmallInteger }" |
|
3038 |
w "{ Class: SmallInteger }" |
|
3039 |
h "{ Class: SmallInteger }" |
|
3040 |
newImage newBits bitsPerPixel newBytesPerRow newMask |
|
4719 | 3041 |
value |
1738 | 3042 |
srcRow pixelArray| |
3043 |
||
8133 | 3044 |
scalePoint := scaleArg asPoint. |
1738 | 3045 |
mX := scalePoint x. |
3046 |
mY := scalePoint y. |
|
3047 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
|
3048 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
3049 |
||
3050 |
newWidth := (width * mX) truncated. |
|
3051 |
newHeight := (height * mY) truncated. |
|
3052 |
||
3053 |
bitsPerPixel := self depth. |
|
3054 |
newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8. |
|
3055 |
newBits := ByteArray new: "uninitializedNew:" (newBytesPerRow * newHeight). |
|
2064 | 3056 |
newBits isNil ifTrue:[ |
8133 | 3057 |
'Depth24Image [warning]: failed to allocate byteArray for image bits' errorPrintCR. |
3058 |
^ nil |
|
2064 | 3059 |
]. |
1738 | 3060 |
|
3061 |
mask notNil ifTrue:[ |
|
8133 | 3062 |
newMask := (mask magnifiedBy:scalePoint) |
1738 | 3063 |
]. |
3064 |
||
3065 |
newImage := self species new. |
|
4719 | 3066 |
newImage |
8133 | 3067 |
width:newWidth |
3068 |
height:newHeight |
|
3069 |
photometric:photometric |
|
3070 |
samplesPerPixel:samplesPerPixel |
|
3071 |
bitsPerSample:bitsPerSample |
|
3072 |
colorMap:nil |
|
3073 |
bits:newBits |
|
3074 |
mask:newMask. |
|
1738 | 3075 |
|
3076 |
mY := mY asFloat. |
|
3077 |
mX := mX asFloat. |
|
3078 |
||
3079 |
%{ |
|
3080 |
REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBits)->ba_element; |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3081 |
unsigned char *_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
1738 | 3082 |
unsigned char *_srcRowP, *sP; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3083 |
int _width3 = __intVal(__INST(width)) * 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3084 |
int _oldW = __intVal(__INST(width)) - 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3085 |
int _oldH = __intVal(__INST(height)) - 1; |
1738 | 3086 |
int _w = __intVal(newWidth) - 1; |
3087 |
int _h = __intVal(newHeight) - 1; |
|
3088 |
int _row, _col; |
|
3089 |
double _mX = __floatVal(mX); |
|
3090 |
double _mY = __floatVal(mY); |
|
3091 |
||
3092 |
for (_row = 0; _row <= _h; _row++) { |
|
8133 | 3093 |
double _srcY; |
3094 |
double _dY; |
|
3095 |
int _sR; |
|
3096 |
||
3097 |
_srcY = ((double)_row / _mY); |
|
3098 |
_sR = (int)_srcY; |
|
3099 |
_dY = _srcY - ((double)_sR); |
|
3100 |
_srcRowP = _srcP + (_width3 * _sR); |
|
3101 |
||
3102 |
for (_col = 0; _col <= _w; _col++) { |
|
3103 |
unsigned int rHere, gHere, bHere; |
|
3104 |
unsigned int rRight, gRight, bRight; |
|
3105 |
unsigned int rRightBelow, gRightBelow, bRightBelow; |
|
3106 |
unsigned int rBelow, gBelow, bBelow; |
|
3107 |
unsigned int _r, _g, _b; |
|
3108 |
double wHere, wRight, wRightBelow, wBelow, sumW; |
|
3109 |
double _srcX; |
|
3110 |
double _dX; |
|
3111 |
int _sC; |
|
3112 |
||
3113 |
_srcX = ((double)_col / _mX); |
|
3114 |
_sC = (int)_srcX; |
|
3115 |
_dX = _srcX - ((double)_sC); |
|
3116 |
sP = _srcRowP + (_sC * 3); |
|
3117 |
||
3118 |
rHere = sP[0]; |
|
3119 |
gHere = sP[1]; |
|
3120 |
bHere = sP[2]; |
|
3121 |
||
3122 |
if (_sC < _oldW) { |
|
3123 |
rRight = sP[3]; |
|
3124 |
gRight = sP[4]; |
|
3125 |
bRight = sP[5]; |
|
3126 |
||
3127 |
if (_sR < _oldH) { |
|
3128 |
rBelow = sP[0+_width3]; |
|
3129 |
gBelow = sP[1+_width3]; |
|
3130 |
bBelow = sP[2+_width3]; |
|
3131 |
rRightBelow = sP[3+_width3]; |
|
3132 |
gRightBelow = sP[4+_width3]; |
|
3133 |
bRightBelow = sP[5+_width3]; |
|
3134 |
} else { |
|
3135 |
rRightBelow = rHere; |
|
3136 |
gRightBelow = gHere; |
|
3137 |
bRightBelow = bHere; |
|
3138 |
rBelow = rHere; |
|
3139 |
gBelow = gHere; |
|
3140 |
bBelow = bHere; |
|
3141 |
} |
|
3142 |
} else { |
|
3143 |
rRight = rRightBelow = rHere; |
|
3144 |
gRight = gRightBelow = gHere; |
|
3145 |
bRight = bRightBelow = bHere; |
|
3146 |
if (_sR < _oldH) { |
|
3147 |
rBelow = sP[0+_width3]; |
|
3148 |
gBelow = sP[1+_width3]; |
|
3149 |
bBelow = sP[2+_width3]; |
|
3150 |
} else { |
|
3151 |
rBelow = rHere; |
|
3152 |
gBelow = gHere; |
|
3153 |
bBelow = bHere; |
|
3154 |
} |
|
3155 |
} |
|
3156 |
||
3157 |
wHere = (1.0 - _dX) * (1.0 - _dY); |
|
3158 |
wRight = _dX * (1.0 - _dY); |
|
3159 |
wBelow = _dY * (1.0 - _dX); |
|
3160 |
wRightBelow = _dX * _dY; |
|
3161 |
sumW = wHere + wRight + wBelow + wRightBelow; |
|
3162 |
||
3163 |
_r = ((rHere * wHere) + (rRight * wRight) + (rBelow * wBelow) + (rRightBelow * wRightBelow)) / sumW; |
|
3164 |
_g = ((gHere * wHere) + (gRight * wRight) + (gBelow * wBelow) + (gRightBelow * wRightBelow)) / sumW; |
|
3165 |
_b = ((bHere * wHere) + (bRight * wRight) + (bBelow * wBelow) + (bRightBelow * wRightBelow)) / sumW; |
|
3166 |
||
3167 |
_dstP[0] = _r; |
|
3168 |
_dstP[1] = _g; |
|
3169 |
_dstP[2] = _b; |
|
3170 |
||
3171 |
_dstP += 3; |
|
3172 |
} |
|
1738 | 3173 |
} |
3174 |
%}. |
|
3175 |
||
3176 |
^ newImage |
|
3177 |
||
3178 |
" |
|
3179 |
|i| |
|
3180 |
i := Image fromFile:'bitmaps/gifImages/garfield.gif'. |
|
3181 |
i hardAntiAliasedMagnifiedBy:2@2 |
|
3182 |
" |
|
3183 |
" |
|
3184 |
|i| |
|
3185 |
i := Depth24Image width:3 height:3 fromArray:#[ 0 0 0 0 0 0 0 0 0 |
|
8133 | 3186 |
0 0 0 255 255 255 0 0 0 |
3187 |
0 0 0 0 0 0 0 0 0]. |
|
1738 | 3188 |
i hardAntiAliasedMagnifiedBy:8@8 |
3189 |
" |
|
3190 |
||
8133 | 3191 |
"Created: / 02-06-1997 / 13:18:53 / cg" |
3192 |
"Modified: / 30-08-2017 / 13:35:20 / cg" |
|
1738 | 3193 |
! |
3194 |
||
8133 | 3195 |
hardMagnifiedBy:scaleArg |
1577 | 3196 |
"return a new image magnified by scalePoint, aPoint. |
8133 | 3197 |
This is the general magnification method, handling non-integral values. |
3198 |
It is slower than the integral magnification method. |
|
3199 |
||
3200 |
Notice: this is a naive algorithm, which simply samples the pixel value |
|
3201 |
at the corresponding original pixel's point, without taking neighbors into |
|
3202 |
consideration (i.e. it does not compute an average of those pixels). |
|
3203 |
As a consequence, this will generate bad shrunk images when the original contains |
|
3204 |
sharp lines." |
|
3205 |
||
3206 |
|scalePoint mX mY |
|
1 | 3207 |
newWidth "{ Class: SmallInteger }" |
3208 |
newHeight "{ Class: SmallInteger }" |
|
3209 |
w "{ Class: SmallInteger }" |
|
3210 |
h "{ Class: SmallInteger }" |
|
8133 | 3211 |
newImage newBytes newMask |
1 | 3212 |
value "{ Class: SmallInteger }" |
3213 |
srcRowIdx "{ Class: SmallInteger }" |
|
3214 |
srcIndex "{ Class: SmallInteger }" |
|
8133 | 3215 |
dstIndex "{ Class: SmallInteger }"| |
3216 |
||
3217 |
scalePoint := scaleArg asPoint. |
|
1577 | 3218 |
mX := scalePoint x. |
3219 |
mY := scalePoint y. |
|
1 | 3220 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
3221 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
3222 |
||
3223 |
newWidth := (width * mX) truncated. |
|
3224 |
newHeight := (height * mY) truncated. |
|
3225 |
newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight). |
|
3226 |
||
1577 | 3227 |
mask notNil ifTrue:[ |
7817 | 3228 |
newMask := (mask magnifiedBy:scalePoint) |
1577 | 3229 |
]. |
3230 |
||
1 | 3231 |
newImage := self species new. |
4719 | 3232 |
newImage |
8133 | 3233 |
width:newWidth height:newHeight photometric:photometric |
3234 |
samplesPerPixel:samplesPerPixel bitsPerSample:#[8 8 8] |
|
3235 |
colorMap:nil |
|
3236 |
bits:newBytes mask:newMask. |
|
1 | 3237 |
|
3238 |
"walk over destination image fetching pixels from source image" |
|
3239 |
||
3240 |
mY := mY asFloat. |
|
3241 |
mX := mX asFloat. |
|
3242 |
%{ |
|
2042
58c0228331bb
single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents:
1999
diff
changeset
|
3243 |
REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBytes)->ba_element; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3244 |
unsigned char *_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
1 | 3245 |
unsigned char *_srcRowP, *sP; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3246 |
int _width3 = __intVal(__INST(width)) * 3; |
2044
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
3247 |
int _w = __intVal(newWidth) - 1; |
9ea84b4ba249
more single-underline macros
Claus Gittinger <cg@exept.de>
parents:
2042
diff
changeset
|
3248 |
int _h = __intVal(newHeight) - 1; |
1 | 3249 |
int _row, _col; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3250 |
double _mX = __floatVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3251 |
double _mY = __floatVal(mY); |
1 | 3252 |
|
3253 |
for (_row = 0; _row <= _h; _row++) { |
|
7817 | 3254 |
_srcRowP = _srcP + (_width3 * (int)((double)_row / _mY)); |
3255 |
for (_col = 0; _col <= _w; _col++) { |
|
3256 |
sP = _srcRowP + (((int)((double)_col / _mX)) * 3); |
|
3257 |
_dstP[0] = sP[0]; |
|
3258 |
_dstP[1] = sP[1]; |
|
3259 |
_dstP[2] = sP[2]; |
|
3260 |
_dstP += 3; |
|
3261 |
} |
|
1 | 3262 |
} |
3263 |
%} |
|
3264 |
. |
|
81 | 3265 |
" the above C-code is equivalent to: |
3266 |
||
1 | 3267 |
dstIndex := 1. |
3268 |
w := newWidth - 1. |
|
3269 |
h := newHeight - 1. |
|
3270 |
0 to:h do:[:row | |
|
7817 | 3271 |
srcRowIdx := (width * 3 * (row // mY)) + 1. |
3272 |
0 to:w do:[:col | |
|
3273 |
srcIndex := srcRowIdx + ((col // mX) * 3). |
|
3274 |
value := bytes at:srcIndex. |
|
3275 |
newBytes at:dstIndex put:value. |
|
3276 |
value := bytes at:(srcIndex + 1). |
|
3277 |
newBytes at:(dstIndex + 1) put:value. |
|
3278 |
value := bytes at:(srcIndex + 2). |
|
3279 |
newBytes at:(dstIndex + 2) put:value. |
|
3280 |
dstIndex := dstIndex + 3 |
|
3281 |
] |
|
1 | 3282 |
]. |
3283 |
" |
|
3284 |
^ newImage |
|
7923 | 3285 |
|
8133 | 3286 |
"Modified: / 30-08-2017 / 13:33:30 / cg" |
282 | 3287 |
! |
3288 |
||
3289 |
magnifyRowFrom:srcBytes offset:srcStart |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3290 |
into:dstBytes offset:dstStart factor:mX |
282 | 3291 |
|
3292 |
"magnify a single pixel row - can only magnify by integer factors" |
|
3293 |
||
3294 |
%{ |
|
3295 |
unsigned char *srcP, *dstP; |
|
3296 |
int _mag; |
|
3297 |
REGISTER int i; |
|
3298 |
REGISTER unsigned char byte1, byte2, byte3; |
|
3299 |
int _pixels; |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3300 |
OBJ w = __INST(width); |
282 | 3301 |
|
3302 |
if (__bothSmallInteger(srcStart, dstStart) |
|
3303 |
&& __bothSmallInteger(w, mX) |
|
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
3304 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3305 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3306 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3307 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3308 |
_pixels = __intVal(w); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3309 |
|
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3310 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3311 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3312 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3313 |
byte3 = *(srcP+2); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3314 |
srcP += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3315 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3316 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3317 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3318 |
*(dstP+2) = byte3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3319 |
dstP += 3; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3320 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3321 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3322 |
RETURN (self); |
282 | 3323 |
} |
3842 | 3324 |
%}. |
4719 | 3325 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3326 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
6038
diff
changeset
|
3327 |
into:dstBytes offset:dstStart factor:mX |
1 | 3328 |
! ! |
282 | 3329 |
|
3330 |
!Depth24Image methodsFor:'queries'! |
|
3331 |
||
3332 |
bitsPerPixel |
|
3333 |
"return the number of bits per pixel" |
|
3334 |
||
3335 |
^ 24 |
|
3336 |
! |
|
3337 |
||
3338 |
bitsPerRow |
|
3339 |
"return the number of bits in one scanline of the image" |
|
3340 |
||
3868 | 3341 |
^ width * 24 |
282 | 3342 |
! |
3343 |
||
3344 |
bitsPerSample |
|
3345 |
"return the number of bits per sample. |
|
3346 |
The return value is an array of bits-per-plane." |
|
3347 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
3348 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
7817 | 3349 |
^ #[8 8 8] |
3350 |
||
3351 |
"Modified: / 10-06-1996 / 18:02:33 / cg" |
|
3352 |
"Modified: / 30-01-2017 / 18:27:45 / stefan" |
|
282 | 3353 |
! |
3354 |
||
805 | 3355 |
blueBitsOf:pixel |
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3356 |
"given a pixel-value, return the blue component as byteValue (0..255)" |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3357 |
|
8325 | 3358 |
photometric == #rgb ifTrue:[ |
3359 |
^ pixel bitAnd:16rFF. |
|
3360 |
]. |
|
3361 |
^ super blueBitsOf:pixel. |
|
805 | 3362 |
|
3363 |
"Created: 8.6.1996 / 09:56:20 / cg" |
|
3364 |
! |
|
3365 |
||
3366 |
blueComponentOf:pixel |
|
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3367 |
"given a pixel-value, return the blue component in percent (0..100)" |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3368 |
|
805 | 3369 |
^ (100.0 / 255.0) * (pixel bitAnd:16rFF) |
3370 |
||
3371 |
"Created: 8.6.1996 / 08:42:44 / cg" |
|
3372 |
"Modified: 8.6.1996 / 09:57:41 / cg" |
|
3373 |
! |
|
3374 |
||
3490 | 3375 |
blueMaskForPixelValue |
3376 |
"return the mask used with translation from pixelValues to blueBits" |
|
3377 |
||
3378 |
^ 16rFF |
|
3379 |
! |
|
3380 |
||
3381 |
blueShiftForPixelValue |
|
3382 |
"return the shift amount used with translation from pixelValues to blueBits" |
|
3383 |
||
3384 |
^ 0 |
|
3385 |
! |
|
3386 |
||
282 | 3387 |
bytesPerRow |
3388 |
"return the number of bytes in one scanline of the image" |
|
3389 |
||
3390 |
^ width * 3 |
|
3391 |
! |
|
3392 |
||
805 | 3393 |
greenBitsOf:pixel |
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3394 |
"given a pixel-value, return the green component as byteValue (0..255)" |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3395 |
|
8325 | 3396 |
photometric == #rgb ifTrue:[ |
3397 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
3398 |
]. |
|
3399 |
^ super greenBitsOf:pixel. |
|
805 | 3400 |
|
3401 |
"Modified: 8.6.1996 / 08:56:28 / cg" |
|
3402 |
"Created: 8.6.1996 / 09:56:30 / cg" |
|
3403 |
! |
|
3404 |
||
3405 |
greenComponentOf:pixel |
|
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3406 |
"given a pixel-value, return the green component in percent (0..100)" |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3407 |
|
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3408 |
^ (100.0 / 255.0) * ((pixel bitShift:-8) bitAnd:16rFF). |
805 | 3409 |
|
3410 |
"Created: 8.6.1996 / 08:42:37 / cg" |
|
3411 |
"Modified: 8.6.1996 / 09:57:32 / cg" |
|
3412 |
! |
|
3413 |
||
3490 | 3414 |
greenMaskForPixelValue |
3415 |
"return the mask used with translation from pixelValues to redBits" |
|
3416 |
||
3417 |
^ 16rFF |
|
3418 |
! |
|
3419 |
||
3420 |
greenShiftForPixelValue |
|
3421 |
"return the shift amount used with translation from pixelValues to greenBits" |
|
3422 |
||
3423 |
^ -8 |
|
3424 |
! |
|
3425 |
||
8083 | 3426 |
numAlphaBits |
3427 |
^ 0 |
|
3428 |
||
3429 |
"Created: / 22-08-2017 / 17:41:07 / cg" |
|
3430 |
! |
|
3431 |
||
3432 |
numBlueBits |
|
3433 |
^ 8 |
|
3434 |
||
3435 |
"Created: / 22-08-2017 / 17:41:19 / cg" |
|
3436 |
! |
|
3437 |
||
3438 |
numGreenBits |
|
3439 |
^ 8 |
|
3440 |
||
3441 |
"Created: / 22-08-2017 / 17:41:15 / cg" |
|
3442 |
! |
|
3443 |
||
3444 |
numRedBits |
|
3445 |
^ 8 |
|
3446 |
||
3447 |
"Created: / 22-08-2017 / 17:41:12 / cg" |
|
3448 |
! |
|
3449 |
||
805 | 3450 |
redBitsOf:pixel |
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3451 |
"given a pixel-value, return the red component as byteValue (0..255)" |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3452 |
|
8325 | 3453 |
photometric == #rgb ifTrue:[ |
3454 |
^ ((pixel>>16) bitAnd:16rFF). |
|
3455 |
]. |
|
3456 |
^ super redBitsOf:pixel. |
|
805 | 3457 |
|
3458 |
"Modified: 8.6.1996 / 08:56:31 / cg" |
|
3459 |
"Created: 8.6.1996 / 09:56:39 / cg" |
|
3460 |
! |
|
3461 |
||
3462 |
redComponentOf:pixel |
|
2301
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3463 |
"given a pixel-value, return the red component in percent (0..100)" |
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3464 |
|
60f9cf7dd066
comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents:
2190
diff
changeset
|
3465 |
^ (100.0 / 255.0) * ((pixel bitShift:-16) bitAnd:16rFF). |
805 | 3466 |
|
3467 |
"Created: 8.6.1996 / 08:42:25 / cg" |
|
3468 |
"Modified: 8.6.1996 / 09:57:23 / cg" |
|
3469 |
! |
|
3470 |
||
3490 | 3471 |
redMaskForPixelValue |
3472 |
"return the mask used with translation from pixelValues to redBits" |
|
3473 |
||
3474 |
^ 16rFF |
|
3475 |
! |
|
3476 |
||
3477 |
redShiftForPixelValue |
|
3478 |
"return the shift amount used with translation from pixelValues to redBits" |
|
3479 |
||
3480 |
^ -16 |
|
3481 |
! |
|
3482 |
||
4118 | 3483 |
rgbFromValue:pixelValue |
8325 | 3484 |
"given a pixel value, return the corresponding 24bit rgbValue |
3485 |
(rrggbb, red is MSB)." |
|
4118 | 3486 |
|
8090 | 3487 |
(photometric == #rgb) ifTrue:[ |
3488 |
^ pixelValue |
|
3489 |
]. |
|
3490 |
^ super rgbFromValue:pixelValue. |
|
3491 |
||
3492 |
"Modified: / 22-08-2017 / 18:32:42 / cg" |
|
4118 | 3493 |
! |
3494 |
||
282 | 3495 |
samplesPerPixel |
3496 |
"return the number of samples per pixel in the image." |
|
3497 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
3498 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
282 | 3499 |
^ 3 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
3500 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
3501 |
"Modified: 10.6.1996 / 18:03:09 / cg" |
3490 | 3502 |
! |
3503 |
||
8743 | 3504 |
valueFromColor:aColor |
3505 |
"get a color's pixel value." |
|
3506 |
||
3507 |
|r g b| |
|
3508 |
||
3509 |
photometric == #rgb ifTrue:[ |
|
3510 |
r := aColor redByte. |
|
3511 |
g := aColor greenByte. |
|
3512 |
b := aColor blueByte. |
|
3513 |
^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b |
|
3514 |
]. |
|
3515 |
^ super valueFromColor:aColor. |
|
3516 |
||
3517 |
"Created: / 22-07-2019 / 13:50:11 / Claus Gittinger" |
|
3518 |
! |
|
3519 |
||
3520 |
valueFromRGB:anRGBValue |
|
3521 |
"get the pixel value corresponding to an RGB value." |
|
3522 |
||
3523 |
photometric == #rgb ifTrue:[ |
|
3524 |
^ anRGBValue |
|
3525 |
]. |
|
3526 |
^ super valueFromRGB:anRGBValue. |
|
3527 |
||
3528 |
"Created: / 22-07-2019 / 13:48:56 / Claus Gittinger" |
|
3529 |
! |
|
3530 |
||
3490 | 3531 |
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
8743 | 3532 |
"given the rgb bits, each in 0..maxXXXValue (i.e. according to |
3533 |
r/g/b channels number of bits, return the corresponding pixel value. |
|
3534 |
For now, only useful with RGB images" |
|
3535 |
||
3536 |
(photometric == #rgb) ifTrue:[ |
|
8440 | 3537 |
^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits |
3538 |
]. |
|
8743 | 3539 |
^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits |
8090 | 3540 |
|
3541 |
"Modified: / 22-08-2017 / 18:34:07 / cg" |
|
8743 | 3542 |
"Modified (comment): / 22-07-2019 / 13:51:18 / Claus Gittinger" |
282 | 3543 |
! ! |
3544 |
||
1167 | 3545 |
!Depth24Image class methodsFor:'documentation'! |
282 | 3546 |
|
3547 |
version |
|
7125 | 3548 |
^ '$Header$' |
5480
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
3549 |
! |
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
3550 |
|
08d2c4b656bc
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5343
diff
changeset
|
3551 |
version_CVS |
7125 | 3552 |
^ '$Header$' |
282 | 3553 |
! ! |
7549 | 3554 |