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