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