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