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