4
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
1
|
12 |
|
|
13 |
Image subclass:#Depth4Image
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Display Objects'
|
|
18 |
!
|
|
19 |
|
4
|
20 |
Depth4Image comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
54
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.7 1994-08-05 01:13:57 claus Exp $
|
46
|
25 |
'!
|
4
|
26 |
|
46
|
27 |
!Depth4Image class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
4
|
33 |
|
46
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
4
|
42 |
|
46
|
43 |
version
|
|
44 |
"
|
54
|
45 |
$Header: /cvs/stx/stx/libview/Depth4Image.st,v 1.7 1994-08-05 01:13:57 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class represents 16-color (4 bit / pixel) images.
|
|
52 |
Most images coming from the windows world are represented as Depth4Images.
|
|
53 |
It mainly consists of methods already implemented in Image,
|
|
54 |
reimplemented here for more performance.
|
|
55 |
"
|
|
56 |
! !
|
4
|
57 |
|
1
|
58 |
!Depth4Image methodsFor:'accessing'!
|
|
59 |
|
|
60 |
bitsPerPixel
|
|
61 |
"return the number of bits per pixel"
|
|
62 |
|
|
63 |
^ 4
|
|
64 |
!
|
|
65 |
|
|
66 |
bitsPerRow
|
|
67 |
"return the number of bits in one scanline of the image"
|
|
68 |
|
|
69 |
^ width * 4
|
|
70 |
!
|
|
71 |
|
|
72 |
bitsPerSample
|
|
73 |
"return the number of bits per sample.
|
|
74 |
The return value is an array of bits-per-plane."
|
|
75 |
|
|
76 |
^ #(4)
|
|
77 |
!
|
|
78 |
|
|
79 |
bytesPerRow
|
|
80 |
"return the number of bytes in one scanline of the image"
|
|
81 |
|
|
82 |
|nbytes|
|
|
83 |
|
|
84 |
nbytes := width // 2.
|
|
85 |
width odd ifTrue:[
|
|
86 |
^ nbytes + 1
|
|
87 |
].
|
|
88 |
^ nbytes
|
|
89 |
!
|
|
90 |
|
|
91 |
samplesPerPixel
|
|
92 |
"return the number of samples per pixel in the image."
|
|
93 |
|
|
94 |
^ 1
|
|
95 |
!
|
|
96 |
|
|
97 |
valueAtX:x y:y
|
|
98 |
"retrieve a pixel at x/y; return a pixelValue.
|
|
99 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
100 |
x = width-1, y=height-1 for lower right pixel"
|
|
101 |
|
46
|
102 |
|lineIndex "{ Class: SmallInteger }"
|
|
103 |
byte "{ Class: SmallInteger }" |
|
1
|
104 |
|
|
105 |
lineIndex := (self bytesPerRow * y) + 1.
|
|
106 |
|
|
107 |
"left pixel in high bits"
|
|
108 |
byte := bytes at:(lineIndex + (x // 2)).
|
|
109 |
x even ifTrue:[
|
|
110 |
^ (byte bitShift:-4) bitAnd:16rF.
|
|
111 |
].
|
|
112 |
^ byte bitAnd:16rF.
|
|
113 |
!
|
|
114 |
|
|
115 |
atX:x y:y
|
|
116 |
"retrieve a pixel at x/y; return a color.
|
|
117 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
118 |
x = width-1, y=height-1 for lower right pixel"
|
|
119 |
|
46
|
120 |
|lineIndex "{ Class: SmallInteger }"
|
|
121 |
byte "{ Class: SmallInteger }"
|
|
122 |
value "{ Class: SmallInteger }" |
|
1
|
123 |
|
|
124 |
lineIndex := (self bytesPerRow * y) + 1.
|
|
125 |
|
|
126 |
"left pixel in high bits"
|
|
127 |
byte := bytes at:(lineIndex + (x // 2)).
|
|
128 |
x even ifTrue:[
|
|
129 |
value := (byte bitShift:-4) bitAnd:16rF.
|
|
130 |
] ifFalse:[
|
|
131 |
value := byte bitAnd:16rF.
|
|
132 |
].
|
|
133 |
photometric == #whiteIs0 ifTrue:[
|
|
134 |
^ Color grey:100 - (100 / 15 * value)
|
|
135 |
].
|
|
136 |
photometric == #blackIs0 ifTrue:[
|
|
137 |
^ Color grey:(100 / 15 * value)
|
|
138 |
].
|
|
139 |
photometric ~~ #palette ifTrue:[
|
|
140 |
self error:'format not supported'.
|
|
141 |
^ nil
|
|
142 |
].
|
|
143 |
^ Color red:(((colorMap at:1) at:(value + 1)) * 100 / 255)
|
|
144 |
green:(((colorMap at:2) at:(value + 1)) * 100 / 255)
|
|
145 |
blue:(((colorMap at:3) at:(value + 1)) * 100 / 255)
|
|
146 |
!
|
|
147 |
|
|
148 |
atX:x y:y putValue:aPixelValue
|
|
149 |
"set the pixel at x/y to aPixelValue.
|
|
150 |
Pixels start at x=0 , y=0 for upper left pixel, end at
|
|
151 |
x = width-1, y=height-1 for lower right pixel"
|
|
152 |
|
46
|
153 |
|lineIndex "{ Class: SmallInteger }"
|
|
154 |
index "{ Class: SmallInteger }"
|
|
155 |
byte "{ Class: SmallInteger }" |
|
1
|
156 |
|
|
157 |
lineIndex := (self bytesPerRow * y) + 1.
|
|
158 |
|
|
159 |
"left pixel is in high bits"
|
|
160 |
index := lineIndex + (x // 2).
|
|
161 |
byte := bytes at:index.
|
|
162 |
x even ifTrue:[
|
|
163 |
byte := (byte bitAnd:16rF) bitOr:(aPixelValue bitShift:4)
|
|
164 |
] ifFalse:[
|
|
165 |
byte := (byte bitAnd:16rF0) bitOr:aPixelValue
|
|
166 |
].
|
|
167 |
bytes at:index put:byte
|
|
168 |
!
|
|
169 |
|
|
170 |
atY:y from:xLow to:xHigh do:aBlock
|
|
171 |
"perform aBlock for each pixel from x1 to x2 in row y.
|
|
172 |
The block is passed the color at each pixel.
|
|
173 |
This method allows slighly faster processing of an
|
|
174 |
image than using atX:y:, since some processing can be
|
|
175 |
avoided when going from pixel to pixel. However, for
|
|
176 |
real image processing, specialized methods should be written."
|
|
177 |
|
|
178 |
|srcIndex "{ Class: SmallInteger }"
|
|
179 |
byte "{ Class: SmallInteger }"
|
|
180 |
shift "{ Class: SmallInteger }"
|
|
181 |
value "{ Class: SmallInteger }"
|
|
182 |
x1 "{ Class: SmallInteger }"
|
|
183 |
x2 "{ Class: SmallInteger }"
|
|
184 |
colors|
|
|
185 |
|
|
186 |
colors := Array new:16.
|
|
187 |
photometric == #whiteIs0 ifTrue:[
|
|
188 |
0 to:15 do:[:i |
|
|
189 |
colors at:(i+1) put:(Color grey:100 - (100 / 15 * i))
|
|
190 |
]
|
|
191 |
] ifFalse:[
|
|
192 |
photometric == #blackIs0 ifTrue:[
|
|
193 |
0 to:15 do:[:i |
|
|
194 |
colors at:(i+1) put:(Color grey:(100 / 15 * i))
|
|
195 |
]
|
|
196 |
] ifFalse:[
|
|
197 |
photometric == #palette ifTrue:[
|
|
198 |
1 to:16 do:[:i |
|
|
199 |
colors at:i
|
|
200 |
put:(Color red:(((colorMap at:1) at:i) * 100 / 255)
|
|
201 |
green:(((colorMap at:2) at:i) * 100 / 255)
|
|
202 |
blue:(((colorMap at:3) at:i) * 100 / 255))
|
|
203 |
]
|
|
204 |
] ifFalse:[
|
|
205 |
self error:'format not supported'.
|
|
206 |
^ nil
|
|
207 |
]
|
|
208 |
]
|
|
209 |
].
|
|
210 |
|
|
211 |
x1 := xLow.
|
|
212 |
x2 := xHigh.
|
|
213 |
srcIndex := (self bytesPerRow * y) + 1.
|
|
214 |
srcIndex := srcIndex + (x1 // 2).
|
12
|
215 |
x1 even ifTrue:[
|
|
216 |
shift := -4
|
|
217 |
] ifFalse:[
|
|
218 |
shift := 0
|
|
219 |
].
|
1
|
220 |
|
|
221 |
x1 to:x2 do:[:x |
|
12
|
222 |
shift == 0 ifTrue:[
|
|
223 |
byte := bytes at:srcIndex.
|
|
224 |
value := byte bitAnd:16rF.
|
1
|
225 |
shift := -4.
|
|
226 |
srcIndex := srcIndex + 1.
|
|
227 |
] ifFalse:[
|
12
|
228 |
byte := bytes at:srcIndex.
|
|
229 |
value := (byte bitShift:-4) bitAnd:16rF.
|
1
|
230 |
shift := 0
|
12
|
231 |
].
|
|
232 |
aBlock value:x value:(colors at:(value + 1)).
|
1
|
233 |
]
|
|
234 |
! !
|
|
235 |
|
|
236 |
!Depth4Image methodsFor:'magnification'!
|
|
237 |
|
|
238 |
magnifyRowFrom:srcBytes offset:srcStart
|
|
239 |
into:dstBytes offset:dstStart factor:mX
|
|
240 |
|
|
241 |
"magnify a single pixel row - can only magnify by integer factors"
|
|
242 |
|
|
243 |
%{
|
|
244 |
unsigned char *srcP, *dstP;
|
|
245 |
int _mag;
|
|
246 |
REGISTER int i;
|
|
247 |
REGISTER unsigned char _byte;
|
|
248 |
int _pixels;
|
|
249 |
REGISTER int outcnt, bits, bit;
|
|
250 |
|
|
251 |
if (_isSmallInteger(srcStart) && _isSmallInteger(dstStart)
|
|
252 |
&& _isSmallInteger(_INST(width)) && _isSmallInteger(mX)
|
35
|
253 |
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
|
1
|
254 |
_mag = _intVal(mX);
|
|
255 |
srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart);
|
|
256 |
dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart);
|
|
257 |
_pixels = _intVal(_INST(width));
|
|
258 |
|
|
259 |
switch (_mag) {
|
|
260 |
case 1:
|
|
261 |
break;
|
|
262 |
|
|
263 |
case 2:
|
|
264 |
_byte = *srcP++;
|
|
265 |
while (_pixels) {
|
|
266 |
bit = (_byte >> 4) & 0xF;
|
|
267 |
bits = (bit << 4) | bit;
|
|
268 |
*dstP++ = bits;
|
|
269 |
|
|
270 |
if (--_pixels) {
|
|
271 |
bit = _byte & 0xF;
|
|
272 |
bits = (bit << 4) | bit;
|
|
273 |
*dstP++ = bits;
|
|
274 |
_byte = *srcP++;
|
|
275 |
_pixels--;
|
|
276 |
}
|
|
277 |
}
|
|
278 |
break;
|
|
279 |
|
|
280 |
default:
|
|
281 |
bits = 0, outcnt = 0;
|
|
282 |
_byte = *srcP++;
|
|
283 |
while (_pixels) {
|
|
284 |
bit = (_byte >> 4) & 0xF;
|
|
285 |
|
|
286 |
for (i=_mag; i>0; i--) {
|
|
287 |
bits = (bits << 4) | bit;
|
|
288 |
outcnt++;
|
|
289 |
if (outcnt == 2) {
|
|
290 |
*dstP++ = bits;
|
|
291 |
bits = 0;
|
|
292 |
outcnt = 0;
|
|
293 |
}
|
|
294 |
}
|
|
295 |
|
|
296 |
if (--_pixels) {
|
|
297 |
bit = _byte & 0xF;
|
|
298 |
for (i=_mag; i>0; i--) {
|
|
299 |
bits = (bits << 4) | bit;
|
|
300 |
outcnt++;
|
|
301 |
if (outcnt == 2) {
|
|
302 |
*dstP++ = bits;
|
|
303 |
bits = 0;
|
|
304 |
outcnt = 0;
|
|
305 |
}
|
|
306 |
}
|
|
307 |
_byte = *srcP++;
|
|
308 |
_pixels--;
|
|
309 |
}
|
|
310 |
}
|
|
311 |
|
|
312 |
break;
|
|
313 |
}
|
|
314 |
RETURN (self);
|
|
315 |
}
|
|
316 |
%}
|
|
317 |
.
|
|
318 |
self primitiveFailed
|
|
319 |
! !
|