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