author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 03 Oct 2017 11:38:15 +0100 | |
branch | jv |
changeset 8188 | 00df122d8bd4 |
parent 7821 | 8d6b6486b14f |
child 8117 | 8f10ae244f9c |
child 8426 | e2051b1553f0 |
permissions | -rw-r--r-- |
4 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 3 |
All Rights Reserved |
4 | 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 |
||
6827 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Image subclass:#Depth4Image |
579 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Graphics-Images' |
|
1 | 21 |
! |
22 |
||
46 | 23 |
!Depth4Image class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
81 | 28 |
All Rights Reserved |
4 | 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 |
! |
|
4 | 38 |
|
46 | 39 |
documentation |
40 |
" |
|
41 |
this class represents 16-color (4 bit / pixel) images. |
|
42 |
Most images coming from the windows world are represented as Depth4Images. |
|
43 |
It mainly consists of methods already implemented in Image, |
|
44 |
reimplemented here for more performance. |
|
7189 | 45 |
Pixels for even x coordinates are stored in the left (high) nibble. |
46 |
Odd x pixels are in the right (low) nibble. |
|
47 |
||
611 | 48 |
[author:] |
7189 | 49 |
Claus Gittinger |
611 | 50 |
|
51 |
[see also:] |
|
7189 | 52 |
Depth1Image Depth2Image Depth8Image Depth16Image Depth24Image |
53 |
ImageReader |
|
46 | 54 |
" |
55 |
! ! |
|
4 | 56 |
|
89 | 57 |
!Depth4Image class methodsFor:'queries'! |
58 |
||
4758 | 59 |
defaultPhotometric |
60 |
"return the default photometric pixel interpretation" |
|
61 |
||
6827 | 62 |
^ #blackIs0 "/ #palette |
4758 | 63 |
|
64 |
"Created: / 27-05-2007 / 14:04:27 / cg" |
|
65 |
! |
|
66 |
||
89 | 67 |
imageDepth |
579 | 68 |
"return the depth of images represented by instances of |
69 |
this class - here we return 4" |
|
70 |
||
89 | 71 |
^ 4 |
579 | 72 |
|
73 |
"Modified: 20.4.1996 / 23:40:18 / cg" |
|
89 | 74 |
! ! |
75 |
||
3263 | 76 |
!Depth4Image methodsFor:'accessing-pixels'! |
1 | 77 |
|
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
78 |
pixelAtX:x y:y |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
79 |
"retrieve a pixel at x/y; return a pixelValue. |
7516 | 80 |
The interpretation of the returned value depends on the photometric |
81 |
and the colormap. See also Image>>atX:y:) |
|
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
82 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
83 |
x = width-1, y=height-1 for lower right pixel" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
84 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
85 |
|lineIndex "{ Class: SmallInteger }" |
4904 | 86 |
byteIndex "{ Class: SmallInteger }" |
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
87 |
byte "{ Class: SmallInteger }" | |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
88 |
|
6298 | 89 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
90 |
||
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
91 |
lineIndex := (self bytesPerRow * y) + 1. |
4904 | 92 |
byteIndex := lineIndex + (x // 2). |
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
93 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
94 |
"left pixel in high bits" |
4904 | 95 |
byteIndex > bytes size ifTrue:[ |
6298 | 96 |
^ 0 |
4904 | 97 |
]. |
98 |
byte := bytes at:byteIndex. |
|
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
99 |
x even ifTrue:[ |
6298 | 100 |
^ (byte bitShift:-4) bitAnd:16rF. |
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
101 |
]. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
102 |
^ byte bitAnd:16rF. |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
103 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
104 |
"Created: 24.4.1997 / 16:06:43 / cg" |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
105 |
! |
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
106 |
|
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
107 |
pixelAtX:x y:y put:aPixelValue |
1 | 108 |
"set the pixel at x/y to aPixelValue. |
7516 | 109 |
The interpretation of the pixelValue depends on the photometric |
110 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1 | 111 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
112 |
x = width-1, y=height-1 for lower right pixel" |
|
113 |
||
46 | 114 |
|lineIndex "{ Class: SmallInteger }" |
115 |
index "{ Class: SmallInteger }" |
|
116 |
byte "{ Class: SmallInteger }" | |
|
1 | 117 |
|
118 |
lineIndex := (self bytesPerRow * y) + 1. |
|
119 |
||
120 |
"left pixel is in high bits" |
|
121 |
index := lineIndex + (x // 2). |
|
122 |
byte := bytes at:index. |
|
123 |
x even ifTrue:[ |
|
7516 | 124 |
byte := (byte bitAnd:16rF) bitOr:(aPixelValue bitShift:4) |
1 | 125 |
] ifFalse:[ |
7516 | 126 |
byte := (byte bitAnd:16rF0) bitOr:aPixelValue |
1 | 127 |
]. |
128 |
bytes at:index put:byte |
|
280 | 129 |
|
1656
ebcad6911ddb
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
810
diff
changeset
|
130 |
"Created: 24.4.1997 / 17:06:39 / cg" |
1816 | 131 |
! |
132 |
||
3872 | 133 |
rowAt:y into:aPixelBuffer |
1816 | 134 |
"fill aBuffer with pixel values retrieved from a single row. |
3872 | 135 |
Notice: row coordinate starts with 0." |
1816 | 136 |
|
137 |
|lineIndex "{ Class: SmallInteger }" |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
138 |
byte "{ Class: SmallInteger }" |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
139 |
w "{ Class: SmallInteger }" |
7821 | 140 |
pixel bytes| |
1816 | 141 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
142 |
bytes := self bits. |
1816 | 143 |
w := width - 1. |
7821 | 144 |
lineIndex := self bytesPerRow * y. |
1816 | 145 |
0 to:w do:[:x | |
7821 | 146 |
x even ifTrue:[ |
147 |
lineIndex := lineIndex + 1. |
|
148 |
byte := bytes at:lineIndex. |
|
149 |
pixel := (byte bitShift:-4) bitAnd:16rF. |
|
150 |
] ifFalse:[ |
|
151 |
pixel := byte bitAnd:16rF. |
|
152 |
]. |
|
153 |
aPixelBuffer at:x+1 put:pixel. |
|
1816 | 154 |
]. |
155 |
||
7821 | 156 |
"Created: / 21-07-1997 / 18:04:00 / cg" |
157 |
"Modified: / 30-01-2017 / 18:51:24 / stefan" |
|
81 | 158 |
! ! |
159 |
||
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
160 |
!Depth4Image methodsFor:'converting images'! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
161 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
162 |
anyImageAsTrueColorFormOn:aDevice |
2197
1b88e629091d
avoid a byte fetch in colorsAtY:from:to:do:
Claus Gittinger <cg@exept.de>
parents:
2186
diff
changeset
|
163 |
"return a true-color device-form for receiver. |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
164 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
165 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
166 |
|depth |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
167 |
colorValues |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
168 |
form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel |
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
169 |
usedDevicePadding usedDeviceBytesPerRow padd| |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
170 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
171 |
depth := aDevice depth. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
172 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
173 |
"/ gather r/g/b values for all colors in the map ... |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
174 |
|
2203
49d06f1c9fe2
use common colorMap helper when converting to rgb-device form
Claus Gittinger <cg@exept.de>
parents:
2197
diff
changeset
|
175 |
colorValues := self rgbColormapFor:aDevice. |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
176 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
177 |
bestFormat := self bestSupportedImageFormatFor:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
178 |
usedDeviceDepth := bestFormat at:#depth. |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2523
diff
changeset
|
179 |
usedDeviceDepth == 1 ifTrue:[ |
7499 | 180 |
^ self asMonochromeFormOn:aDevice |
2864
dd151bfdff9d
care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents:
2523
diff
changeset
|
181 |
]. |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
182 |
usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
183 |
usedDevicePadding := bestFormat at:#padding. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
184 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
185 |
usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
186 |
padd := usedDeviceBytesPerRow -( self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:8). |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
187 |
imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height). |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
188 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
189 |
"/ for now, only support some depths |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
190 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
191 |
usedDeviceBitsPerPixel == 16 ifTrue:[ |
7499 | 192 |
"/ 16 bits/pixel |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
193 |
|
7499 | 194 |
"/ now, walk over the image and replace |
195 |
"/ colorMap indices by color values in the bits array |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
196 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
197 |
%{ |
7499 | 198 |
unsigned char *srcPtr = 0; |
199 |
unsigned char *dstPtr = 0; |
|
200 |
OBJ _bytes = __INST(bytes); |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
201 |
|
7499 | 202 |
if (__isByteArrayLike(_bytes)) { |
203 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
|
204 |
} else { |
|
205 |
if (__isExternalBytesLike(_bytes)) { |
|
206 |
srcPtr = __externalBytesAddress(_bytes); |
|
207 |
} |
|
208 |
} |
|
209 |
if (__isByteArray(imageBits)) { |
|
210 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
211 |
} else { |
|
212 |
if (__isExternalBytesLike(imageBits)) { |
|
213 |
dstPtr = __externalBytesAddress(imageBits); |
|
214 |
} |
|
215 |
} |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
216 |
|
7499 | 217 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
218 |
&& __isArrayLike(colorValues) |
|
219 |
&& srcPtr |
|
220 |
&& dstPtr) { |
|
221 |
int r,p; |
|
222 |
int x, y, w, h, nPix; |
|
223 |
int byte; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
224 |
|
7499 | 225 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
226 |
|
7499 | 227 |
w = __intVal(__INST(width)); |
228 |
h = __intVal(__INST(height)); |
|
229 |
r = 0; |
|
230 |
p = __intVal(padd); |
|
231 |
nPix = w * h; |
|
232 |
while (nPix-- > 0) { |
|
233 |
unsigned idx, v; |
|
234 |
OBJ clr; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
235 |
|
7499 | 236 |
if (r & 1) { |
237 |
idx = byte & 0xF; |
|
238 |
} else { |
|
239 |
byte = *srcPtr++; |
|
240 |
idx = (byte>>4) & 0xF; |
|
241 |
} |
|
242 |
clr = ap[idx]; |
|
243 |
v = __intVal(clr); |
|
2401 | 244 |
#ifdef __MSBFIRST |
7499 | 245 |
((short *)dstPtr)[0] = v; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
246 |
#else |
2225
8fb244eaaf90
the SWAP_BYTES macro does not work yet.
Claus Gittinger <cg@exept.de>
parents:
2215
diff
changeset
|
247 |
# ifdef xxSWAP_BYTES |
7499 | 248 |
SWAP_BYTES(v); |
249 |
((short *)dstPtr)[0] = v; |
|
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
250 |
# else |
7499 | 251 |
dstPtr[0] = (v>>8) & 0xFF; |
252 |
dstPtr[1] = (v) & 0xFF; |
|
2215
f7183f306690
fixed conversion to 24 & 32 displays
Claus Gittinger <cg@exept.de>
parents:
2203
diff
changeset
|
253 |
# endif |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
254 |
#endif |
7499 | 255 |
dstPtr += 2; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
256 |
|
7499 | 257 |
if (++r == w) { |
258 |
dstPtr += p; |
|
259 |
r = 0; |
|
260 |
} |
|
261 |
} |
|
262 |
} |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
263 |
%}. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
264 |
] ifFalse:[ |
7499 | 265 |
usedDeviceBitsPerPixel == 32 ifTrue:[ |
266 |
"/ 32 bits/pixel |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
267 |
|
7499 | 268 |
"/ now, walk over the image and replace |
269 |
"/ colorMap indices by color values in the bits array |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
270 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
271 |
%{ |
7499 | 272 |
unsigned char *srcPtr = 0; |
273 |
unsigned char *dstPtr = 0; |
|
274 |
OBJ _bytes = __INST(bytes); |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
275 |
|
7499 | 276 |
if (__isByteArrayLike(_bytes)) { |
277 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
|
278 |
} else { |
|
279 |
if (__isExternalBytesLike(_bytes)) { |
|
280 |
srcPtr = __externalBytesAddress(_bytes); |
|
281 |
} |
|
282 |
} |
|
283 |
if (__isByteArray(imageBits)) { |
|
284 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
285 |
} else { |
|
286 |
if (__isExternalBytesLike(imageBits)) { |
|
287 |
dstPtr = __externalBytesAddress(imageBits); |
|
288 |
} |
|
289 |
} |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
290 |
|
7499 | 291 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
292 |
&& __isArrayLike(colorValues) |
|
293 |
&& srcPtr |
|
294 |
&& dstPtr) { |
|
295 |
int x, y, w, h, nPix; |
|
296 |
int r,p; |
|
297 |
int byte; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
298 |
|
7499 | 299 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
300 |
|
7499 | 301 |
w = __intVal(__INST(width)); |
302 |
h = __intVal(__INST(height)); |
|
303 |
r = 0; |
|
304 |
p = __intVal(padd); |
|
305 |
nPix = w * h; |
|
306 |
while (nPix > 0) { |
|
307 |
unsigned idx, v; |
|
308 |
OBJ clr; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
309 |
|
7499 | 310 |
if (r & 1) { |
311 |
idx = byte & 0xF; |
|
312 |
} else { |
|
313 |
byte = *srcPtr++; |
|
314 |
idx = (byte>>4) & 0xF; |
|
315 |
} |
|
316 |
clr = ap[idx]; |
|
317 |
v = __intVal(clr); |
|
2401 | 318 |
#ifdef __MSBFIRST |
7499 | 319 |
((long *)dstPtr)[0] = v; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
320 |
#else |
7499 | 321 |
dstPtr[0] = (v>>24) & 0xFF; |
322 |
dstPtr[1] = (v>>16) & 0xFF; |
|
323 |
dstPtr[2] = (v>>8) & 0xFF; |
|
324 |
dstPtr[3] = (v) & 0xFF; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
325 |
#endif |
7499 | 326 |
dstPtr += 4; |
327 |
nPix--; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
328 |
|
7499 | 329 |
if (++r == w) { |
330 |
dstPtr += p; |
|
331 |
r = 0; |
|
332 |
} |
|
333 |
} |
|
334 |
} |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
335 |
%}. |
7499 | 336 |
] ifFalse:[ |
337 |
usedDeviceBitsPerPixel == 8 ifTrue:[ |
|
338 |
"/ 8 bits/pixel |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
339 |
|
7499 | 340 |
"/ now, walk over the image and replace |
341 |
"/ colorMap indices by color values in the bits array |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
342 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
343 |
%{ |
7499 | 344 |
unsigned char *srcPtr = 0; |
345 |
unsigned char *dstPtr = 0; |
|
346 |
OBJ _bytes = __INST(bytes); |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
347 |
|
7499 | 348 |
if (__isByteArrayLike(_bytes)) { |
349 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
|
350 |
} else { |
|
351 |
if (__isExternalBytesLike(_bytes)) { |
|
352 |
srcPtr = __externalBytesAddress(_bytes); |
|
353 |
} |
|
354 |
} |
|
355 |
if (__isByteArray(imageBits)) { |
|
356 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
357 |
} else { |
|
358 |
if (__isExternalBytesLike(imageBits)) { |
|
359 |
dstPtr = __externalBytesAddress(imageBits); |
|
360 |
} |
|
361 |
} |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
362 |
|
7499 | 363 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
364 |
&& __isArrayLike(colorValues) |
|
365 |
&& srcPtr |
|
366 |
&& dstPtr) { |
|
367 |
int x, y, w, h, nPix; |
|
368 |
int r,p, byte; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
369 |
|
7499 | 370 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
371 |
|
7499 | 372 |
w = __intVal(__INST(width)); |
373 |
h = __intVal(__INST(height)); |
|
374 |
r = 0; |
|
375 |
p = __intVal(padd); |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
376 |
|
7499 | 377 |
nPix = w * h; |
378 |
while (nPix > 0) { |
|
379 |
unsigned idx, v; |
|
380 |
OBJ clr; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
381 |
|
7499 | 382 |
if (r & 1) { |
383 |
idx = byte & 0xF; |
|
384 |
} else { |
|
385 |
byte = *srcPtr++; |
|
386 |
idx = (byte>>4) & 0xF; |
|
387 |
} |
|
388 |
clr = ap[idx]; |
|
389 |
v = __intVal(clr); |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
390 |
|
7499 | 391 |
dstPtr[0] = v; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
392 |
|
7499 | 393 |
dstPtr += 1; |
394 |
nPix--; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
395 |
|
7499 | 396 |
if (++r == w) { |
397 |
dstPtr += p; |
|
398 |
r = 0; |
|
399 |
} |
|
400 |
} |
|
401 |
} |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
402 |
%}. |
7499 | 403 |
] ifFalse:[ |
404 |
usedDeviceBitsPerPixel == 24 ifTrue:[ |
|
405 |
"/ 24 bits/pixel |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
406 |
|
7499 | 407 |
"/ now, walk over the image and replace |
408 |
"/ colorMap indices by color values in the bits array |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
409 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
410 |
%{ |
7499 | 411 |
unsigned char *srcPtr = 0; |
412 |
unsigned char *dstPtr = 0; |
|
413 |
OBJ _bytes = __INST(bytes); |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
414 |
|
7499 | 415 |
if (__isByteArrayLike(_bytes)) { |
416 |
srcPtr = __ByteArrayInstPtr(_bytes)->ba_element; |
|
417 |
} else { |
|
418 |
if (__isExternalBytesLike(_bytes)) { |
|
419 |
srcPtr = __externalBytesAddress(_bytes); |
|
420 |
} |
|
421 |
} |
|
422 |
if (__isByteArray(imageBits)) { |
|
423 |
dstPtr = __ByteArrayInstPtr(imageBits)->ba_element; |
|
424 |
} else { |
|
425 |
if (__isExternalBytesLike(imageBits)) { |
|
426 |
dstPtr = __externalBytesAddress(imageBits); |
|
427 |
} |
|
428 |
} |
|
3851
34637f468b2a
also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents:
3842
diff
changeset
|
429 |
|
7499 | 430 |
if (__bothSmallInteger(__INST(height), __INST(width)) |
431 |
&& __isArrayLike(colorValues) |
|
432 |
&& srcPtr |
|
433 |
&& dstPtr) { |
|
434 |
int x, y, w, h, nPix; |
|
435 |
int r, p, byte; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
436 |
|
7499 | 437 |
OBJ *ap = __ArrayInstPtr(colorValues)->a_element; |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
438 |
|
7499 | 439 |
w = __intVal(__INST(width)); |
440 |
h = __intVal(__INST(height)); |
|
441 |
r = 0; |
|
442 |
p = __intVal(padd); |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
443 |
|
7499 | 444 |
nPix = w * h; |
445 |
while (nPix > 0) { |
|
446 |
unsigned idx, v; |
|
447 |
OBJ clr; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
448 |
|
7499 | 449 |
if (r & 1) { |
450 |
idx = byte & 0xF; |
|
451 |
} else { |
|
452 |
byte = *srcPtr++; |
|
453 |
idx = (byte>>4) & 0xF; |
|
454 |
} |
|
455 |
clr = ap[idx]; |
|
456 |
v = __intVal(clr); |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
457 |
|
7499 | 458 |
dstPtr[0] = (v>>16) & 0xFF; |
459 |
dstPtr[1] = (v>>8) & 0xFF; |
|
460 |
dstPtr[2] = (v) & 0xFF; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
461 |
|
7499 | 462 |
dstPtr += 3; |
463 |
nPix--; |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
464 |
|
7499 | 465 |
if (++r == w) { |
466 |
dstPtr += p; |
|
467 |
r = 0; |
|
468 |
} |
|
469 |
} |
|
470 |
} |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
471 |
%}. |
7499 | 472 |
] ifFalse:[ |
473 |
'Image [warning]: unimplemented trueColor depth in anyImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR. |
|
474 |
^ nil |
|
475 |
] |
|
476 |
] |
|
477 |
] |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
478 |
]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
479 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
480 |
imageBits isNil ifTrue:[ |
7499 | 481 |
^ nil |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
482 |
]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
483 |
|
7499 | 484 |
form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice. |
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
485 |
form isNil ifTrue:[^ nil]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
486 |
form initGC. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
487 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
488 |
form |
7499 | 489 |
copyBitsFrom:imageBits |
490 |
bitsPerPixel:usedDeviceBitsPerPixel |
|
491 |
depth:usedDeviceDepth |
|
492 |
padding:usedDevicePadding |
|
493 |
width:width height:height |
|
494 |
x:0 y:0 |
|
495 |
toX:0 y:0. |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
496 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
497 |
^ form |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
498 |
|
4766 | 499 |
"Created: / 20-10-1995 / 22:05:10 / cg" |
500 |
"Modified: / 29-05-2007 / 19:22:19 / cg" |
|
2186
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
501 |
! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
502 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
503 |
greyImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
504 |
"return a true-color device-form for the grey-image receiver. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
505 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
506 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
507 |
|f| |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
508 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
509 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
510 |
f notNil ifTrue:[^ f]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
511 |
^ super greyImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
512 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
513 |
"Created: / 24.7.1998 / 01:21:28 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
514 |
! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
515 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
516 |
paletteImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
517 |
"return a true-color device-form for the palette-image receiver. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
518 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
519 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
520 |
|f| |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
521 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
522 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
523 |
f notNil ifTrue:[^ f]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
524 |
^ super paletteImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
525 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
526 |
"Created: / 24.7.1998 / 01:20:46 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
527 |
! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
528 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
529 |
rgbImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
530 |
"return a true-color device-form for the rgb-image receiver. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
531 |
Supports true color devices with depths: 8, 16, 24 and 32" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
532 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
533 |
|f| |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
534 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
535 |
f := self anyImageAsTrueColorFormOn:aDevice. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
536 |
f notNil ifTrue:[^ f]. |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
537 |
^ super rgbImageAsTrueColorFormOn:aDevice |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
538 |
|
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
539 |
"Created: / 24.7.1998 / 01:21:57 / cg" |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
540 |
! ! |
4e4b6f9b0d27
tuned conversion to trueColor
Claus Gittinger <cg@exept.de>
parents:
2179
diff
changeset
|
541 |
|
810 | 542 |
!Depth4Image methodsFor:'dither helpers'! |
798 | 543 |
|
1782 | 544 |
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth |
806 | 545 |
"return the bitmap for a dithered depth-bitmap from the image; |
546 |
with a constant ditherMatrix, this can be used for thresholding. |
|
547 |
Redefined to make use of knowing that pixels are 4-bit values." |
|
548 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
549 |
|dH nDither bytes |
806 | 550 |
greyLevels greyMap1 greyMap2 |
551 |
bytesPerRow "{Class: SmallInteger }" |
|
552 |
bytesPerOutRow "{Class: SmallInteger }" |
|
553 |
pixelsPerByte "{Class: SmallInteger }" |
|
554 |
outBits |
|
555 |
w "{Class: SmallInteger }" |
|
556 |
h "{Class: SmallInteger }" | |
|
557 |
||
558 |
nDither := ditherMatrix size. |
|
559 |
dH := nDither / dW. |
|
560 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
561 |
bytes := self bits. |
806 | 562 |
w := width. |
563 |
h := height. |
|
564 |
||
565 |
greyLevels := 1 bitShift:depth. |
|
566 |
pixelsPerByte := 8 / depth. |
|
567 |
||
568 |
bytesPerRow := self bytesPerRow. |
|
569 |
||
570 |
bytesPerOutRow := (w * depth + 7) // 8. |
|
571 |
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h). |
|
572 |
(outBits isNil or:[bytes isNil]) ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
573 |
^ nil |
806 | 574 |
]. |
575 |
||
576 |
greyMap1 := self greyMapForRange:(greyLevels-1). "/ the pixels |
|
577 |
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
578 |
0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
579 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
580 |
b truncated |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
581 |
] |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
582 |
]) asByteArray. |
806 | 583 |
|
584 |
greyMap2 := self greyMapForRange:(greyLevels-1). |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
585 |
greyMap2 := (greyMap2 collect:[:el | |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
586 |
el isNil ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
587 |
0 |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
588 |
] ifFalse:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
589 |
((el - el truncated) "/ the error (0..1) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
590 |
* nDither) rounded |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
591 |
]]) asByteArray. |
806 | 592 |
|
593 |
%{ |
|
594 |
int __dW = __intVal(dW); |
|
595 |
int __dH = __intVal(dH); |
|
596 |
int __byte; |
|
597 |
int __dT, __dO; |
|
598 |
int __depth = __intVal(depth); |
|
599 |
int __dstIdx = 0; |
|
600 |
int __srcIdx = 0; |
|
601 |
int __bitCnt; |
|
602 |
int __inByte; |
|
603 |
int __grey, __pixel; |
|
604 |
int __w = __intVal(w); |
|
605 |
int __h = __intVal(h); |
|
606 |
int __x; |
|
607 |
int __y; |
|
608 |
int __oX, __oY, __dY; |
|
609 |
int __nextDst; |
|
610 |
int __nextSrc; |
|
611 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
612 |
int __bytesPerOutRow = __intVal(bytesPerOutRow); |
|
613 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
614 |
unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element; |
808 | 615 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
616 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
806 | 617 |
unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element; |
618 |
unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element; |
|
619 |
||
620 |
__oY = __dY = 0; |
|
621 |
for (__y=0; __y<__h; __y++) { |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
622 |
__nextDst = __dstIdx + __bytesPerOutRow; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
623 |
__nextSrc = __srcIdx + __bytesPerRow; |
806 | 624 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
625 |
__byte = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
626 |
__bitCnt = 8; |
806 | 627 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
628 |
__oX = 0; |
806 | 629 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
630 |
for (__x=0; __x<__w; __x++) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
631 |
if (__x & 1) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
632 |
/* odd */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
633 |
__grey = __inByte & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
634 |
__srcIdx++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
635 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
636 |
__inByte = __bytes[__srcIdx]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
637 |
__grey = (__inByte >> 4) & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
638 |
} |
806 | 639 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
640 |
__pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
641 |
__dO = __greyMap2[__grey]; /* 0.. nDither-1) */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
642 |
__dT = __ditherMatrix[__dY + __oX]; |
806 | 643 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
644 |
if (__dO > __dT) /* dither says: next pixel */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
645 |
__pixel++; |
806 | 646 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
647 |
__oX++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
648 |
if (__oX == __dW) __oX = 0; |
806 | 649 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
650 |
__byte = (__byte << __depth) | __pixel; |
806 | 651 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
652 |
__bitCnt = __bitCnt - __depth; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
653 |
if (__bitCnt == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
654 |
__outBits[__dstIdx] = __byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
655 |
__dstIdx++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
656 |
__byte = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
657 |
__bitCnt = 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
658 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
659 |
} |
806 | 660 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
661 |
if (__bitCnt != 8) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
662 |
__byte = __byte << __bitCnt; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
663 |
__outBits[__dstIdx] = __byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
664 |
} |
806 | 665 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
666 |
__oY++; __dY += __dW; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
667 |
if (__oY == __dH) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
668 |
__oY = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
669 |
__dY = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
670 |
} |
806 | 671 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
672 |
__srcIdx = __nextSrc; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
673 |
__dstIdx = __nextDst; |
806 | 674 |
} |
675 |
%}. |
|
676 |
^ outBits |
|
677 |
! |
|
678 |
||
798 | 679 |
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW |
680 |
"return the dithered monochrome bits for the receiver image; |
|
681 |
with a constant ditherMatrix, this can be used for thresholding. |
|
682 |
Redefined to make use of knowing that pixels are 4-bit values." |
|
683 |
||
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
684 |
|dH nDither bytes |
798 | 685 |
greyMap monoBits |
686 |
bytesPerMonoRow "{Class: SmallInteger }" |
|
687 |
bytesPerRow "{Class: SmallInteger }" |
|
688 |
w "{Class: SmallInteger }" |
|
689 |
h "{Class: SmallInteger }"| |
|
690 |
||
691 |
nDither := ditherMatrix size. |
|
692 |
dH := nDither / dW. |
|
693 |
||
694 |
w := width. |
|
695 |
h := height. |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
696 |
bytes := self bits. |
798 | 697 |
|
698 |
bytesPerRow := self bytesPerRow. |
|
699 |
||
700 |
bytesPerMonoRow := w + 7 // 8. |
|
701 |
monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h). |
|
702 |
(monoBits isNil or:[bytes isNil]) ifTrue:[ |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
703 |
^ nil |
798 | 704 |
]. |
705 |
||
803
899f7eb32ef2
support #rgb - specialized code relaxed
Claus Gittinger <cg@exept.de>
parents:
798
diff
changeset
|
706 |
greyMap := self greyByteMapForRange:nDither. |
798 | 707 |
|
708 |
%{ |
|
709 |
int __dW = __intVal(dW); |
|
710 |
int __dH = __intVal(dH); |
|
711 |
int __byte; |
|
712 |
int __dT; |
|
713 |
int __dstIdx = 0; |
|
714 |
int __srcIdx = 0; |
|
715 |
int __bitCnt; |
|
716 |
int __inByte; |
|
717 |
int __grey; |
|
718 |
int __w = __intVal(w); |
|
719 |
int __h = __intVal(h); |
|
720 |
int __x; |
|
721 |
int __y; |
|
722 |
int __oX, __oY, __dY; |
|
723 |
int __nextDst; |
|
724 |
int __nextSrc; |
|
725 |
int __bytesPerRow = __intVal(bytesPerRow); |
|
726 |
int __bytesPerMonoRow = __intVal(bytesPerMonoRow); |
|
727 |
||
1812
beeaf75b245b
avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
728 |
unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element; |
808 | 729 |
unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element; |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
730 |
unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element; |
798 | 731 |
unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element; |
732 |
||
733 |
__oY = __dY = 0; |
|
734 |
for (__y=0; __y<__h; __y++) { |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
735 |
__nextDst = __dstIdx + __bytesPerMonoRow; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
736 |
__nextSrc = __srcIdx + __bytesPerRow; |
798 | 737 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
738 |
__byte = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
739 |
__bitCnt = 8; |
798 | 740 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
741 |
__oX = 0; |
798 | 742 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
743 |
for (__x=0; __x<__w; __x++) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
744 |
if (__x & 1) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
745 |
/* odd */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
746 |
__grey = __inByte & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
747 |
__srcIdx++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
748 |
} else { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
749 |
__inByte = __bytes[__srcIdx]; /* 0..255 */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
750 |
__grey = (__inByte >> 4) & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
751 |
} |
798 | 752 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
753 |
__grey = __greyMap[__grey]; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
754 |
__dT = __ditherMatrix[__dY + __oX]; |
798 | 755 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
756 |
__oX++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
757 |
if (__oX == __dW) __oX = 0; |
798 | 758 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
759 |
__byte = __byte << 1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
760 |
if (__grey > __dT) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
761 |
__byte = __byte | 1; /* white */ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
762 |
} |
798 | 763 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
764 |
__bitCnt--; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
765 |
if (__bitCnt == 0) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
766 |
__monoBits[__dstIdx] = __byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
767 |
__dstIdx++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
768 |
__byte = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
769 |
__bitCnt = 8; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
770 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
771 |
} |
798 | 772 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
773 |
if (__bitCnt != 8) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
774 |
__byte = __byte << __bitCnt; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
775 |
__monoBits[__dstIdx] = __byte; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
776 |
} |
798 | 777 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
778 |
__oY++; __dY += __dW; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
779 |
if (__oY == __dH) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
780 |
__oY = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
781 |
__dY = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
782 |
} |
798 | 783 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
784 |
__srcIdx = __nextSrc; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
785 |
__dstIdx = __nextDst; |
798 | 786 |
} |
787 |
%}. |
|
788 |
||
789 |
^ monoBits |
|
790 |
! ! |
|
791 |
||
89 | 792 |
!Depth4Image methodsFor:'enumerating'! |
81 | 793 |
|
798 | 794 |
colorsAtY:y from:xLow to:xHigh do:aBlock |
1 | 795 |
"perform aBlock for each pixel from x1 to x2 in row y. |
796 |
The block is passed the color at each pixel. |
|
797 |
This method allows slighly faster processing of an |
|
798 |
image than using atX:y:, since some processing can be |
|
799 |
avoided when going from pixel to pixel. However, for |
|
800 |
real image processing, specialized methods should be written." |
|
801 |
||
802 |
|srcIndex "{ Class: SmallInteger }" |
|
803 |
byte "{ Class: SmallInteger }" |
|
804 |
shift "{ Class: SmallInteger }" |
|
805 |
value "{ Class: SmallInteger }" |
|
806 |
x1 "{ Class: SmallInteger }" |
|
807 |
x2 "{ Class: SmallInteger }" |
|
4904 | 808 |
byteSize "{ Class: SmallInteger }" |
7321 | 809 |
colorArray pixelBytes| |
1 | 810 |
|
7321 | 811 |
pixelBytes := self bits. |
812 |
byteSize := pixelBytes size. |
|
813 |
colorArray := Array new:16. |
|
814 |
0 to:15 do:[:i | colorArray at:i+1 put:(self colorFromValue:i)]. |
|
1 | 815 |
|
816 |
x1 := xLow. |
|
817 |
x2 := xHigh. |
|
810 | 818 |
|
1 | 819 |
srcIndex := (self bytesPerRow * y) + 1. |
820 |
srcIndex := srcIndex + (x1 // 2). |
|
12 | 821 |
x1 even ifTrue:[ |
7321 | 822 |
shift := -4 |
12 | 823 |
] ifFalse:[ |
7321 | 824 |
shift := 0 |
12 | 825 |
]. |
1 | 826 |
|
7321 | 827 |
byte := pixelBytes at:srcIndex. |
1 | 828 |
x1 to:x2 do:[:x | |
7321 | 829 |
shift == 0 ifTrue:[ |
830 |
value := byte bitAnd:16rF. |
|
831 |
shift := -4. |
|
832 |
srcIndex := srcIndex + 1. |
|
833 |
] ifFalse:[ |
|
834 |
srcIndex > byteSize ifTrue:[ |
|
835 |
byte := 0. |
|
836 |
] ifFalse:[ |
|
837 |
byte := pixelBytes at:srcIndex. |
|
838 |
]. |
|
839 |
value := (byte bitShift:-4) bitAnd:16rF. |
|
840 |
shift := 0 |
|
841 |
]. |
|
842 |
aBlock value:x value:(colorArray at:(value + 1)). |
|
1 | 843 |
] |
746 | 844 |
|
2197
1b88e629091d
avoid a byte fetch in colorsAtY:from:to:do:
Claus Gittinger <cg@exept.de>
parents:
2186
diff
changeset
|
845 |
"Created: / 7.6.1996 / 19:12:33 / cg" |
1b88e629091d
avoid a byte fetch in colorsAtY:from:to:do:
Claus Gittinger <cg@exept.de>
parents:
2186
diff
changeset
|
846 |
"Modified: / 28.7.1998 / 21:26:11 / cg" |
280 | 847 |
! |
848 |
||
798 | 849 |
valuesAtY:y from:xLow to:xHigh do:aBlock |
280 | 850 |
"perform aBlock for each pixelValue from x1 to x2 in row y. |
851 |
The block is passed the pixelValue at each pixel. |
|
852 |
This method allows slighly faster processing of an |
|
853 |
image than using valueAtX:y:, since some processing can be |
|
854 |
avoided when going from pixel to pixel. However, for |
|
855 |
real image processing, specialized methods should be written." |
|
856 |
||
857 |
|srcIndex "{ Class: SmallInteger }" |
|
858 |
shift "{ Class: SmallInteger }" |
|
859 |
pixelValue "{ Class: SmallInteger }" |
|
860 |
x1 "{ Class: SmallInteger }" |
|
861 |
x2 "{ Class: SmallInteger }" |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
862 |
bytes| |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
863 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
864 |
bytes := self bits. |
280 | 865 |
|
866 |
x1 := xLow. |
|
867 |
x2 := xHigh. |
|
868 |
srcIndex := (self bytesPerRow * y) + 1. |
|
869 |
srcIndex := srcIndex + (x1 // 2). |
|
870 |
x1 even ifTrue:[ |
|
7821 | 871 |
shift := -4 |
280 | 872 |
] ifFalse:[ |
7821 | 873 |
shift := 0 |
280 | 874 |
]. |
875 |
||
876 |
x1 to:x2 do:[:x | |
|
7821 | 877 |
pixelValue := bytes at:srcIndex. |
878 |
shift == 0 ifTrue:[ |
|
879 |
shift := -4. |
|
880 |
srcIndex := srcIndex + 1. |
|
881 |
] ifFalse:[ |
|
882 |
pixelValue := pixelValue bitShift:-4. |
|
883 |
shift := 0 |
|
884 |
]. |
|
885 |
aBlock value:x value:(pixelValue bitAnd:16rF). |
|
280 | 886 |
] |
798 | 887 |
|
7821 | 888 |
"Created: / 07-06-1996 / 19:09:45 / cg" |
889 |
"Modified (format): / 30-01-2017 / 20:41:31 / stefan" |
|
1 | 890 |
! ! |
891 |
||
892 |
!Depth4Image methodsFor:'magnification'! |
|
893 |
||
894 |
magnifyRowFrom:srcBytes offset:srcStart |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
895 |
into:dstBytes offset:dstStart factor:mX |
1 | 896 |
|
89 | 897 |
"magnify a single pixel row - can only magnify by integer factors. |
898 |
Specially tuned for factor 2." |
|
1 | 899 |
|
900 |
%{ |
|
901 |
unsigned char *srcP, *dstP; |
|
902 |
int _mag; |
|
903 |
REGISTER int i; |
|
904 |
REGISTER unsigned char _byte; |
|
905 |
int _pixels; |
|
906 |
REGISTER int outcnt, bits, bit; |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
907 |
OBJ w = __INST(width); |
1 | 908 |
|
97 | 909 |
if (__bothSmallInteger(srcStart, dstStart) |
910 |
&& __bothSmallInteger(w, mX) |
|
5475
e6469c3d8a46
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4904
diff
changeset
|
911 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
912 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
913 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
914 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
915 |
_pixels = __intVal(w); |
1 | 916 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
917 |
switch (_mag) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
918 |
case 1: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
919 |
break; |
2179 | 920 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
921 |
case 2: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
922 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
923 |
while (_pixels) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
924 |
bit = (_byte >> 4) & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
925 |
bits = (bit << 4) | bit; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
926 |
*dstP++ = bits; |
1 | 927 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
928 |
if (--_pixels) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
929 |
bit = _byte & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
930 |
bits = (bit << 4) | bit; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
931 |
*dstP++ = bits; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
932 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
933 |
_pixels--; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
934 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
935 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
936 |
break; |
1 | 937 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
938 |
default: |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
939 |
bits = 0, outcnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
940 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
941 |
while (_pixels) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
942 |
bit = (_byte >> 4) & 0xF; |
1 | 943 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
944 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
945 |
bits = (bits << 4) | bit; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
946 |
outcnt++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
947 |
if (outcnt == 2) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
948 |
*dstP++ = bits; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
949 |
bits = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
950 |
outcnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
951 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
952 |
} |
1 | 953 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
954 |
if (--_pixels) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
955 |
bit = _byte & 0xF; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
956 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
957 |
bits = (bits << 4) | bit; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
958 |
outcnt++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
959 |
if (outcnt == 2) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
960 |
*dstP++ = bits; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
961 |
bits = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
962 |
outcnt = 0; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
963 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
964 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
965 |
_byte = *srcP++; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
966 |
_pixels--; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
967 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
968 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
969 |
if (outcnt) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
970 |
*dstP = bits << 4; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
971 |
} |
1 | 972 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
973 |
break; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
974 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
975 |
RETURN (self); |
1 | 976 |
} |
3842 | 977 |
%}. |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
978 |
super |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
979 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
980 |
into:dstBytes offset:dstStart factor:mX |
1 | 981 |
! ! |
280 | 982 |
|
983 |
!Depth4Image methodsFor:'queries'! |
|
984 |
||
985 |
bitsPerPixel |
|
986 |
"return the number of bits per pixel" |
|
987 |
||
988 |
^ 4 |
|
989 |
! |
|
990 |
||
991 |
bitsPerRow |
|
992 |
"return the number of bits in one scanline of the image" |
|
993 |
||
3868 | 994 |
^ width * 4 |
280 | 995 |
! |
996 |
||
997 |
bytesPerRow |
|
998 |
"return the number of bytes in one scanline of the image" |
|
999 |
||
1000 |
|nbytes| |
|
1001 |
||
1002 |
nbytes := width // 2. |
|
1003 |
width odd ifTrue:[ |
|
1004 |
^ nbytes + 1 |
|
1005 |
]. |
|
1006 |
^ nbytes |
|
1007 |
! |
|
1008 |
||
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1009 |
colorFromValue:pixelValue |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1010 |
"given a pixel value, return the corresponding color. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1011 |
Pixel values start with 0." |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1012 |
|
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1013 |
photometric == #whiteIs0 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
1014 |
^ Color gray:100 - (100 / 15 * pixelValue) |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1015 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1016 |
photometric == #blackIs0 ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
1017 |
^ Color gray:(100 / 15 * pixelValue) |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1018 |
]. |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1019 |
photometric == #palette ifTrue:[ |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
1020 |
pixelValue < colorMap size ifTrue:[ |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
1021 |
^ colorMap at:(pixelValue + 1) |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5475
diff
changeset
|
1022 |
] |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1023 |
]. |
3869 | 1024 |
^ super colorFromValue:pixelValue |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1025 |
! |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3851
diff
changeset
|
1026 |
|
280 | 1027 |
usedValues |
1028 |
"return a collection of color values used in the receiver." |
|
1029 |
||
6897 | 1030 |
|useFlags usedValues |
1031 |
h "{ Class: SmallInteger }" |
|
1032 |
w "{ Class: SmallInteger }" | |
|
280 | 1033 |
|
1034 |
useFlags := Array new:16 withAll:false. |
|
6897 | 1035 |
w := width. |
1036 |
h := height. |
|
1037 |
||
1038 |
w even ifFalse:[ |
|
1039 |
0 to:h-1 do:[:y | |
|
1040 |
self valuesAtY:y from:0 to:w-1 do:[:x :pixel | |
|
1041 |
useFlags at:(pixel + 1) put:true |
|
1042 |
] |
|
1043 |
]. |
|
280 | 1044 |
] ifTrue:[ |
6897 | 1045 |
self bits usedValues do:[:byte | |
1046 |
useFlags at:(byte bitShift:-4)+1 put:true. |
|
1047 |
useFlags at:(byte bitAnd:2r1111)+1 put:true. |
|
1048 |
]. |
|
280 | 1049 |
]. |
2265 | 1050 |
^ (0 to:15) select:[:i | useFlags at:(i+1)]. |
798 | 1051 |
|
2265 | 1052 |
"/ usedValues := OrderedCollection new. |
1053 |
"/ 1 to:16 do:[:i | (useFlags at:i) ifTrue:[usedValues add:(i-1)]]. |
|
1054 |
"/ ^ usedValues |
|
1055 |
||
1056 |
"Modified: / 24.8.1998 / 13:56:59 / cg" |
|
280 | 1057 |
! ! |
1058 |
||
1059 |
!Depth4Image class methodsFor:'documentation'! |
|
1060 |
||
1061 |
version |
|
6897 | 1062 |
^ '$Header$' |
5475
e6469c3d8a46
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4904
diff
changeset
|
1063 |
! |
e6469c3d8a46
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4904
diff
changeset
|
1064 |
|
e6469c3d8a46
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
4904
diff
changeset
|
1065 |
version_CVS |
6897 | 1066 |
^ '$Header$' |
280 | 1067 |
! ! |
6298 | 1068 |