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