author | Claus Gittinger <cg@exept.de> |
Mon, 14 Apr 1997 21:03:08 +0200 | |
changeset 1598 | a576243e73d3 |
parent 1597 | 019f40ecbe64 |
child 1607 | 4eb60ce558db |
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 |
|
13 |
Image subclass:#Depth24Image |
|
579 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Graphics-Images' |
|
1 | 18 |
! |
19 |
||
1167 | 20 |
!Depth24Image class methodsFor:'documentation'! |
46 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 25 |
All Rights Reserved |
3 | 26 |
|
46 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
3 | 35 |
|
46 | 36 |
documentation |
37 |
" |
|
38 |
this class represents true-color (24 bit / pixel) images. |
|
39 |
It mainly consists of methods already implemented in Image, |
|
40 |
reimplemented here for more performance. |
|
611 | 41 |
|
798 | 42 |
Only the #rgb format is supported here. |
43 |
||
611 | 44 |
[author:] |
45 |
Claus Gittinger |
|
46 |
||
47 |
[see also:] |
|
48 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image |
|
49 |
ImageReader |
|
46 | 50 |
" |
51 |
! ! |
|
3 | 52 |
|
1167 | 53 |
!Depth24Image class methodsFor:'queries'! |
89 | 54 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
55 |
defaultPhotometric |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
56 |
"return the default photometric pixel interpretation" |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
57 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
58 |
^ #rgb |
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 |
"Created: 10.6.1996 / 18:08:25 / cg" |
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 |
|
89 | 63 |
imageDepth |
579 | 64 |
"return the depth of images represented by instances of |
65 |
this class - here we return 24" |
|
66 |
||
89 | 67 |
^ 24 |
579 | 68 |
|
69 |
"Modified: 20.4.1996 / 23:39:50 / cg" |
|
89 | 70 |
! ! |
71 |
||
81 | 72 |
!Depth24Image methodsFor:'accessing'! |
1 | 73 |
|
74 |
atX:x y:y |
|
75 |
"retrieve a pixel at x/y; return a color. |
|
76 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
77 |
x = width-1, y=height-1 for lower right pixel" |
|
78 |
||
38 | 79 |
|index "{ Class: SmallInteger }" |
80 |
rVal gVal bVal| |
|
1 | 81 |
|
82 |
index := 1 + (((width * y) + x) * 3). |
|
83 |
rVal := bytes at:(index). |
|
84 |
gVal := bytes at:(index + 1). |
|
85 |
bVal := bytes at:(index + 2). |
|
86 |
||
87 |
photometric ~~ #rgb ifTrue:[ |
|
805 | 88 |
^ super atX:x y:y |
1 | 89 |
]. |
1350 | 90 |
^ Color redByte:rVal greenByte:gVal blueByte:bVal |
1 | 91 |
! |
92 |
||
89 | 93 |
atX:x y:y put:aColor |
94 |
"set the pixel at x/y to aColor. |
|
95 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
96 |
x = width-1, y=height-1 for lower right pixel." |
|
97 |
||
98 |
|index "{ Class: SmallInteger }" |
|
99 |
val "{ Class: SmallInteger }" | |
|
100 |
||
101 |
index := 1 + (((width * y) + x) * 3). |
|
102 |
val := (aColor red / 100 * 255) rounded. |
|
103 |
bytes at:(index) put:val. |
|
104 |
val := (aColor green / 100 * 255) rounded. |
|
105 |
bytes at:(index + 1) put:val. |
|
106 |
val := (aColor blue / 100 * 255) rounded. |
|
107 |
bytes at:(index + 2) put:val. |
|
108 |
! |
|
109 |
||
1 | 110 |
atX:x y:y putValue:aPixelValue |
111 |
"set a pixel at x/y to aPixelValue, which is 24 bits RGB. |
|
112 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
113 |
x = width-1, y=height-1 for lower right pixel" |
|
114 |
||
115 |
|index "{ Class: SmallInteger }" |
|
116 |
val "{ Class: SmallInteger }" | |
|
117 |
||
118 |
index := 1 + (((width * y) + x) * 3). |
|
119 |
val := aPixelValue. |
|
120 |
bytes at:(index + 2) put:(val bitAnd:16rFF). |
|
121 |
val := val bitShift:-8. |
|
122 |
bytes at:(index + 1) put:(val bitAnd:16rFF). |
|
123 |
val := val bitShift:-8. |
|
124 |
bytes at:(index) put:val. |
|
125 |
! |
|
126 |
||
282 | 127 |
valueAtX:x y:y |
128 |
"retrieve a pixel at x/y; return a color. |
|
129 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
|
130 |
x = width-1, y=height-1 for lower right pixel" |
|
1 | 131 |
|
282 | 132 |
|index "{ Class: SmallInteger }" |
133 |
rVal "{ Class: SmallInteger }" |
|
134 |
gVal "{ Class: SmallInteger }" |
|
135 |
bVal "{ Class: SmallInteger }"| |
|
1 | 136 |
|
282 | 137 |
index := 1 + (((width * y) + x) * 3). |
138 |
rVal := bytes at:(index). |
|
139 |
gVal := bytes at:(index + 1). |
|
140 |
bVal := bytes at:(index + 2). |
|
141 |
^ (((rVal bitShift:8) bitOr:gVal) bitShift:8) bitOr:bVal |
|
1 | 142 |
! ! |
143 |
||
144 |
!Depth24Image methodsFor:'converting rgb images'! |
|
145 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
146 |
asGrayFormOn:aDevice |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
147 |
"return a grey form from the receiver. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
148 |
Redefined to use special code when converting to 8-bit |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
149 |
greyScale displays." |
1 | 150 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
151 |
(aDevice visualType == #StaticGray) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
152 |
aDevice depth == 8 ifTrue:[ |
816 | 153 |
^ self makeDeviceGrayPixmapOn:aDevice depth:aDevice depth fromArray:(self threshold8BitGrayBits) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
154 |
]. |
1 | 155 |
]. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
156 |
^ super asGrayFormOn:aDevice |
1 | 157 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
158 |
"Created: 10.6.1996 / 19:00:45 / cg" |
816 | 159 |
"Modified: 10.6.1996 / 20:10:19 / cg" |
1 | 160 |
! |
161 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
162 |
asThresholdGrayImageDepth:depth |
808 | 163 |
"return an 8-bit grey image from the rgb picture. |
164 |
Pixel values are reduced to a 0..255 grey level." |
|
1 | 165 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
166 |
depth == 8 ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
167 |
photometric == #rgb ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
168 |
^ Depth8Image |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
169 |
width:width |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
170 |
height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
171 |
fromArray:(self threshold8BitGrayBits) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
172 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
173 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
174 |
^ super asThresholdGrayImageDepth:depth |
808 | 175 |
|
176 |
" |
|
177 |
|i| |
|
178 |
||
179 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
180 |
(i asThresholdGrayImageDepth:8) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
181 |
(i asThresholdGrayImageDepth:4) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
182 |
(i asThresholdGrayImageDepth:2) inspect. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
183 |
(i asThresholdGrayImageDepth:1) inspect. |
808 | 184 |
" |
1 | 185 |
|
808 | 186 |
" |
187 |
|i| |
|
188 |
||
189 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
190 |
((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:2) inspect |
808 | 191 |
" |
192 |
||
193 |
" |
|
194 |
|i| |
|
1 | 195 |
|
808 | 196 |
i := Image fromFile:'bitmaps/granite.tiff'. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
197 |
((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:4) inspect |
808 | 198 |
" |
199 |
||
200 |
" |
|
201 |
|i| |
|
202 |
||
203 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
204 |
(i asThresholdGrayImageDepth:8) asOrderedDitheredMonochromeImage inspect |
808 | 205 |
" |
206 |
||
207 |
"Created: 8.6.1996 / 13:58:46 / cg" |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
208 |
"Modified: 10.6.1996 / 19:11:18 / cg" |
1 | 209 |
! |
210 |
||
282 | 211 |
rgbImageAsDitheredPseudoFormOn:aDevice |
212 |
"return a dithered pseudocolor form from the rgb-picture. |
|
213 |
This method depends on fixColors being allocated (see Color>>getColors*)" |
|
214 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
215 |
^ self |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
216 |
rgbImageAsDitheredPseudoFormOn:aDevice |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
217 |
colors:aDevice fixColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
218 |
nRed:aDevice numFixRed |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
219 |
nGreen:aDevice numFixGreen |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
220 |
nBlue:aDevice numFixBlue |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
221 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
222 |
"Modified: 14.4.1997 / 19:11:49 / cg" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
223 |
! |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
224 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
225 |
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
226 |
"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
|
227 |
arbitrary fix colors in fixColors." |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
228 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
229 |
|pseudoBits f |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
230 |
h "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
231 |
w "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
232 |
numFix "{Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
233 |
srcIndex "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
234 |
dstIndex "{ Class: SmallInteger }" |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
235 |
deviceDepth has8BitImage |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
236 |
fixIds fixRed fixGreen fixBlue failed cache| |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
237 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
238 |
numFix := fixColors size. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
239 |
numFix == 256 ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
240 |
"/ algorithm below only handles 255 colors. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
241 |
numFix := 255. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
242 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
243 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
244 |
fixRed := (fixColors asArray collect:[:clr | clr redByte]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
245 |
fixGreen := (fixColors asArray collect:[:clr | clr greenByte]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
246 |
fixBlue := (fixColors asArray collect:[:clr | clr blueByte]) asByteArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
247 |
cache := ByteArray new:(1 bitShift:14). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
248 |
cache atAllPut:16rFF. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
249 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
250 |
deviceDepth := aDevice depth. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
251 |
deviceDepth == 8 ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
252 |
has8BitImage := true. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
253 |
] ifFalse:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
254 |
has8BitImage := false. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
255 |
aDevice supportedImageFormats do:[:fmt | |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
256 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
257 |
has8BitImage := true. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
258 |
] |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
259 |
] |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
260 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
261 |
has8BitImage ifFalse:[^ nil]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
262 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
263 |
'Depth24Image [info]: dithering ...' infoPrintCR. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
264 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
265 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
266 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
267 |
h := height. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
268 |
w := width. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
269 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
270 |
%{ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
271 |
int __x, __y, __numFix; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
272 |
int __eR, __eG, __eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
273 |
unsigned char *srcP, *dstP; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
274 |
int pix; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
275 |
unsigned char *idP, *redP, *greenP, *blueP, *cacheP; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
276 |
int __w = __intVal(w); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
277 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
278 |
if (__isByteArray(__INST(bytes)) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
279 |
&& __isSmallInteger(numFix) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
280 |
&& __isByteArray(pseudoBits) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
281 |
&& __isByteArray(cache) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
282 |
&& __isByteArray(fixIds) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
283 |
&& __isByteArray(fixRed) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
284 |
&& __isByteArray(fixGreen) |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
285 |
&& __isByteArray(fixBlue) ) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
286 |
failed = false; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
287 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
288 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
289 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
290 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
291 |
redP = __ByteArrayInstPtr(fixRed)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
292 |
greenP = __ByteArrayInstPtr(fixGreen)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
293 |
blueP = __ByteArrayInstPtr(fixBlue)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
294 |
cacheP = __ByteArrayInstPtr(cache)->ba_element; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
295 |
__numFix = __intVal(numFix); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
296 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
297 |
for (__y=__intVal(h); __y>0; __y--) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
298 |
__eR = __eG = __eB = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
299 |
for (__x=__w; __x>0; __x--) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
300 |
int cacheIdx, clrIdx; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
301 |
int __wantR, __wantG, __wantB; |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
302 |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
303 |
__wantR = srcP[0] + __eR; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
304 |
if (__wantR > 255) __wantR = 255; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
305 |
else if (__wantR < 0) __wantR = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
306 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
307 |
__wantG = srcP[1] + __eG; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
308 |
if (__wantG > 255) __wantG = 255; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
309 |
else if (__wantG < 0) __wantG = 0; |
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 |
__wantB = srcP[2] + __eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
312 |
if (__wantB > 255) __wantB = 255; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
313 |
else if (__wantB < 0) __wantB = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
314 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
315 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
316 |
* compute cache index |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
317 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
318 |
cacheIdx = ((__wantR & 0xF8) >> 3); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
319 |
cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
320 |
cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4); |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
321 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
322 |
clrIdx = cacheP[cacheIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
323 |
if (clrIdx == 0xFF) { /* invalid slot */ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
324 |
unsigned minErr, minIdx; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
325 |
int i; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
326 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
327 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
328 |
* must search ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
329 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
330 |
minErr = 0x7FFFFFF; minIdx = 0; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
331 |
for (i=0; i<__numFix; i++) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
332 |
unsigned cR, cG, cB, e; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
333 |
int eR, eG, eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
334 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
335 |
cR = redP[i]; cG = greenP[i]; cB = blueP[i]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
336 |
eR = cR - __wantR; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
337 |
if (eR < 0) eR = -eR; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
338 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
339 |
eG = cG - __wantG; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
340 |
if (eG < 0) eG = -eG; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
341 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
342 |
eB = cB - __wantB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
343 |
if (eB < 0) eB = -eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
344 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
345 |
e = eR + eG + eB; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
346 |
if (e < minErr) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
347 |
minErr = e; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
348 |
minIdx = i; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
349 |
if (e < 7) { |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
350 |
break; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
351 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
352 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
353 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
354 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
355 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
356 |
* minIdx is now index into fixColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
357 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
358 |
cacheP[cacheIdx] = clrIdx = minIdx; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
359 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
360 |
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
|
361 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
362 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
363 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
364 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
365 |
* store the corresponding dither colorId |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
366 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
367 |
*dstP++ = idP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
368 |
srcP += 3; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
369 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
370 |
/* |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
371 |
* the new error: |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
372 |
*/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
373 |
__eR = __wantR - redP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
374 |
__eG = __wantG - greenP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
375 |
__eB = __wantB - blueP[clrIdx]; |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
376 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
377 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
378 |
} |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
379 |
%}. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
380 |
failed ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
381 |
self primitiveFailed. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
382 |
^ nil |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
383 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
384 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
385 |
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
|
386 |
f isNil ifTrue:[^ nil]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
387 |
f colorMap:fixColors. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
388 |
f initGC. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
389 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:aDevice depth |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
390 |
width:width height:height |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
391 |
x:0 y:0 |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
392 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
393 |
^ f |
282 | 394 |
! |
395 |
||
396 |
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
|
397 |
"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
|
398 |
using colors from a colorCube for dithering." |
282 | 399 |
|
400 |
|pseudoBits f |
|
401 |
h "{ Class: SmallInteger }" |
|
402 |
w "{ Class: SmallInteger }" |
|
403 |
"/ eR "{Class: SmallInteger }" |
|
404 |
"/ eG "{Class: SmallInteger }" |
|
405 |
"/ eB "{Class: SmallInteger }" |
|
406 |
"/ wantR "{Class: SmallInteger }" |
|
407 |
"/ wantG "{Class: SmallInteger }" |
|
408 |
"/ wantB "{Class: SmallInteger }" |
|
409 |
fixR "{Class: SmallInteger }" |
|
410 |
fixG "{Class: SmallInteger }" |
|
411 |
fixB "{Class: SmallInteger }" |
|
412 |
srcIndex "{ Class: SmallInteger }" |
|
413 |
dstIndex "{ Class: SmallInteger }" |
|
414 |
deviceDepth has8BitImage |
|
415 |
fixIds failed| |
|
416 |
||
417 |
fixR := nRed. |
|
418 |
fixR == 0 ifTrue:[ ^ nil]. |
|
419 |
fixG := nGreen. |
|
420 |
fixG == 0 ifTrue:[ ^ nil]. |
|
421 |
fixB := nBlue. |
|
422 |
fixB == 0 ifTrue:[ ^ nil]. |
|
423 |
"/ simple check |
|
424 |
(fixR * fixG * fixB) ~~ fixColors size ifTrue:[ |
|
858 | 425 |
self error:'invalid color array passed'. |
426 |
^ nil |
|
282 | 427 |
]. |
428 |
fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray. |
|
429 |
||
430 |
deviceDepth := aDevice depth. |
|
431 |
deviceDepth == 8 ifTrue:[ |
|
858 | 432 |
has8BitImage := true. |
282 | 433 |
] ifFalse:[ |
858 | 434 |
has8BitImage := false. |
435 |
aDevice supportedImageFormats do:[:fmt | |
|
436 |
(fmt at:#bitsPerPixel) == 8 ifTrue:[ |
|
437 |
has8BitImage := true. |
|
438 |
] |
|
439 |
] |
|
282 | 440 |
]. |
441 |
has8BitImage ifFalse:[^ nil]. |
|
442 |
||
1167 | 443 |
'Depth24Image [info]: dithering ...' infoPrintCR. |
282 | 444 |
|
445 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
446 |
||
447 |
h := height. |
|
448 |
w := width. |
|
449 |
||
450 |
%{ |
|
451 |
int __x, __y; |
|
452 |
int __eR, __eG, __eB; |
|
453 |
int __wantR, __wantG, __wantB; |
|
454 |
unsigned char *srcP, *dstP; |
|
455 |
unsigned char *redP, *greenP, *blueP; |
|
456 |
int pix; |
|
457 |
unsigned char *idP; |
|
458 |
int __fR, __fG, __fB; |
|
459 |
int iR, iG, iB; |
|
460 |
int idx; |
|
858 | 461 |
int __w = __intVal(w); |
282 | 462 |
|
858 | 463 |
if (__isByteArray(__INST(bytes)) |
282 | 464 |
&& __isByteArray(pseudoBits) |
465 |
&& __isByteArray(fixIds) |
|
466 |
&& __bothSmallInteger(fixR, fixG) |
|
467 |
&& __isSmallInteger(fixB)) { |
|
858 | 468 |
failed = false; |
282 | 469 |
|
858 | 470 |
srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
471 |
dstP = __ByteArrayInstPtr(pseudoBits)->ba_element; |
|
472 |
idP = __ByteArrayInstPtr(fixIds)->ba_element; |
|
473 |
__fR = __intVal(fixR)-1; |
|
474 |
__fG = __intVal(fixG)-1; |
|
475 |
__fB = __intVal(fixB)-1; |
|
282 | 476 |
|
858 | 477 |
for (__y=__intVal(h); __y>0; __y--) { |
478 |
__eR = __eG = __eB = 0; |
|
479 |
for (__x=__w; __x>0; __x--) { |
|
480 |
int __want; |
|
282 | 481 |
|
858 | 482 |
/* |
483 |
* wR, wG and wB is the wanted r/g/b value; |
|
484 |
* compute the index into the dId table .. |
|
485 |
* values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1 |
|
486 |
* |
|
487 |
* bad kludge: knows how to index into FixColor table |
|
488 |
*/ |
|
489 |
__wantR = __want = srcP[0] + __eR; |
|
282 | 490 |
|
858 | 491 |
if (__want > 255) __want = 255; |
492 |
else if (__want < 0) __want = 0; |
|
493 |
||
494 |
iR = __want * __fR / 128; |
|
495 |
iR = (iR / 2) + (iR & 1); |
|
282 | 496 |
|
858 | 497 |
__wantG = __want = srcP[1] + __eG; |
498 |
if (__want > 255) __want = 255; |
|
499 |
else if (__want < 0) __want = 0; |
|
282 | 500 |
|
858 | 501 |
iG = __want * __fG / 128; |
502 |
iG = (iG / 2) + (iG & 1); |
|
282 | 503 |
|
858 | 504 |
__wantB = __want = srcP[2] + __eB; |
505 |
if (__want > 255) __want = 255; |
|
506 |
else if (__want < 0) __want = 0; |
|
282 | 507 |
|
858 | 508 |
iB = __want * __fB / 128; |
509 |
iB = (iB / 2) + (iB & 1); |
|
282 | 510 |
|
858 | 511 |
idx = iR * (__fG+1); |
512 |
idx = (idx + iG) * (__fB+1); |
|
513 |
idx = idx + iB; |
|
282 | 514 |
|
858 | 515 |
/* |
516 |
* store the corresponding dither colorId |
|
517 |
*/ |
|
518 |
*dstP++ = idP[idx]; |
|
282 | 519 |
|
858 | 520 |
srcP += 3; |
521 |
||
522 |
/* |
|
523 |
* the new error: |
|
524 |
*/ |
|
525 |
__eR = __wantR - (iR * 256 / __fR); |
|
526 |
__eG = __wantG - (iG * 256 / __fG); |
|
527 |
__eB = __wantB - (iB * 256 / __fB); |
|
528 |
} |
|
529 |
} |
|
282 | 530 |
} |
531 |
%}. |
|
532 |
failed ifTrue:[ |
|
858 | 533 |
self primitiveFailed. |
534 |
^ nil |
|
282 | 535 |
|
536 |
"/ for non-C programmers: |
|
1218
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
537 |
"/ the above code is (roughly) equivalent to: |
2d7c79e5965f
oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents:
1177
diff
changeset
|
538 |
"/ (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
|
539 |
"/ |
282 | 540 |
"/ srcIndex := 1. |
541 |
"/ dstIndex := 1. |
|
542 |
"/ 1 to:h do:[:y | |
|
543 |
"/ eR := eG := eB := 0. |
|
544 |
"/ 1 to:w do:[:x | |
|
545 |
"/ |pixel "{ Class: SmallInteger }" |
|
546 |
"/ clr |
|
547 |
"/ idx "{ Class: SmallInteger }" |
|
548 |
"/ iR "{ Class: SmallInteger }" |
|
549 |
"/ iG "{ Class: SmallInteger }" |
|
550 |
"/ iB "{ Class: SmallInteger }" |
|
551 |
"/ wR "{ Class: SmallInteger }" |
|
552 |
"/ wG "{ Class: SmallInteger }" |
|
553 |
"/ wB "{ Class: SmallInteger }" | |
|
554 |
"/ |
|
555 |
"/ wantR := ((bytes at:srcIndex) + eR). srcIndex := srcIndex + 1. |
|
556 |
"/ wantG := ((bytes at:srcIndex) + eG). srcIndex := srcIndex + 1. |
|
557 |
"/ wantB := ((bytes at:srcIndex) + eB). srcIndex := srcIndex + 1. |
|
558 |
"/ wR := wantR. |
|
559 |
"/ wR > 255 ifTrue:[wR := 255] ifFalse:[wR < 0 ifTrue:[wR := 0]]. |
|
560 |
"/ wG := wantG. |
|
561 |
"/ wG > 255 ifTrue:[wG := 255] ifFalse:[wG < 0 ifTrue:[wG := 0]]. |
|
562 |
"/ wB := wantB. |
|
563 |
"/ wB > 255 ifTrue:[wB := 255] ifFalse:[wB < 0 ifTrue:[wB := 0]]. |
|
564 |
"/ |
|
565 |
"/ iR := wR * (fixR-1) // 128. |
|
566 |
"/ iR := (iR // 2) + (iR bitAnd:1). |
|
567 |
"/ iG := wG * (fixG-1) // 128. |
|
568 |
"/ iG := (iG // 2) + (iG bitAnd:1). |
|
569 |
"/ iB := wB * (fixB-1) // 128. |
|
570 |
"/ iB := (iB // 2) + (iB bitAnd:1). |
|
571 |
"/ idx := (iR * fixR + iG) * fixB + iB + 1. |
|
572 |
"/ |
|
573 |
"/ clr := fixColors at:idx. |
|
574 |
"/ |
|
575 |
"/ eR := wantR - (clr red * 2) asInteger. |
|
576 |
"/ eG := wantG - (clr green * 2) asInteger. |
|
577 |
"/ eB := wantB - (clr blue * 2) asInteger. |
|
578 |
"/ |
|
579 |
"/ pixel := clr colorId. |
|
580 |
"/ pseudoBits at:dstIndex put:pixel. |
|
581 |
"/ |
|
582 |
"/ dstIndex := dstIndex + 1 |
|
583 |
"/ ]. |
|
584 |
]. |
|
585 |
||
586 |
f := Form width:width height:height depth:aDevice depth on:aDevice. |
|
587 |
f isNil ifTrue:[^ nil]. |
|
588 |
f colorMap:fixColors. |
|
589 |
f initGC. |
|
590 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:aDevice depth |
|
858 | 591 |
width:width height:height |
592 |
x:0 y:0 |
|
593 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
|
282 | 594 |
^ f |
595 |
! |
|
596 |
||
1 | 597 |
rgbImageAsPseudoFormOn:aDevice |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
598 |
"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
|
599 |
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
|
600 |
code. Otherwise, allocate as many colors as possible, then |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
601 |
use those for dithering. Could be improved, by searching for |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
602 |
heavily used colors and/or boundaries first." |
1 | 603 |
|
604 |
|pseudoBits f |
|
605 |
r "{ Class: SmallInteger }" |
|
606 |
g "{ Class: SmallInteger }" |
|
607 |
b "{ Class: SmallInteger }" |
|
608 |
srcIndex "{ Class: SmallInteger }" |
|
609 |
dstIndex "{ Class: SmallInteger }" |
|
610 |
rMask "{ Class: SmallInteger }" |
|
611 |
gMask "{ Class: SmallInteger }" |
|
612 |
bMask "{ Class: SmallInteger }" |
|
613 |
redArray greenArray blueArray |
|
614 |
dataSize "{ Class: SmallInteger }" |
|
615 |
nColors "{ Class: SmallInteger }" |
|
616 |
fit fitMap colors color |
|
617 |
fast |
|
618 |
colorIndex "{ Class: SmallInteger }" |
|
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
619 |
depth nColorCells deep nColorsNeeded| |
89 | 620 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
621 |
aDevice fixColors notNil ifTrue:[ |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
622 |
"/ no need to look for used colors - dithering anyway ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
623 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
624 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
625 |
f notNil ifTrue:[^ f]. |
89 | 626 |
]. |
1 | 627 |
|
628 |
"find used colors; build color-tree" |
|
629 |
||
630 |
fit := false. |
|
631 |
fitMap := false. |
|
632 |
depth := aDevice depth. |
|
633 |
nColorCells := aDevice ncells. |
|
634 |
||
89 | 635 |
deep := (depth > 8). |
636 |
||
1 | 637 |
rMask := 2r11111111. |
638 |
gMask := 2r11111111. |
|
639 |
bMask := 2r11111111. |
|
640 |
||
1167 | 641 |
'Depth24Image [info]: allocating colors ...' infoPrintCR. |
66 | 642 |
|
1 | 643 |
[fit] whileFalse:[ |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
644 |
[fitMap] whileFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
645 |
srcIndex := 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
646 |
redArray := Array new:256. |
1 | 647 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
648 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
649 |
find used colors, build [r][g][b] 3-dimensional array |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
650 |
containing true for used colors |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
651 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
652 |
nColors := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
653 |
srcIndex := 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
654 |
dataSize := bytes size. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
655 |
[srcIndex < dataSize] whileTrue:[ |
1 | 656 |
%{ |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
657 |
if (__isByteArray(_INST(bytes))) { |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
658 |
int sI = _intVal(srcIndex); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
659 |
unsigned char *cp = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
1 | 660 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
661 |
r = __MKSMALLINT((cp[sI - 1] & _intVal(rMask)) + 1); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
662 |
g = __MKSMALLINT((cp[sI] & _intVal(gMask)) + 1); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
663 |
b = __MKSMALLINT((cp[sI + 1] & _intVal(bMask)) + 1); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
664 |
srcIndex = __MKSMALLINT(sI + 3); |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
665 |
fast = true; |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
666 |
} else { |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
667 |
fast = false; |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
668 |
} |
1 | 669 |
%} |
670 |
. |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
671 |
fast ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
672 |
r := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
673 |
r := (r bitAnd:rMask) + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
674 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
675 |
g := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
676 |
g := (g bitAnd:gMask) + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
677 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
678 |
b := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
679 |
b := (b bitAnd:bMask) + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
680 |
srcIndex := srcIndex + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
681 |
]. |
1 | 682 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
683 |
greenArray := redArray at:r. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
684 |
greenArray isNil ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
685 |
greenArray := Array new:256. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
686 |
redArray at:r put:greenArray |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
687 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
688 |
blueArray := greenArray at:g. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
689 |
blueArray isNil ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
690 |
deep ifTrue:[blueArray := Array new:256] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
691 |
ifFalse:[blueArray := ByteArray new:256]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
692 |
greenArray at:g put:blueArray |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
693 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
694 |
(blueArray at:b) == 0 ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
695 |
blueArray at:b put:1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
696 |
nColors := nColors + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
697 |
(nColors > nColorCells) ifTrue:[ |
1177
e89408c15bb5
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
698 |
'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR. |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
699 |
srcIndex := dataSize + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
700 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
701 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
702 |
]. |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
703 |
nColorsNeeded isNil ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
704 |
nColorsNeeded := nColors |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
705 |
]. |
1 | 706 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
707 |
"again with less color bits if it does not fit colormap" |
1 | 708 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
709 |
(nColors <= nColorCells) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
710 |
fitMap := true |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
711 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
712 |
"must try again - cutting off some bits" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
713 |
(bMask == 2r11111111) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
714 |
bMask := 2r11111110 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
715 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
716 |
(bMask == 2r11111110) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
717 |
bMask := 2r11111100 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
718 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
719 |
rMask := (rMask bitShift:1) bitAnd:2r11111111. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
720 |
gMask := (gMask bitShift:1) bitAnd:2r11111111. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
721 |
bMask := (bMask bitShift:1) bitAnd:2r11111111 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
722 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
723 |
]. |
1167 | 724 |
'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR. |
38 | 725 |
" |
1 | 726 |
'masks:' print. rMask print. ' ' print. gMask print. ' ' print. |
727 |
bMask printNewline |
|
38 | 728 |
" |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
729 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
730 |
]. |
1 | 731 |
|
1167 | 732 |
'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR. |
89 | 733 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
734 |
colors := Array new:nColors. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
735 |
colorIndex := 1. |
1 | 736 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
737 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
738 |
now, we have reduced things to the number of colors |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
739 |
which are theoretically supported by the devices colormap. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
740 |
allocate all used colors in walking over true entries in |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
741 |
the [r][g][b] table - this may still fail, |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
742 |
if we run out of device colors. |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
743 |
" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
744 |
fit := true. |
1 | 745 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
746 |
r := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
747 |
redArray do:[:greenArray | |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
748 |
(fit and:[greenArray notNil]) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
749 |
g := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
750 |
greenArray do:[:blueArray | |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
751 |
(fit and:[blueArray notNil]) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
752 |
b := 0. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
753 |
blueArray do:[:present | |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
754 |
|id| |
89 | 755 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
756 |
(fit and:[present ~~ 0]) ifTrue:[ |
1237 | 757 |
color := Color redByte:r |
758 |
greenByte:g |
|
759 |
blueByte:b. |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
760 |
color := color on:aDevice. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
761 |
(id := color colorId) isNil ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
762 |
fit := false |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
763 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
764 |
colors at:colorIndex put:color. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
765 |
colorIndex := colorIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
766 |
blueArray at:(b + 1) put:id |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
767 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
768 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
769 |
b := b + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
770 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
771 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
772 |
g := g + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
773 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
774 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
775 |
r := r + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
776 |
]. |
1 | 777 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
778 |
"again with less color bits if we did not get all colors" |
1 | 779 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
780 |
fit ifFalse:[ |
1167 | 781 |
'Depth24Image [info]: could not allocate color(s)' infoPrintCR. |
1 | 782 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
783 |
"free the allocated colors" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
784 |
colors atAllPut:nil. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
785 |
"a kludge - force immediate freeing of colors" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
786 |
ObjectMemory scavenge; finalize. |
1 | 787 |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
788 |
"cut off one more color-bit - cut off blue first" |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
789 |
(bMask == 2r11111111) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
790 |
bMask := 2r11111110 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
791 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
792 |
(bMask == 2r11111110) ifTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
793 |
bMask := 2r11111100 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
794 |
] ifFalse:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
795 |
rMask := (rMask bitShift:1) bitAnd:2r11111111. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
796 |
gMask := (gMask bitShift:1) bitAnd:2r11111111. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
797 |
bMask := (bMask bitShift:1) bitAnd:2r11111111 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
798 |
] |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
799 |
]. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
800 |
fitMap := false. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
801 |
redArray := nil |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
802 |
] |
1 | 803 |
]. |
804 |
||
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
805 |
(nColors ~~ nColorsNeeded) ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
806 |
"/ mhmh - did not get all colors ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
807 |
'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
808 |
nColorsNeeded infoPrint. ' image colors.' infoPrintCR. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
809 |
|
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
810 |
"/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
811 |
"/ dither using those we got ... |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
812 |
"/ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
813 |
DitherAlgorithm == #floydSteinberg ifTrue:[ |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
814 |
colors := colors asSet. |
1598 | 815 |
colors addAll:(aDevice ditherColors). |
1597
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
816 |
colors := colors asArray. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
817 |
f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
818 |
f notNil ifTrue:[^ f]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
819 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
820 |
]. |
019f40ecbe64
added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
821 |
|
1 | 822 |
"create pseudocolor bits and translate" |
823 |
||
824 |
pseudoBits := ByteArray uninitializedNew:(width * height). |
|
825 |
||
826 |
srcIndex := 1. |
|
827 |
dstIndex := 1. |
|
828 |
||
89 | 829 |
(rMask == 2r11111111 |
830 |
and:[gMask == 2r11111111 |
|
831 |
and:[bMask == 2r11111111]]) ifTrue:[ |
|
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
832 |
[srcIndex < dataSize] whileTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
833 |
r := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
834 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
835 |
g := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
836 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
837 |
b := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
838 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
839 |
greenArray := redArray at:(r + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
840 |
blueArray := greenArray at:(g + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
841 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
842 |
dstIndex := dstIndex + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
843 |
] |
89 | 844 |
] ifFalse:[ |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
845 |
[srcIndex < dataSize] whileTrue:[ |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
846 |
r := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
847 |
r := r bitAnd:rMask. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
848 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
849 |
g := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
850 |
g := g bitAnd:gMask. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
851 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
852 |
b := bytes at:srcIndex. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
853 |
b := b bitAnd:bMask. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
854 |
srcIndex := srcIndex + 1. |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
855 |
greenArray := redArray at:(r + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
856 |
blueArray := greenArray at:(g + 1). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
857 |
pseudoBits at:dstIndex put:(blueArray at:(b + 1)). |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
858 |
dstIndex := dstIndex + 1 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
859 |
] |
1 | 860 |
]. |
861 |
||
89 | 862 |
f := Form width:width height:height depth:depth on:aDevice. |
1 | 863 |
f isNil ifTrue:[^ nil]. |
864 |
f colorMap:colors. |
|
865 |
f initGC. |
|
89 | 866 |
aDevice drawBits:pseudoBits bitsPerPixel:8 depth:depth |
938
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
867 |
width:width height:height |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
868 |
x:0 y:0 |
1926ecac24b5
fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents:
886
diff
changeset
|
869 |
into:(f id) x:0 y:0 width:width height:height with:(f gcId). |
1 | 870 |
^ f |
194 | 871 |
! |
872 |
||
873 |
rgbImageAsTrueColorFormOn:aDevice |
|
874 |
"return a truecolor form from the rgb-picture." |
|
875 |
||
876 |
|bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth |
|
877 |
myDepth form imageBits destIndex srcIndex |
|
856 | 878 |
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue| |
194 | 879 |
|
880 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
|
236 | 881 |
usedDeviceDepth := bestFormat at:#depth. |
882 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
|
194 | 883 |
|
884 |
rightShiftR := (8 - aDevice bitsRed). |
|
885 |
rightShiftG := (8 - aDevice bitsGreen). |
|
886 |
rightShiftB := (8 - aDevice bitsBlue). |
|
887 |
||
888 |
shiftRed := aDevice shiftRed. |
|
889 |
shiftGreen := aDevice shiftGreen. |
|
890 |
shiftBlue := aDevice shiftBlue. |
|
891 |
||
892 |
"/ |
|
893 |
"/ for now, only a few formats are supported |
|
894 |
"/ |
|
895 |
myDepth := self bitsPerPixel. |
|
896 |
myDepth == usedDeviceBitsPerPixel ifTrue:[ |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
897 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
898 |
"/ first, the trivial case, where the depths match |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
899 |
"/ 24 bit/pixel |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
900 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
901 |
imageBits := bytes. |
194 | 902 |
] ifFalse:[ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
903 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
904 |
"/ 16 bit/pixel ... |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
905 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
906 |
(usedDeviceBitsPerPixel == 16) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
907 |
imageBits := ByteArray uninitializedNew:(width * height * 2). |
194 | 908 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
909 |
"/ now, walk over the image and compose 16bit values from the r/g/b triples |
194 | 910 |
|
856 | 911 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
912 |
if (__bothSmallInteger(_INST(height),_INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
913 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
914 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
915 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
916 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
917 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
918 |
int rShRed = __intVal(rightShiftR), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
919 |
rShGreen = __intVal(rightShiftG), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
920 |
rShBlue = __intVal(rightShiftB), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
921 |
lShRed = __intVal(shiftRed), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
922 |
lShGreen = __intVal(shiftGreen), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
923 |
lShBlue = __intVal(shiftBlue); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
924 |
int x, y, w; |
194 | 925 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
926 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
927 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
194 | 928 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
929 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
930 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
931 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
932 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
933 |
unsigned v; |
194 | 934 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
935 |
v = srcPtr[0] << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
936 |
v |= (srcPtr[1] << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
937 |
v |= (srcPtr[2] << lShBlue); |
194 | 938 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
939 |
((short *)dstPtr)[0] = v; |
194 | 940 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
941 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
942 |
dstPtr[1] = (v) & 0xFF; |
194 | 943 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
944 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
945 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
946 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
947 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
948 |
} else { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
949 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
950 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
951 |
unsigned r, g, b, v; |
194 | 952 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
953 |
r = srcPtr[0] >> rShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
954 |
g = srcPtr[1] >> rShGreen; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
955 |
b = srcPtr[2] >> rShBlue; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
956 |
v = r << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
957 |
v |= (g << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
958 |
v |= (b << lShBlue); |
194 | 959 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
960 |
((short *)dstPtr)[0] = v; |
194 | 961 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
962 |
dstPtr[0] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
963 |
dstPtr[1] = (v) & 0xFF; |
194 | 964 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
965 |
dstPtr += 2; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
966 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
967 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
968 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
969 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
970 |
} |
194 | 971 |
%}. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
972 |
] ifFalse:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
973 |
"/ |
856 | 974 |
"/ 32 bits/pixel ... |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
975 |
"/ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
976 |
(usedDeviceBitsPerPixel == 32) ifTrue:[ |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
977 |
imageBits := ByteArray uninitializedNew:(width * height * 4). |
194 | 978 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
979 |
"/ now, walk over the image and compose 32bit values from the r/g/b triples |
194 | 980 |
|
856 | 981 |
%{ |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
982 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
983 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
984 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
985 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
986 |
&& __isByteArray(_INST(bytes)) |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
987 |
&& __isByteArray(imageBits)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
988 |
int rShRed = __intVal(rightShiftR), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
989 |
rShGreen = __intVal(rightShiftG), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
990 |
rShBlue = __intVal(rightShiftB), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
991 |
lShRed = __intVal(shiftRed), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
992 |
lShGreen = __intVal(shiftGreen), |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
993 |
lShBlue = __intVal(shiftBlue); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
994 |
int x, y, w; |
194 | 995 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
996 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
997 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
194 | 998 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
999 |
w = __intVal(_INST(width)); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1000 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1001 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1002 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1003 |
unsigned v; |
194 | 1004 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1005 |
v = srcPtr[0] << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1006 |
v |= (srcPtr[1] << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1007 |
v |= (srcPtr[2] << lShBlue); |
194 | 1008 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1009 |
((int *)dstPtr)[0] = v; |
194 | 1010 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1011 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1012 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1013 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1014 |
dstPtr[3] = (v) & 0xFF; |
194 | 1015 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1016 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1017 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1018 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1019 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1020 |
} else { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1021 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1022 |
for (x=w; x > 0; x--) { |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1023 |
unsigned r, g, b, v; |
194 | 1024 |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1025 |
r = srcPtr[0] >> rShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1026 |
g = srcPtr[1] >> rShGreen; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1027 |
b = srcPtr[2] >> rShBlue; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1028 |
v = r << lShRed; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1029 |
v |= (g << lShGreen); |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1030 |
v |= (b << lShBlue); |
194 | 1031 |
# ifdef MSBFIRST |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1032 |
((int *)dstPtr)[0] = v; |
194 | 1033 |
# else |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1034 |
dstPtr[0] = (v>>24) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1035 |
dstPtr[1] = (v>>16) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1036 |
dstPtr[2] = (v>>8) & 0xFF; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1037 |
dstPtr[3] = (v) & 0xFF; |
194 | 1038 |
# endif |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1039 |
dstPtr += 4; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1040 |
srcPtr += 3; |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1041 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1042 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1043 |
} |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1044 |
} |
194 | 1045 |
%}. |
856 | 1046 |
] ifFalse:[ |
1047 |
"/ |
|
1048 |
"/ 8 bits/pixel ... |
|
1049 |
"/ |
|
1050 |
(usedDeviceBitsPerPixel == 8) ifTrue:[ |
|
1051 |
imageBits := ByteArray uninitializedNew:(width * height). |
|
1052 |
||
1053 |
"/ now, walk over the image and compose 8bit values from the r/g/b triples |
|
194 | 1054 |
|
856 | 1055 |
%{ |
1056 |
if (__bothSmallInteger(_INST(height), _INST(width)) |
|
1057 |
&& __bothSmallInteger(rightShiftR, shiftRed) |
|
1058 |
&& __bothSmallInteger(rightShiftG, shiftGreen) |
|
1059 |
&& __bothSmallInteger(rightShiftB, shiftBlue) |
|
1060 |
&& __isByteArray(_INST(bytes)) |
|
1061 |
&& __isByteArray(imageBits)) { |
|
1062 |
int rShRed = __intVal(rightShiftR), |
|
1063 |
rShGreen = __intVal(rightShiftG), |
|
1064 |
rShBlue = __intVal(rightShiftB), |
|
1065 |
lShRed = __intVal(shiftRed), |
|
1066 |
lShGreen = __intVal(shiftGreen), |
|
1067 |
lShBlue = __intVal(shiftBlue); |
|
1068 |
int x, y, w; |
|
194 | 1069 |
|
856 | 1070 |
unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
1071 |
char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element; |
|
194 | 1072 |
|
856 | 1073 |
w = __intVal(_INST(width)); |
1074 |
if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) { |
|
1075 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
|
1076 |
for (x=w; x > 0; x--) { |
|
1077 |
unsigned v; |
|
194 | 1078 |
|
856 | 1079 |
v = srcPtr[0] << lShRed; |
1080 |
v |= (srcPtr[1] << lShGreen); |
|
1081 |
v |= (srcPtr[2] << lShBlue); |
|
1082 |
dstPtr[0] = v; |
|
194 | 1083 |
|
856 | 1084 |
dstPtr += 1; |
1085 |
srcPtr += 3; |
|
1086 |
} |
|
1087 |
} |
|
1088 |
} else { |
|
1089 |
for (y=__intVal(_INST(height)); y > 0; y--) { |
|
1090 |
for (x=w; x > 0; x--) { |
|
1091 |
unsigned r, g, b, v; |
|
194 | 1092 |
|
856 | 1093 |
r = srcPtr[0] >> rShRed; |
1094 |
g = srcPtr[1] >> rShGreen; |
|
1095 |
b = srcPtr[2] >> rShBlue; |
|
1096 |
v = r << lShRed; |
|
1097 |
v |= (g << lShGreen); |
|
1098 |
v |= (b << lShBlue); |
|
1099 |
||
1100 |
dstPtr[0] = v; |
|
1101 |
||
1102 |
dstPtr += 1; |
|
1103 |
srcPtr += 3; |
|
1104 |
} |
|
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
%}. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1109 |
] |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1110 |
]. |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1111 |
] |
194 | 1112 |
]. |
1113 |
||
1114 |
imageBits isNil ifTrue:[ |
|
856 | 1115 |
'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint. |
1116 |
usedDeviceBitsPerPixel errorPrintCR. |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1117 |
^ self asMonochromeFormOn:aDevice |
194 | 1118 |
]. |
1119 |
||
1120 |
form := Form width:width height:height depth:usedDeviceDepth on:aDevice. |
|
1121 |
form isNil ifTrue:[ |
|
1177
e89408c15bb5
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1167
diff
changeset
|
1122 |
'Depth24Image [warning]: display bitmap creation failed' errorPrintCR. |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1123 |
^ nil |
194 | 1124 |
]. |
1125 |
form initGC. |
|
1126 |
||
1127 |
form |
|
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1128 |
copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1129 |
width:width height:height |
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1130 |
x:0 y:0 toX:0 y:0. |
194 | 1131 |
|
1132 |
^ form |
|
1133 |
||
1134 |
"Modified: 21.10.1995 / 19:30:11 / cg" |
|
810 | 1135 |
! ! |
1136 |
||
1137 |
!Depth24Image methodsFor:'dither helpers'! |
|
1138 |
||
842
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1139 |
floydSteinbergDitheredBitsDepth:depth |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1140 |
"return the bitmap for a dithered depth bitmap from the image. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1141 |
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
|
1142 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1143 |
|dstIndex "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1144 |
nextDst "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1145 |
bytesPerRow "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1146 |
bytesPerOutRow "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1147 |
outBits greyMap1 greyMap2 greyLevels |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1148 |
errorArray |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1149 |
errorArray1 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1150 |
e t v |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1151 |
w "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1152 |
h "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1153 |
bitCnt "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1154 |
byte "{Class: SmallInteger }" |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1155 |
grey dT |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1156 |
eR eRB eB eLB | |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1157 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1158 |
(samplesPerPixel ~~ 3 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1159 |
or:[bitsPerSample ~= #(8 8 8)]) ifTrue:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1160 |
^ super floydSteinbergDitheredBitsDepth:depth |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1161 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1162 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1163 |
w := width. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1164 |
h := height. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1165 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1166 |
bytesPerRow := self bytesPerRow. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1167 |
bytesPerOutRow := ((w * depth) + 7) // 8. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1168 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1169 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1170 |
^ nil |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1171 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1172 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1173 |
greyLevels := (1 bitShift:depth) - 1. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1174 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1175 |
greyMap1 := Array new:256. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1176 |
greyMap2 := Array new:256. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1177 |
1 to:256 do:[:i | |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1178 |
v := (greyLevels / 255 * (i-1)). |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1179 |
greyMap1 at:i put:v. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1180 |
greyMap2 at:i put:v. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1181 |
]. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1182 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1183 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1184 |
0 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1185 |
] ifFalse:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1186 |
b truncated |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1187 |
] |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1188 |
]) asByteArray. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1189 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1190 |
greyMap2 := (greyMap2 collect:[:el | |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1191 |
el isNil ifTrue:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1192 |
0 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1193 |
] ifFalse:[ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1194 |
((el - el truncated) "/ the error (0..1) |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1195 |
* 255) rounded |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1196 |
]]) asByteArray. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1197 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1198 |
errorArray := ByteArray new:(w + 2) * 2. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1199 |
errorArray1 := ByteArray new:(w + 2) * 2. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1200 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1201 |
%{ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1202 |
int __byte; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1203 |
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
|
1204 |
int __depth = __intVal(depth); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1205 |
int __dstIdx = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1206 |
int __srcIdx = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1207 |
int __bitCnt; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1208 |
int __grey; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1209 |
int __w = __intVal(w); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1210 |
int __h = __intVal(h); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1211 |
int __x; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1212 |
int __y; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1213 |
int __nextDst; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1214 |
int __nextSrc; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1215 |
int __bytesPerRow = __intVal(bytesPerRow); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1216 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1217 |
int __pixel; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1218 |
int __greyLevels = __intVal(greyLevels); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1219 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1220 |
char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1221 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1222 |
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
|
1223 |
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
|
1224 |
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
|
1225 |
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
|
1226 |
short *__t; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1227 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1228 |
bzero(errorArray1, (__w+2) * 2); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1229 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1230 |
__bitCnt = 8; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1231 |
for (__y=0; __y<__h; __y++) { |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1232 |
__nextDst = __dstIdx + __bytesPerOutRow; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1233 |
__nextSrc = __srcIdx + __bytesPerRow; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1234 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1235 |
__byte = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1236 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1237 |
__t = __errorArray; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1238 |
__errorArray = __errorArray1; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1239 |
__errorArray1 = __t; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1240 |
bzero(errorArray1, (__w+2) * 2); |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1241 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1242 |
for (__x=0; __x<__w; __x++) { |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1243 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1244 |
+ (__bytes[__srcIdx+1] * 6) |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1245 |
+ __bytes[__srcIdx+2]; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1246 |
__grey = __grey / 10; /* 0 .. 255 */ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1247 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1248 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1249 |
__err = __greyMap2[__grey]; /* 0.. 255 - error) */ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1250 |
__err += __errorArray[__x+1]; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1251 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1252 |
if (__err > 127) { /* dither says: next pixel */ |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1253 |
if ( __pixel != __greyLevels) |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1254 |
__pixel++; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1255 |
__err = __err - 255; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1256 |
} else { |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1257 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1258 |
if (__err) { |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1259 |
__e16 = __err >> 4; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1260 |
__eR = __e16 * 7; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1261 |
__eRB = __e16 * 1; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1262 |
__eB = __e16 * 5; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1263 |
__eLB = __err - __eR - __eRB - __eB; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1264 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1265 |
__errorArray [__x+1+1] += __eR; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1266 |
__errorArray1[__x+1+1] += __eRB; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1267 |
__errorArray1[__x+1 ] += __eB; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1268 |
__errorArray1[__x+1-1] += __eLB; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1269 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1270 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1271 |
__srcIdx += 3; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1272 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1273 |
__byte = (__byte << __depth) | __pixel; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1274 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1275 |
__bitCnt = __bitCnt - __depth; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1276 |
if (__bitCnt == 0) { |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1277 |
__outBits[__dstIdx] = __byte; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1278 |
__dstIdx++; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1279 |
__byte = 0; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1280 |
__bitCnt = 8; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1281 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1282 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1283 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1284 |
if (__bitCnt != 8) { |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1285 |
__byte = __byte << __bitCnt; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1286 |
__outBits[__dstIdx] = __byte; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1287 |
__bitCnt = 8; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1288 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1289 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1290 |
__srcIdx = __nextSrc; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1291 |
__dstIdx = __nextDst; |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1292 |
} |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1293 |
%}. |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1294 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1295 |
^ outBits |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1296 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1297 |
"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
|
1298 |
"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
|
1299 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1300 |
! |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1301 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1302 |
floydSteinbergDitheredMonochromeBits |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1303 |
"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
|
1304 |
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
|
1305 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1306 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1307 |
^ self floydSteinbergDitheredBitsDepth:1 |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1308 |
|
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1309 |
"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
|
1310 |
! |
dc8aa9127b49
added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
1311 |
|
810 | 1312 |
orderedDitheredBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
1313 |
"return the bitmap for a dithered depth-bitmap from the image; |
|
1314 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1315 |
Redefined to make use of knowing that pixels are 24-bit values." |
|
1316 |
||
1317 |
|f dH nDither v range |
|
1318 |
greyMap1 greyMap2 greyLevels outBits |
|
1319 |
bytesPerOutRow "{Class: SmallInteger }" |
|
1320 |
bytesPerRow "{Class: SmallInteger }" |
|
1321 |
w "{Class: SmallInteger }" |
|
1322 |
h "{Class: SmallInteger }"| |
|
1323 |
||
1324 |
photometric ~~ #rgb ifTrue:[ |
|
1325 |
self error:'invalid format'. |
|
1326 |
^ nil |
|
1327 |
]. |
|
1328 |
||
1329 |
nDither := ditherMatrix size. |
|
1330 |
dH := nDither / dW. |
|
1331 |
||
1332 |
w := width. |
|
1333 |
h := height. |
|
1334 |
||
1335 |
greyLevels := 1 bitShift:depth. |
|
1336 |
bytesPerRow := self bytesPerRow. |
|
1337 |
||
1338 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
1339 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
1340 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
|
1341 |
^ nil |
|
1342 |
]. |
|
1343 |
||
1344 |
greyMap1 := Array new:256. |
|
1345 |
greyMap2 := Array new:256. |
|
1346 |
range := greyLevels-1. |
|
1347 |
1 to:256 do:[:i | |
|
1348 |
v := (range / 255 * (i-1)). |
|
1349 |
greyMap1 at:i put:v. |
|
1350 |
greyMap2 at:i put:v. |
|
1351 |
]. |
|
1352 |
||
1353 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
1354 |
0 |
|
1355 |
] ifFalse:[ |
|
1356 |
b truncated |
|
1357 |
] |
|
1358 |
]) asByteArray. |
|
1359 |
||
1360 |
greyMap2 := (greyMap2 collect:[:el | |
|
1361 |
el isNil ifTrue:[ |
|
1362 |
0 |
|
1363 |
] ifFalse:[ |
|
1364 |
((el - el truncated) "/ the error (0..1) |
|
1365 |
* nDither) rounded |
|
1366 |
]]) asByteArray. |
|
1367 |
%{ |
|
1368 |
int __dW = __intVal(dW); |
|
1369 |
int __dH = __intVal(dH); |
|
1370 |
int __byte; |
|
1371 |
int __nDither = __intVal(nDither); |
|
1372 |
int __dT, __dO; |
|
1373 |
int __depth = __intVal(depth); |
|
1374 |
int __dstIdx = 0; |
|
1375 |
int __srcIdx = 0; |
|
1376 |
int __bitCnt; |
|
1377 |
int __grey; |
|
1378 |
int __w = __intVal(w); |
|
1379 |
int __h = __intVal(h); |
|
1380 |
int __x; |
|
1381 |
int __y; |
|
1382 |
int __oX, __oY, __dY; |
|
1383 |
int __nextDst; |
|
1384 |
int __nextSrc; |
|
1385 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1386 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
1387 |
int __pixel; |
|
1388 |
||
1389 |
char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
|
1390 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
|
1391 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1392 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
|
1393 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
1394 |
||
1395 |
__oY = __dY = 0; |
|
1396 |
for (__y=0; __y<__h; __y++) { |
|
1397 |
__nextDst = __dstIdx + __bytesPerOutRow; |
|
1398 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
1399 |
||
1400 |
__byte = 0; |
|
1401 |
__bitCnt = 8; |
|
1402 |
||
1403 |
__oX = 0; |
|
1404 |
||
1405 |
for (__x=0; __x<__w; __x++) { |
|
1406 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
1407 |
+ (__bytes[__srcIdx+1] * 6) |
|
1408 |
+ __bytes[__srcIdx+2]; |
|
1409 |
__grey = __grey / 10; /* 0 .. 255 */ |
|
1410 |
||
1411 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
|
1412 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
|
1413 |
__dT = __ditherMatrix[__dY + __oX]; |
|
1414 |
||
1415 |
if (__dO > __dT) /* dither says: next pixel */ |
|
1416 |
__pixel++; |
|
1417 |
||
1418 |
__srcIdx += 3; |
|
1419 |
||
1420 |
__oX++; |
|
1421 |
if (__oX == __dW) __oX = 0; |
|
1422 |
||
1423 |
__byte = (__byte << __depth) | __pixel; |
|
1424 |
||
1425 |
__bitCnt = __bitCnt - __depth; |
|
1426 |
if (__bitCnt == 0) { |
|
1427 |
__outBits[__dstIdx] = __byte; |
|
1428 |
__dstIdx++; |
|
1429 |
__byte = 0; |
|
1430 |
__bitCnt = 8; |
|
1431 |
} |
|
1432 |
} |
|
1433 |
||
1434 |
if (__bitCnt != 8) { |
|
1435 |
__byte = __byte << __bitCnt; |
|
1436 |
__outBits[__dstIdx] = __byte; |
|
1437 |
} |
|
1438 |
||
1439 |
__oY++; __dY += __dW; |
|
1440 |
if (__oY == __dH) { |
|
1441 |
__oY = 0; |
|
1442 |
__dY = 0; |
|
1443 |
} |
|
1444 |
||
1445 |
__srcIdx = __nextSrc; |
|
1446 |
__dstIdx = __nextDst; |
|
1447 |
} |
|
1448 |
%}. |
|
1449 |
||
1450 |
^ outBits |
|
1451 |
||
1452 |
" |
|
1453 |
|i| |
|
1454 |
||
1455 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1456 |
i asOrderedDitheredMonochromeImage inspect. |
|
1457 |
i asOrderedDitheredDepth2GrayImage inspect. |
|
1458 |
i asOrderedDitheredDepth4GrayImage inspect. |
|
1459 |
i asOrderedDitheredDepth8GrayImage inspect. |
|
1460 |
" |
|
1461 |
||
1462 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
1463 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
808 | 1464 |
! |
1465 |
||
810 | 1466 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
1467 |
"return the dithered monochrome bits for the receiver image; |
|
1468 |
with a constant ditherMatrix, this can be used for thresholding. |
|
1469 |
Redefined to make use of knowing that pixels are 24-bit values." |
|
1470 |
||
1471 |
|f dH nDither |
|
1472 |
greyMap monoBits |
|
1473 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
1474 |
bytesPerRow "{Class: SmallInteger }" |
|
1475 |
w "{Class: SmallInteger }" |
|
1476 |
h "{Class: SmallInteger }"| |
|
1477 |
||
1478 |
photometric ~~ #rgb ifTrue:[ |
|
1479 |
self error:'invalid format'. |
|
1480 |
^ nil |
|
1481 |
]. |
|
1482 |
||
1483 |
nDither := ditherMatrix size. |
|
1484 |
dH := nDither / dW. |
|
1485 |
||
1486 |
w := width. |
|
1487 |
h := height. |
|
1488 |
||
1489 |
bytesPerRow := self bytesPerRow. |
|
1490 |
||
1491 |
bytesPerMonoRow := w + 7 // 8. |
|
1492 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
1493 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
1494 |
^ nil |
|
1495 |
]. |
|
1496 |
||
1497 |
%{ |
|
1498 |
int __dW = __intVal(dW); |
|
1499 |
int __dH = __intVal(dH); |
|
1500 |
int __byte; |
|
1501 |
int __nDither = __intVal(nDither); |
|
1502 |
int __dT; |
|
1503 |
int __dstIdx = 0; |
|
1504 |
int __srcIdx = 0; |
|
1505 |
int __bitCnt; |
|
1506 |
int __grey; |
|
1507 |
int __w = __intVal(w); |
|
1508 |
int __h = __intVal(h); |
|
1509 |
int __x; |
|
1510 |
int __y; |
|
1511 |
int __oX, __oY, __dY; |
|
1512 |
int __nextDst; |
|
1513 |
int __nextSrc; |
|
1514 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
1515 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
1516 |
||
1517 |
char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
|
1518 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
|
1519 |
unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1520 |
||
1521 |
__oY = __dY = 0; |
|
1522 |
for (__y=0; __y<__h; __y++) { |
|
1523 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
|
1524 |
__nextSrc = __srcIdx + __bytesPerRow; |
|
1525 |
||
1526 |
__byte = 0; |
|
1527 |
__bitCnt = 8; |
|
1528 |
||
1529 |
__oX = 0; |
|
1530 |
||
1531 |
for (__x=0; __x<__w; __x++) { |
|
1532 |
__grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */ |
|
1533 |
+ (__bytes[__srcIdx+1] * 6) |
|
1534 |
+ __bytes[__srcIdx+2]; |
|
1535 |
__grey = __grey * (__nDither+1) / 2550; /* 0 .. nDither+1 */ |
|
1536 |
__srcIdx += 3; |
|
1537 |
||
1538 |
__dT = __ditherMatrix[__dY + __oX]; |
|
1539 |
||
1540 |
__oX++; |
|
1541 |
if (__oX == __dW) __oX = 0; |
|
1542 |
||
1543 |
__byte = __byte << 1; |
|
1544 |
if (__grey > __dT) { |
|
1545 |
__byte = __byte | 1; /* white */ |
|
1546 |
} |
|
1547 |
||
1548 |
__bitCnt--; |
|
1549 |
if (__bitCnt == 0) { |
|
1550 |
__monoBits[__dstIdx] = __byte; |
|
1551 |
__dstIdx++; |
|
1552 |
__byte = 0; |
|
1553 |
__bitCnt = 8; |
|
1554 |
} |
|
1555 |
} |
|
1556 |
||
1557 |
if (__bitCnt != 8) { |
|
1558 |
__byte = __byte << __bitCnt; |
|
1559 |
__monoBits[__dstIdx] = __byte; |
|
1560 |
} |
|
1561 |
||
1562 |
__oY++; __dY += __dW; |
|
1563 |
if (__oY == __dH) { |
|
1564 |
__oY = 0; |
|
1565 |
__dY = 0; |
|
1566 |
} |
|
1567 |
||
1568 |
__srcIdx = __nextSrc; |
|
1569 |
__dstIdx = __nextDst; |
|
1570 |
} |
|
1571 |
%}. |
|
1572 |
||
1573 |
^ monoBits |
|
1574 |
||
1575 |
" |
|
1576 |
|i f| |
|
1577 |
||
1578 |
i := Image fromFile:'bitmaps/granite.tiff'. |
|
1579 |
f := i asOrderedDitheredMonochromeFormOn:Display. |
|
1580 |
" |
|
1581 |
||
1582 |
"Created: 7.6.1996 / 10:48:06 / cg" |
|
1583 |
"Modified: 7.6.1996 / 11:08:50 / cg" |
|
1584 |
! |
|
1585 |
||
1586 |
threshold8BitGrayBits |
|
808 | 1587 |
"return the bits for an 8-bit grey image from the receiver. |
1588 |
Special code, since this is a common case." |
|
1589 |
||
1590 |
|greyBits |
|
1591 |
srcIndex "{ Class: SmallInteger }" |
|
1592 |
dstIndex "{ Class: SmallInteger }"| |
|
1593 |
||
1594 |
greyBits := ByteArray uninitializedNew:(width * height). |
|
1595 |
%{ |
|
1596 |
register unsigned char *srcPtr, *dstPtr; |
|
1597 |
register __v; |
|
1598 |
register i; |
|
1599 |
||
1600 |
if ((__Class(__INST(bytes)) == ByteArray) |
|
1601 |
&& (__Class(greyBits) == ByteArray)) { |
|
1602 |
srcPtr = __ByteArrayInstPtr(__INST(bytes))->ba_element; |
|
1603 |
dstPtr = __ByteArrayInstPtr(greyBits)->ba_element; |
|
1604 |
||
1605 |
i = __intVal(__INST(height)) * __intVal(__INST(width)); |
|
1606 |
||
1607 |
for (; i > 0; i--) { |
|
1608 |
__v = (srcPtr[0] * 3); /* 3*r + 6*g + b ; 0 .. 2550 */ |
|
1609 |
__v += (srcPtr[1] * 6); |
|
1610 |
__v += srcPtr[2]; |
|
1611 |
srcPtr += 3; |
|
1612 |
__v /= 10; /* 0..255 */ |
|
1613 |
*dstPtr++ = __v ; |
|
1614 |
} |
|
1615 |
} |
|
1616 |
%}. |
|
1617 |
^ greyBits |
|
1618 |
||
1 | 1619 |
! ! |
1620 |
||
282 | 1621 |
!Depth24Image methodsFor:'enumerating'! |
1 | 1622 |
|
798 | 1623 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
282 | 1624 |
"perform aBlock for each pixel from x1 to x2 in row y. |
1625 |
The block is passed the color at each pixel. |
|
1626 |
This method allows slighly faster processing of an |
|
1627 |
image than using atX:y:, since some processing can be |
|
1628 |
avoided when going from pixel to pixel. However, for |
|
1629 |
real image processing, specialized methods should be written." |
|
1 | 1630 |
|
282 | 1631 |
|srcIndex "{ Class: SmallInteger }" |
1632 |
x1 "{ Class: SmallInteger }" |
|
1633 |
x2 "{ Class: SmallInteger }" |
|
1634 |
rVal "{ Class: SmallInteger }" |
|
1635 |
gVal "{ Class: SmallInteger }" |
|
1636 |
bVal "{ Class: SmallInteger }" |
|
1637 |
lastR lastG lastB lastColor| |
|
1638 |
||
1639 |
photometric ~~ #rgb ifTrue:[ |
|
805 | 1640 |
^ super colorsAtY:y from:xLow to:xHigh do:aBlock. |
282 | 1641 |
]. |
1642 |
||
1643 |
x1 := xLow. |
|
1644 |
x2 := xHigh. |
|
1645 |
||
1646 |
srcIndex := 1 + (((width * y) + x1) * 3). |
|
1 | 1647 |
|
282 | 1648 |
x1 to:x2 do:[:x | |
798 | 1649 |
rVal := bytes at:(srcIndex). |
1650 |
gVal := bytes at:(srcIndex + 1). |
|
1651 |
bVal := bytes at:(srcIndex + 2). |
|
1652 |
srcIndex := srcIndex + 3. |
|
1653 |
||
1654 |
(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[ |
|
1350 | 1655 |
lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal * 100 / 255. |
798 | 1656 |
lastR := rVal. |
1657 |
lastG := gVal. |
|
1658 |
lastB := bVal. |
|
1659 |
]. |
|
1660 |
aBlock value:x value:lastColor |
|
282 | 1661 |
] |
798 | 1662 |
|
1663 |
"Created: 7.6.1996 / 19:12:28 / cg" |
|
805 | 1664 |
"Modified: 8.6.1996 / 10:16:51 / cg" |
282 | 1665 |
! |
1 | 1666 |
|
798 | 1667 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
282 | 1668 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
1669 |
The block is passed the pixelValue at each pixel. |
|
1670 |
This method allows slighly faster processing of an |
|
1671 |
image than using valueAtX:y:, since some processing can be |
|
1672 |
avoided when going from pixel to pixel. However, for |
|
1673 |
real image processing, specialized methods should be written. |
|
1674 |
Notice that the pixelValue is the r/g/b value packed into an integer |
|
1675 |
(r bitShift:16) bitOr:(g bitSHift:8) bitOr:b" |
|
1676 |
||
1677 |
|srcIndex "{ Class: SmallInteger }" |
|
1678 |
x1 "{ Class: SmallInteger }" |
|
1679 |
x2 "{ Class: SmallInteger }" |
|
1680 |
r "{ Class: SmallInteger }" |
|
1681 |
g "{ Class: SmallInteger }" |
|
1682 |
b "{ Class: SmallInteger }"| |
|
1683 |
||
1684 |
x1 := xLow. |
|
1685 |
x2 := xHigh. |
|
1686 |
||
1687 |
srcIndex := 1 + (((width * y) + x1) * 3). |
|
1688 |
||
1689 |
x1 to:x2 do:[:x | |
|
798 | 1690 |
r := bytes at:(srcIndex). |
1691 |
g := bytes at:(srcIndex + 1). |
|
1692 |
b := bytes at:(srcIndex + 2). |
|
1693 |
srcIndex := srcIndex + 3. |
|
1694 |
aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b) |
|
282 | 1695 |
] |
798 | 1696 |
|
1697 |
"Created: 7.6.1996 / 19:09:40 / cg" |
|
282 | 1698 |
! ! |
1699 |
||
1700 |
!Depth24Image methodsFor:'magnification'! |
|
1 | 1701 |
|
1577 | 1702 |
hardMagnifiedBy:scalePoint |
1703 |
"return a new image magnified by scalePoint, aPoint. |
|
1 | 1704 |
This is the general magnification method, handling non-integral values" |
1705 |
||
1706 |
|mX mY |
|
1707 |
newWidth "{ Class: SmallInteger }" |
|
1708 |
newHeight "{ Class: SmallInteger }" |
|
1709 |
w "{ Class: SmallInteger }" |
|
1710 |
h "{ Class: SmallInteger }" |
|
1711 |
newImage newBytes |
|
1712 |
value "{ Class: SmallInteger }" |
|
1713 |
srcRowIdx "{ Class: SmallInteger }" |
|
1714 |
srcIndex "{ Class: SmallInteger }" |
|
1577 | 1715 |
dstIndex "{ Class: SmallInteger }" |
1716 |
newMask| |
|
1 | 1717 |
|
1577 | 1718 |
mX := scalePoint x. |
1719 |
mY := scalePoint y. |
|
1 | 1720 |
((mX < 0) or:[mY < 0]) ifTrue:[^ nil]. |
1721 |
((mX = 1) and:[mY = 1]) ifTrue:[^ self]. |
|
1722 |
||
1723 |
newWidth := (width * mX) truncated. |
|
1724 |
newHeight := (height * mY) truncated. |
|
1725 |
newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight). |
|
1726 |
||
1577 | 1727 |
mask notNil ifTrue:[ |
1728 |
newMask := (mask magnifiedBy:scalePoint) |
|
1729 |
]. |
|
1730 |
||
1 | 1731 |
newImage := self species new. |
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1732 |
newImage |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1733 |
width:newWidth |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1734 |
height:newHeight |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1735 |
photometric:photometric |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1736 |
samplesPerPixel:samplesPerPixel |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1737 |
bitsPerSample:#(8 8 8) |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1738 |
colorMap:nil |
1577 | 1739 |
bits:newBytes |
1740 |
mask:newMask. |
|
1 | 1741 |
|
1742 |
"walk over destination image fetching pixels from source image" |
|
1743 |
||
1744 |
mY := mY asFloat. |
|
1745 |
mX := mX asFloat. |
|
1746 |
%{ |
|
1747 |
REGISTER unsigned char *_dstP = _ByteArrayInstPtr(newBytes)->ba_element; |
|
1748 |
unsigned char *_srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element; |
|
1749 |
unsigned char *_srcRowP, *sP; |
|
1750 |
int _width3 = _intVal(_INST(width)) * 3; |
|
1751 |
int _w = _intVal(newWidth) - 1; |
|
1752 |
int _h = _intVal(newHeight) - 1; |
|
1753 |
int _row, _col; |
|
1754 |
double _mX = _floatVal(mX); |
|
1755 |
double _mY = _floatVal(mY); |
|
1756 |
||
1757 |
for (_row = 0; _row <= _h; _row++) { |
|
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1758 |
_srcRowP = _srcP + (_width3 * (int)((double)_row / _mY)); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1759 |
for (_col = 0; _col <= _w; _col++) { |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1760 |
sP = _srcRowP + (((int)((double)_col / _mX)) * 3); |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1761 |
_dstP[0] = sP[0]; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1762 |
_dstP[1] = sP[1]; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1763 |
_dstP[2] = sP[2]; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1764 |
_dstP += 3; |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1765 |
} |
1 | 1766 |
} |
1767 |
%} |
|
1768 |
. |
|
81 | 1769 |
" the above C-code is equivalent to: |
1770 |
||
1 | 1771 |
dstIndex := 1. |
1772 |
w := newWidth - 1. |
|
1773 |
h := newHeight - 1. |
|
1774 |
0 to:h do:[:row | |
|
886
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1775 |
srcRowIdx := (width * 3 * (row // mY)) + 1. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1776 |
0 to:w do:[:col | |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1777 |
srcIndex := srcRowIdx + ((col // mX) * 3). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1778 |
value := bytes at:srcIndex. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1779 |
newBytes at:dstIndex put:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1780 |
value := bytes at:(srcIndex + 1). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1781 |
newBytes at:(dstIndex + 1) put:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1782 |
value := bytes at:(srcIndex + 2). |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1783 |
newBytes at:(dstIndex + 2) put:value. |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1784 |
dstIndex := dstIndex + 3 |
04b88b61c640
tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents:
858
diff
changeset
|
1785 |
] |
1 | 1786 |
]. |
1787 |
" |
|
1788 |
^ newImage |
|
282 | 1789 |
! |
1790 |
||
1791 |
magnifyRowFrom:srcBytes offset:srcStart |
|
1792 |
into:dstBytes offset:dstStart factor:mX |
|
1793 |
||
1794 |
"magnify a single pixel row - can only magnify by integer factors" |
|
1795 |
||
1796 |
%{ |
|
1797 |
unsigned char *srcP, *dstP; |
|
1798 |
int _mag; |
|
1799 |
REGISTER int i; |
|
1800 |
REGISTER unsigned char byte1, byte2, byte3; |
|
1801 |
int _pixels; |
|
1802 |
OBJ w = _INST(width); |
|
1803 |
||
1804 |
if (__bothSmallInteger(srcStart, dstStart) |
|
1805 |
&& __bothSmallInteger(w, mX) |
|
1806 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) { |
|
1807 |
_mag = _intVal(mX); |
|
1808 |
srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart); |
|
1809 |
dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart); |
|
1810 |
_pixels = _intVal(w); |
|
1811 |
||
1812 |
while (_pixels--) { |
|
1813 |
byte1 = *srcP; |
|
1814 |
byte2 = *(srcP+1); |
|
1815 |
byte3 = *(srcP+2); |
|
1816 |
srcP += 3; |
|
1817 |
for (i=_mag; i>0; i--) { |
|
1818 |
*dstP = byte1; |
|
1819 |
*(dstP+1) = byte2; |
|
1820 |
*(dstP+2) = byte3; |
|
1821 |
dstP += 3; |
|
1822 |
} |
|
1823 |
} |
|
1824 |
RETURN (self); |
|
1825 |
} |
|
1826 |
%} |
|
1827 |
. |
|
1828 |
self primitiveFailed |
|
1 | 1829 |
! ! |
282 | 1830 |
|
1831 |
!Depth24Image methodsFor:'queries'! |
|
1832 |
||
1833 |
bitsPerPixel |
|
1834 |
"return the number of bits per pixel" |
|
1835 |
||
1836 |
^ 24 |
|
1837 |
! |
|
1838 |
||
1839 |
bitsPerRow |
|
1840 |
"return the number of bits in one scanline of the image" |
|
1841 |
||
1842 |
^ width * 24 |
|
1843 |
! |
|
1844 |
||
1845 |
bitsPerSample |
|
1846 |
"return the number of bits per sample. |
|
1847 |
The return value is an array of bits-per-plane." |
|
1848 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1849 |
bitsPerSample notNil ifTrue:[^ bitsPerSample]. |
282 | 1850 |
^ #(8 8 8) |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1851 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1852 |
"Modified: 10.6.1996 / 18:02:33 / cg" |
282 | 1853 |
! |
1854 |
||
805 | 1855 |
blueBitsOf:pixel |
1856 |
^ pixel bitAnd:16rFF. |
|
1857 |
||
1858 |
"Created: 8.6.1996 / 09:56:20 / cg" |
|
1859 |
! |
|
1860 |
||
1861 |
blueComponentOf:pixel |
|
1862 |
^ (100.0 / 255.0) * (pixel bitAnd:16rFF) |
|
1863 |
||
1864 |
"Created: 8.6.1996 / 08:42:44 / cg" |
|
1865 |
"Modified: 8.6.1996 / 09:57:41 / cg" |
|
1866 |
! |
|
1867 |
||
282 | 1868 |
bytesPerRow |
1869 |
"return the number of bytes in one scanline of the image" |
|
1870 |
||
1871 |
^ width * 3 |
|
1872 |
! |
|
1873 |
||
805 | 1874 |
greenBitsOf:pixel |
1875 |
^ (pixel bitShift:-8) bitAnd:16rFF. |
|
1876 |
||
1877 |
"Modified: 8.6.1996 / 08:56:28 / cg" |
|
1878 |
"Created: 8.6.1996 / 09:56:30 / cg" |
|
1879 |
! |
|
1880 |
||
1881 |
greenComponentOf:pixel |
|
1882 |
^ (100.0 / 255.0) * (pixel bitShift:-8) bitAnd:16rFF. |
|
1883 |
||
1884 |
"Created: 8.6.1996 / 08:42:37 / cg" |
|
1885 |
"Modified: 8.6.1996 / 09:57:32 / cg" |
|
1886 |
! |
|
1887 |
||
1888 |
redBitsOf:pixel |
|
1889 |
^ (pixel bitShift:-16) bitAnd:16rFF. |
|
1890 |
||
1891 |
"Modified: 8.6.1996 / 08:56:31 / cg" |
|
1892 |
"Created: 8.6.1996 / 09:56:39 / cg" |
|
1893 |
! |
|
1894 |
||
1895 |
redComponentOf:pixel |
|
1896 |
^ (100.0 / 255.0) * (pixel bitShift:-16) bitAnd:16rFF. |
|
1897 |
||
1898 |
"Created: 8.6.1996 / 08:42:25 / cg" |
|
1899 |
"Modified: 8.6.1996 / 09:57:23 / cg" |
|
1900 |
! |
|
1901 |
||
282 | 1902 |
samplesPerPixel |
1903 |
"return the number of samples per pixel in the image." |
|
1904 |
||
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1905 |
samplesPerPixel notNil ifTrue:[^ samplesPerPixel]. |
282 | 1906 |
^ 3 |
813
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1907 |
|
8bc17dba7a02
removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
1908 |
"Modified: 10.6.1996 / 18:03:09 / cg" |
282 | 1909 |
! ! |
1910 |
||
1167 | 1911 |
!Depth24Image class methodsFor:'documentation'! |
282 | 1912 |
|
1913 |
version |
|
1598 | 1914 |
^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.45 1997-04-14 19:03:08 cg Exp $' |
282 | 1915 |
! ! |