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