1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
155
|
3 |
All Rights Reserved
|
1
|
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 |
"
|
|
12 |
|
10
|
13 |
ArrayedCollection variableByteSubclass:#ByteArray
|
550
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Arrayed'
|
1
|
18 |
!
|
|
19 |
|
88
|
20 |
!ByteArray class methodsFor:'documentation'!
|
|
21 |
|
563
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
|
34 |
!
|
|
35 |
|
88
|
36 |
documentation
|
|
37 |
"
|
|
38 |
ByteArrays store integers in the range 0..255.
|
129
|
39 |
In contrast to normal arrays (which store pointers to their elements),
|
362
|
40 |
byteArrays store the values in a dense & compact way. ByteArrays can
|
129
|
41 |
be used to hold the data for bitmaps, images and other bulk data.
|
|
42 |
ByteArrays are also used to store the bytecode-instructions of an
|
|
43 |
interpreted method and are used as superclass for Strings.
|
|
44 |
|
|
45 |
ByteArrays can be used as literals i.e. you can enter ByteArray-constants
|
|
46 |
as #[ element1 element2 .... elementN] and also use byteArray constants
|
|
47 |
as elements in a constant array.
|
|
48 |
As in: #( #[1 1 1] #[2 2 2] #[3 3 3])
|
|
49 |
|
|
50 |
If you have to communicate structure-data (in the C-sense) with external
|
|
51 |
programs/data-bases, see a companion class (Structure) in the goodies directory.
|
|
52 |
It allows the definition of subclasses of ByteArray, which transparently fetch
|
|
53 |
and store C-structure fields.
|
88
|
54 |
"
|
550
|
55 |
!
|
3
|
56 |
|
550
|
57 |
version
|
563
|
58 |
^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.38 1995-11-15 17:08:15 cg Exp $'
|
2
|
59 |
! !
|
|
60 |
|
1
|
61 |
!ByteArray class methodsFor:'instance creation'!
|
|
62 |
|
563
|
63 |
fromPackedString:aString
|
|
64 |
"ST-80 compatibility: decode a byteArray from a packed string in which
|
|
65 |
6bits are encoded per character. The argument, aString must be a multiple
|
|
66 |
of 4 in size (since 24 is the lcm of 6 and 8). This is somewhat like
|
|
67 |
the radix-encoding used in good old PDP11 times ;-)
|
|
68 |
ST-80 uses this encoding for Images ...
|
|
69 |
PS: It took a while to figure that one out ... I dont like it ;-)"
|
|
70 |
|
|
71 |
|index "{ Class: SmallInteger }"
|
|
72 |
dstIndex "{ Class: SmallInteger }"
|
|
73 |
stop "{ Class: SmallInteger }"
|
|
74 |
n "{ Class: SmallInteger }"
|
|
75 |
sz "{ Class: SmallInteger }"
|
|
76 |
lastCharacter bytes|
|
|
77 |
|
|
78 |
sz := aString size.
|
|
79 |
sz == 0 ifTrue:[^ self new].
|
|
80 |
stop := sz // 4 * 3.
|
|
81 |
"the size modulu 3 is encoded in the last character, if its in the
|
|
82 |
range 97 .. otherwise, its exact."
|
|
83 |
|
|
84 |
lastCharacter := aString last.
|
|
85 |
lastCharacter asciiValue > 96 ifTrue:[
|
|
86 |
stop := stop - 3 + lastCharacter asciiValue - 96
|
|
87 |
].
|
|
88 |
bytes := self new:stop.
|
|
89 |
index := 1. dstIndex := 1.
|
|
90 |
[dstIndex <= stop] whileTrue:[
|
|
91 |
"take 4 characters ..."
|
|
92 |
n := (aString at:index) asciiValue - 32.
|
|
93 |
n := (n bitShift:6) + ((aString at:index+1) asciiValue - 32).
|
|
94 |
n := (n bitShift:6) + ((aString at:index+2) asciiValue - 32).
|
|
95 |
n := (n bitShift:6) + ((aString at:index+3) asciiValue - 32).
|
|
96 |
n := n bitXor:16r820820.
|
|
97 |
index := index + 4.
|
|
98 |
bytes at:dstIndex put:(n bitShift:-16).
|
|
99 |
dstIndex < stop ifTrue:[
|
|
100 |
bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
|
|
101 |
dstIndex+2 <= stop ifTrue:[
|
|
102 |
bytes at:dstIndex+2 put:(n bitAnd:16rFF).
|
|
103 |
]
|
|
104 |
].
|
|
105 |
dstIndex := dstIndex + 3.
|
|
106 |
].
|
|
107 |
^ bytes
|
|
108 |
|
|
109 |
"
|
|
110 |
ByteArray fromPackedString:(#[1 1 1 1] asPackedString)
|
|
111 |
ByteArray fromPackedString:(#[1 1 1 1 1] asPackedString)
|
|
112 |
ByteArray fromPackedString:(#[1 1 1 1 1 1] asPackedString)
|
|
113 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1] asPackedString)
|
|
114 |
ByteArray fromPackedString:(#[1 1 1 1 1 1 1 1] asPackedString)
|
|
115 |
|
|
116 |
"
|
|
117 |
!
|
|
118 |
|
1
|
119 |
uninitializedNew:anInteger
|
|
120 |
"return a new instance of the receiver with uninitialized
|
|
121 |
(i.e. undefined) contents. The indexed elements have any random
|
75
|
122 |
value. However, any named instance variables are still nilled.
|
|
123 |
For use, when contents will be set anyway shortly after - this
|
|
124 |
is a bit faster than the regular basicNew:, which clears the bytes.
|
|
125 |
Of course, it only makes a difference for very big ByteArrays, such
|
|
126 |
as used for images/bitmaps.
|
|
127 |
|
|
128 |
Notice: if you want to port code using uninitializedNew: to another
|
|
129 |
smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling
|
|
130 |
method to the ByteArray class of the other smalltalk."
|
1
|
131 |
|
|
132 |
%{ /* NOCONTEXT */
|
|
133 |
OBJ newobj;
|
|
134 |
INT instsize, nInstVars, nindexedinstvars;
|
|
135 |
REGISTER OBJ *op;
|
|
136 |
|
249
|
137 |
if (__isSmallInteger(anInteger)) {
|
155
|
138 |
nindexedinstvars = _intVal(anInteger);
|
|
139 |
if (nindexedinstvars >= 0) {
|
249
|
140 |
if (self == ByteArray) {
|
|
141 |
/*
|
|
142 |
* the most common case
|
|
143 |
*/
|
|
144 |
instsize = OHDR_SIZE + nindexedinstvars;
|
|
145 |
if (_CanDoQuickNew(instsize)) {
|
|
146 |
_qCheckedNew(newobj, instsize);
|
|
147 |
_InstPtr(newobj)->o_class = self;
|
|
148 |
RETURN (newobj );
|
155
|
149 |
}
|
249
|
150 |
}
|
|
151 |
nInstVars = _intVal(_ClassInstPtr(self)->c_ninstvars);
|
|
152 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
|
|
153 |
PROTECT_CONTEXT
|
|
154 |
_qNew(newobj, instsize, SENDER);
|
|
155 |
UNPROTECT_CONTEXT
|
281
|
156 |
if (newobj != nil) {
|
249
|
157 |
_InstPtr(newobj)->o_class = self;
|
367
|
158 |
__qSTORE(newobj, self);
|
249
|
159 |
if (nInstVars) {
|
|
160 |
/*
|
|
161 |
* still have to nil out named instvars ...
|
|
162 |
*/
|
|
163 |
#if defined(FAST_OBJECT_MEMSET4)
|
|
164 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
1
|
165 |
#else
|
249
|
166 |
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES)
|
|
167 |
/*
|
|
168 |
* knowing that nil is 0
|
|
169 |
*/
|
|
170 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
171 |
# else
|
|
172 |
op = _InstPtr(newobj)->i_instvars;
|
|
173 |
while (nInstVars--)
|
|
174 |
*op++ = nil;
|
|
175 |
# endif
|
1
|
176 |
#endif
|
155
|
177 |
}
|
249
|
178 |
RETURN ( newobj );
|
155
|
179 |
}
|
|
180 |
}
|
1
|
181 |
}
|
|
182 |
%}
|
|
183 |
.
|
12
|
184 |
(anInteger isMemberOf:SmallInteger) ifTrue:[
|
155
|
185 |
(anInteger < 0) ifTrue:[
|
|
186 |
^ self error:'bad (negative) argument to new'
|
|
187 |
].
|
|
188 |
"
|
|
189 |
memory allocation failed.
|
|
190 |
When we arrive here, there was no memory, even after
|
|
191 |
a garbage collect. This means, that the VM wanted to
|
|
192 |
get some more memory from the Operatingsystem, which
|
|
193 |
was not kind enough to give some.
|
|
194 |
"
|
|
195 |
^ ObjectMemory allocationFailureSignal raise.
|
12
|
196 |
].
|
1
|
197 |
^ self basicNew:anInteger
|
|
198 |
! !
|
|
199 |
|
550
|
200 |
!ByteArray class methodsFor:'binary storage'!
|
1
|
201 |
|
550
|
202 |
binaryDefinitionFrom: stream manager: manager
|
|
203 |
"get a ByteArray from the binary stream.
|
|
204 |
ByteArrays are stored as 4-byte size, followed by the bytes"
|
1
|
205 |
|
550
|
206 |
"take care of subclasses ..."
|
|
207 |
self == ByteArray ifTrue:[
|
|
208 |
^ (stream next: (stream nextNumber: 4))
|
|
209 |
].
|
|
210 |
^ super binaryDefinitionFrom: stream manager: manager
|
|
211 |
! !
|
|
212 |
|
|
213 |
!ByteArray class methodsFor:'queries'!
|
|
214 |
|
|
215 |
isBuiltInClass
|
|
216 |
"this class is known by the run-time-system"
|
|
217 |
|
|
218 |
^ self == ByteArray
|
|
219 |
! !
|
|
220 |
|
|
221 |
!ByteArray methodsFor:'accessing'!
|
1
|
222 |
|
563
|
223 |
basicAt:index
|
|
224 |
"return the indexed instance variable with index, anInteger
|
|
225 |
- redefined here to be slighly faster than the default in Object"
|
|
226 |
|
|
227 |
%{ /* NOCONTEXT */
|
|
228 |
|
|
229 |
REGISTER int indx;
|
|
230 |
int nIndex;
|
|
231 |
OBJ cls;
|
|
232 |
|
|
233 |
if (__isSmallInteger(index)) {
|
|
234 |
indx = _intVal(index);
|
|
235 |
if (indx > 0) {
|
|
236 |
if ((cls = __qClass(self)) != ByteArray)
|
|
237 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
238 |
nIndex = __byteArraySize(self);
|
|
239 |
if (indx <= nIndex) {
|
|
240 |
RETURN ( _MKSMALLINT(_ByteArrayInstPtr(self)->ba_element[indx - 1]) );
|
|
241 |
}
|
|
242 |
}
|
|
243 |
}
|
|
244 |
%}
|
|
245 |
.
|
|
246 |
^ super basicAt:index
|
|
247 |
!
|
|
248 |
|
1
|
249 |
basicAt:index put:value
|
|
250 |
"set the indexed instance variable with index, anInteger to value
|
2
|
251 |
- redefined here to be slighly faster than the default in Object"
|
1
|
252 |
|
|
253 |
%{ /* NOCONTEXT */
|
|
254 |
|
|
255 |
REGISTER int indx;
|
|
256 |
int nIndex;
|
|
257 |
int val;
|
54
|
258 |
OBJ cls;
|
1
|
259 |
|
249
|
260 |
if (__bothSmallInteger(index, value)) {
|
155
|
261 |
val = _intVal(value);
|
216
|
262 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
|
155
|
263 |
indx = _intVal(index);
|
249
|
264 |
if (indx > 0) {
|
328
|
265 |
if ((cls = __qClass(self)) != ByteArray)
|
249
|
266 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
267 |
nIndex = __byteArraySize(self);
|
|
268 |
if (indx <= nIndex) {
|
|
269 |
_ByteArrayInstPtr(self)->ba_element[indx - 1] = val;
|
|
270 |
RETURN ( value );
|
|
271 |
}
|
155
|
272 |
}
|
|
273 |
}
|
1
|
274 |
}
|
|
275 |
%}
|
|
276 |
.
|
|
277 |
^ super basicAt:index put:value
|
2
|
278 |
!
|
|
279 |
|
54
|
280 |
byteAt:index
|
249
|
281 |
"return the byte at index.
|
|
282 |
For ByteArray, this is the same as basicAt:;
|
|
283 |
however, for strings or symbols, this returns a numeric byteValue
|
|
284 |
instead of a character."
|
|
285 |
|
|
286 |
%{ /* NOCONTEXT */
|
|
287 |
|
|
288 |
REGISTER int indx;
|
|
289 |
int nIndex;
|
|
290 |
OBJ cls;
|
54
|
291 |
|
249
|
292 |
if (__isSmallInteger(index)) {
|
|
293 |
indx = _intVal(index);
|
|
294 |
if (indx > 0) {
|
328
|
295 |
if ((cls = __qClass(self)) != ByteArray)
|
249
|
296 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
297 |
nIndex = __byteArraySize(self);
|
|
298 |
if (indx <= nIndex) {
|
|
299 |
RETURN ( _MKSMALLINT(_ByteArrayInstPtr(self)->ba_element[indx - 1]) );
|
|
300 |
}
|
|
301 |
}
|
|
302 |
}
|
|
303 |
%}
|
|
304 |
.
|
|
305 |
^ (super basicAt:index) asInteger
|
54
|
306 |
!
|
|
307 |
|
249
|
308 |
byteAt:index put:value
|
|
309 |
"set the byte at index. For ByteArray, this is the same as basicAt:put:.
|
|
310 |
However, for Strings, this expects a byteValue to be stored."
|
|
311 |
|
|
312 |
%{ /* NOCONTEXT */
|
|
313 |
|
|
314 |
REGISTER int indx;
|
|
315 |
int nIndex;
|
|
316 |
int val;
|
|
317 |
OBJ cls;
|
54
|
318 |
|
249
|
319 |
if (__bothSmallInteger(index, value)) {
|
|
320 |
val = _intVal(value);
|
|
321 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) {
|
|
322 |
indx = _intVal(index);
|
|
323 |
if (indx > 0) {
|
328
|
324 |
if ((cls = __qClass(self)) != ByteArray)
|
249
|
325 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
326 |
nIndex = __byteArraySize(self);
|
|
327 |
if (indx <= nIndex) {
|
|
328 |
_ByteArrayInstPtr(self)->ba_element[indx - 1] = val;
|
|
329 |
RETURN ( value );
|
|
330 |
}
|
|
331 |
}
|
|
332 |
}
|
|
333 |
}
|
|
334 |
%}
|
|
335 |
.
|
|
336 |
^ super basicAt:index put:value
|
54
|
337 |
!
|
|
338 |
|
563
|
339 |
doubleAt:index
|
|
340 |
"return the 8-bytes starting at index as a Float.
|
|
341 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
|
|
342 |
Notice also, that the bytes are expected to be in this machines
|
|
343 |
float representation - if the bytearray originated from another
|
|
344 |
machine, some conversion is usually needed."
|
2
|
345 |
|
563
|
346 |
|newFloat|
|
359
|
347 |
|
563
|
348 |
newFloat := Float basicNew.
|
|
349 |
1 to:8 do:[:destIndex|
|
|
350 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
|
359
|
351 |
].
|
563
|
352 |
^ newFloat.
|
359
|
353 |
!
|
|
354 |
|
563
|
355 |
doubleAt:index put:aFloat
|
|
356 |
"store the value of the argument, aFloat into the receiver
|
|
357 |
starting at index.
|
|
358 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80.
|
|
359 |
Notice also, that the bytes are expected to be in this machines
|
|
360 |
float representation - if the bytearray originated from another
|
|
361 |
machine, some conversion is usually needed."
|
54
|
362 |
|
563
|
363 |
1 to:8 do:[:srcIndex|
|
|
364 |
self at:index - 1 + srcIndex put:(aFloat basicAt:srcIndex)
|
359
|
365 |
].
|
563
|
366 |
^ aFloat
|
54
|
367 |
!
|
|
368 |
|
2
|
369 |
doubleWordAt:index
|
|
370 |
"return the 4-bytes starting at index as an (unsigned) Integer.
|
359
|
371 |
The value is retrieved in the machines natural byte order.
|
|
372 |
Q: should it return a signed value ? (see ByteArray>>signedDoubleWordAt:)"
|
|
373 |
|
|
374 |
%{ /* NOCONTEXT */
|
|
375 |
|
|
376 |
REGISTER int indx;
|
|
377 |
int nIndex;
|
|
378 |
union {
|
|
379 |
char u_char[4];
|
|
380 |
unsigned u_uint;
|
|
381 |
} val;
|
|
382 |
OBJ cls;
|
|
383 |
|
|
384 |
if (__isSmallInteger(index)) {
|
|
385 |
indx = _intVal(index);
|
|
386 |
if (indx > 0) {
|
|
387 |
if ((cls = __qClass(self)) != ByteArray)
|
|
388 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
389 |
nIndex = __byteArraySize(self);
|
|
390 |
if ((indx+3) <= nIndex) {
|
|
391 |
val.u_char[0] = _ByteArrayInstPtr(self)->ba_element[indx+0-1];
|
|
392 |
val.u_char[1] = _ByteArrayInstPtr(self)->ba_element[indx+1-1];
|
|
393 |
val.u_char[2] = _ByteArrayInstPtr(self)->ba_element[indx+2-1];
|
|
394 |
val.u_char[3] = _ByteArrayInstPtr(self)->ba_element[indx+3-1];
|
|
395 |
if ((val.u_uint >= 0) && (val.u_uint <= _MAX_INT)) {
|
|
396 |
RETURN ( _MKSMALLINT(val.u_uint) );
|
|
397 |
}
|
|
398 |
RETURN ( _MKULARGEINT(val.u_uint) );
|
|
399 |
}
|
|
400 |
}
|
|
401 |
}
|
|
402 |
%}.
|
|
403 |
^ SubscriptOutOfBoundsSignal raise.
|
|
404 |
|
|
405 |
"
|
|
406 |
|b|
|
|
407 |
|
|
408 |
b := ByteArray withAll:#(1 2 3 4).
|
|
409 |
(b doubleWordAt:1) printStringRadix:16
|
|
410 |
"
|
|
411 |
!
|
|
412 |
|
|
413 |
doubleWordAt:index MSB:msb
|
|
414 |
"return the 4-bytes starting at index as an (unsigned) Integer.
|
|
415 |
The value is retrieved MSB-first, if the msb-arg is true;
|
|
416 |
LSB-first otherwise.
|
|
417 |
Q: should it return a signed value ? (see ByteArray>>signedDoubleWordAt:)"
|
2
|
418 |
|
|
419 |
%{ /* NOCONTEXT */
|
|
420 |
|
|
421 |
REGISTER int indx;
|
|
422 |
int nIndex;
|
|
423 |
int val;
|
249
|
424 |
OBJ cls;
|
2
|
425 |
|
249
|
426 |
if (__isSmallInteger(index)) {
|
155
|
427 |
indx = _intVal(index);
|
249
|
428 |
if (indx > 0) {
|
328
|
429 |
if ((cls = __qClass(self)) != ByteArray)
|
249
|
430 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
431 |
nIndex = __byteArraySize(self);
|
|
432 |
if ((indx+3) <= nIndex) {
|
359
|
433 |
if (msb == true) {
|
|
434 |
val = _ByteArrayInstPtr(self)->ba_element[indx-1];
|
|
435 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx+1-1];
|
|
436 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx+2-1];
|
|
437 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx+3-1];
|
|
438 |
} else {
|
|
439 |
val = _ByteArrayInstPtr(self)->ba_element[indx+3-1];
|
|
440 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx+2-1];
|
|
441 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx+1-1];
|
|
442 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx-1];
|
|
443 |
}
|
249
|
444 |
if ((val >= 0) && (val <= _MAX_INT)) {
|
|
445 |
RETURN ( _MKSMALLINT(val) );
|
|
446 |
}
|
|
447 |
RETURN ( _MKULARGEINT(val) );
|
155
|
448 |
}
|
|
449 |
}
|
2
|
450 |
}
|
359
|
451 |
%}.
|
|
452 |
^ SubscriptOutOfBoundsSignal raise.
|
129
|
453 |
|
|
454 |
"
|
|
455 |
|b|
|
|
456 |
|
|
457 |
b := ByteArray withAll:#(1 2 3 4).
|
359
|
458 |
(b doubleWordAt:1 MSB:true) printStringRadix:16.
|
|
459 |
(b doubleWordAt:1 MSB:false) printStringRadix:16
|
129
|
460 |
"
|
2
|
461 |
!
|
|
462 |
|
|
463 |
doubleWordAt:index put:value
|
|
464 |
"set the 4-bytes starting at index from the (unsigned) Integer value.
|
359
|
465 |
The value should be in the range 0 to 16rFFFFFFFF
|
|
466 |
(for negative values, the stored value is not defined).
|
|
467 |
The value is stored in the machines natural byte order.
|
|
468 |
Q: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
|
|
469 |
|
|
470 |
|t|
|
|
471 |
|
|
472 |
%{ /* NOCONTEXT */
|
|
473 |
|
|
474 |
REGISTER int indx;
|
|
475 |
int nIndex;
|
|
476 |
union {
|
|
477 |
char u_char[4];
|
|
478 |
unsigned u_uint;
|
|
479 |
} val;
|
|
480 |
OBJ cls;
|
|
481 |
|
|
482 |
if (__isSmallInteger(index)) {
|
|
483 |
if (__isSmallInteger(value)) {
|
|
484 |
val.u_uint = _intVal(value);
|
|
485 |
} else {
|
|
486 |
val.u_uint = __longIntVal(value);
|
|
487 |
if (val.u_uint == 0) goto error;
|
|
488 |
}
|
|
489 |
|
|
490 |
indx = _intVal(index);
|
|
491 |
if (indx > 0) {
|
|
492 |
if ((cls = __qClass(self)) != ByteArray)
|
|
493 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
494 |
nIndex = __qSize(self) - OHDR_SIZE;
|
|
495 |
if ((indx+3) <= nIndex) {
|
|
496 |
_ByteArrayInstPtr(self)->ba_element[indx+0-1] = val.u_char[0];
|
|
497 |
_ByteArrayInstPtr(self)->ba_element[indx+1-1] = val.u_char[1];
|
|
498 |
_ByteArrayInstPtr(self)->ba_element[indx+2-1] = val.u_char[2];
|
|
499 |
_ByteArrayInstPtr(self)->ba_element[indx+3-1] = val.u_char[3];
|
|
500 |
RETURN ( value );
|
|
501 |
}
|
|
502 |
}
|
|
503 |
}
|
|
504 |
error: ;
|
|
505 |
%}.
|
|
506 |
^ SubscriptOutOfBoundsSignal raise.
|
|
507 |
|
|
508 |
"
|
|
509 |
|b|
|
|
510 |
b := ByteArray new:4.
|
|
511 |
b doubleWordAt:1 put:16r04030201.
|
|
512 |
b inspect
|
|
513 |
"
|
|
514 |
!
|
|
515 |
|
|
516 |
doubleWordAt:index put:value MSB:msb
|
|
517 |
"set the 4-bytes starting at index from the (unsigned) Integer value.
|
129
|
518 |
The value must be in the range 0 to 16rFFFFFFFF.
|
359
|
519 |
The value is stored MSB-first if msb is true; LSB-first otherwise.
|
129
|
520 |
question: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
|
2
|
521 |
|
|
522 |
|t|
|
|
523 |
|
|
524 |
%{ /* NOCONTEXT */
|
|
525 |
|
|
526 |
REGISTER int indx;
|
|
527 |
int nIndex;
|
|
528 |
int val;
|
249
|
529 |
OBJ cls;
|
2
|
530 |
|
359
|
531 |
if (__isSmallInteger(index)) {
|
|
532 |
if (__isSmallInteger(value)) {
|
|
533 |
val = _intVal(value);
|
|
534 |
} else {
|
|
535 |
val = __longIntVal(value);
|
|
536 |
if (val == 0) goto error;
|
|
537 |
}
|
|
538 |
indx = _intVal(index);
|
|
539 |
if (indx > 0) {
|
|
540 |
if ((cls = __qClass(self)) != ByteArray)
|
|
541 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
542 |
nIndex = __qSize(self) - OHDR_SIZE;
|
|
543 |
if ((indx+3) <= nIndex) {
|
|
544 |
if (msb == true) {
|
|
545 |
_ByteArrayInstPtr(self)->ba_element[indx+3-1] = val & 0xFF;
|
|
546 |
val >>= 8;
|
|
547 |
_ByteArrayInstPtr(self)->ba_element[indx+2-1] = val & 0xFF;
|
249
|
548 |
val >>= 8;
|
|
549 |
_ByteArrayInstPtr(self)->ba_element[indx+1-1] = val & 0xFF;
|
|
550 |
val >>= 8;
|
359
|
551 |
_ByteArrayInstPtr(self)->ba_element[indx+0-1] = val & 0xFF;
|
|
552 |
} else {
|
|
553 |
_ByteArrayInstPtr(self)->ba_element[indx+0-1] = val & 0xFF;
|
|
554 |
val >>= 8;
|
|
555 |
_ByteArrayInstPtr(self)->ba_element[indx+1-1] = val & 0xFF;
|
|
556 |
val >>= 8;
|
249
|
557 |
_ByteArrayInstPtr(self)->ba_element[indx+2-1] = val & 0xFF;
|
|
558 |
val >>= 8;
|
|
559 |
_ByteArrayInstPtr(self)->ba_element[indx+3-1] = val & 0xFF;
|
|
560 |
}
|
359
|
561 |
RETURN ( value );
|
155
|
562 |
}
|
|
563 |
}
|
2
|
564 |
}
|
359
|
565 |
error: ;
|
|
566 |
%}.
|
|
567 |
^ SubscriptOutOfBoundsSignal raise.
|
129
|
568 |
|
|
569 |
"
|
|
570 |
|b|
|
359
|
571 |
b := ByteArray new:8.
|
|
572 |
b doubleWordAt:1 put:16r04030201 MSB:true.
|
|
573 |
b doubleWordAt:5 put:16r04030201 MSB:false.
|
129
|
574 |
b inspect
|
|
575 |
"
|
54
|
576 |
!
|
|
577 |
|
563
|
578 |
floatAt:index
|
|
579 |
"return the 4-bytes starting at index as a Float.
|
|
580 |
Notice, that (currently) ST/X Floats are what Doubles are in ST-80;
|
|
581 |
therefore this method reads a 4-byte float from the byteArray and returns
|
|
582 |
a float object which keeps an 8-byte double internally.
|
|
583 |
Notice also, that the bytes are expected to be in this machines
|
|
584 |
float representation and order - if the bytearray originated from another
|
|
585 |
machine, some conversion is usually needed."
|
|
586 |
|
|
587 |
|newFloat|
|
|
588 |
|
|
589 |
newFloat := Float basicNew.
|
|
590 |
UninterpretedBytes isBigEndian ifFalse:[
|
|
591 |
5 to:8 do:[:destIndex|
|
|
592 |
newFloat basicAt:destIndex put:(self at:index - 5 + destIndex)
|
|
593 |
].
|
|
594 |
] ifTrue:[
|
|
595 |
1 to:4 do:[:destIndex|
|
|
596 |
newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
|
|
597 |
].
|
|
598 |
].
|
|
599 |
^ newFloat.
|
|
600 |
!
|
|
601 |
|
|
602 |
floatAt:index put:aFloat
|
|
603 |
"store the 4 bytes of value of the argument, aFloat into the receiver
|
|
604 |
starting at index.
|
|
605 |
Notice, that (currently) ST/X Floats are what DOubles are in ST-80.
|
|
606 |
Notice also, that the bytes are expected to be in this machines
|
|
607 |
float representation - if the bytearray originated from another
|
|
608 |
machine, some conversion is usually needed."
|
|
609 |
|
|
610 |
UninterpretedBytes isBigEndian ifFalse:[
|
|
611 |
5 to:8 do:[:srcIndex|
|
|
612 |
self at:index - 5 + srcIndex put:(aFloat basicAt:srcIndex)
|
|
613 |
].
|
|
614 |
] ifTrue:[
|
|
615 |
1 to:4 do:[:srcIndex|
|
|
616 |
self at:index - 1 + srcIndex put:(aFloat basicAt:srcIndex)
|
|
617 |
].
|
|
618 |
].
|
|
619 |
^ aFloat
|
|
620 |
!
|
|
621 |
|
|
622 |
ieeDoubleAt:index
|
|
623 |
"retrieve the 8 bytes starting at index as a float.
|
|
624 |
The 8 bytes are assumed to be in IEE floating point single precision
|
|
625 |
number format."
|
|
626 |
|
|
627 |
"
|
|
628 |
currently, we assume that the machines native number format is already
|
|
629 |
IEE format - we need some more code here whenever ST/X is ported
|
|
630 |
to an IBM 370 or old VAX etc.
|
|
631 |
To date, all supported systems use IEE float numbers, so there should be
|
|
632 |
no problem.
|
|
633 |
"
|
|
634 |
^ self doubleAt:index
|
|
635 |
!
|
|
636 |
|
|
637 |
ieeDoubleAt:index put:aFloat
|
|
638 |
"store the value of the argument, aFloat into the receiver
|
|
639 |
starting at index. Storage is in IEE floating point double precision format.
|
|
640 |
(i.e. 8 bytes are stored)."
|
|
641 |
|
|
642 |
"
|
|
643 |
currently, we assume that the machines native number format is already
|
|
644 |
IEE format - we need some more code here whenever ST/X is ported
|
|
645 |
to an IBM 370 or old VAX etc.
|
|
646 |
To date, all supported systems use IEE float numbers, so there should be
|
|
647 |
no problem.
|
|
648 |
"
|
|
649 |
^ self doubleAt:index put:aFloat
|
|
650 |
!
|
|
651 |
|
|
652 |
ieeFloatAt:index
|
|
653 |
"retrieve the 4 bytes starting at index as a float.
|
|
654 |
The 4 bytes are assumed to be in IEE floating point single precision
|
|
655 |
number format."
|
|
656 |
|
|
657 |
"
|
|
658 |
currently, we assume that the machines native number format is already
|
|
659 |
IEE format - we need some more code here whenever ST/X is ported
|
|
660 |
to an IBM 370 or old VAX etc.
|
|
661 |
To date, all supported systems use IEE float numbers, so there should be
|
|
662 |
no problem.
|
|
663 |
"
|
|
664 |
^ self floatAt:index
|
|
665 |
!
|
|
666 |
|
|
667 |
ieeFloatAt:index put:aFloat
|
|
668 |
"store the value of the argument, aFloat into the receiver
|
|
669 |
starting at index. Storage is in IEE floating point single precision format.
|
|
670 |
(i.e. 4 bytes are stored). Since ST/X floats are really doubles, the low-
|
|
671 |
order 4 bytes of the precision is lost."
|
|
672 |
|
|
673 |
"
|
|
674 |
currently, we assume that the machines native number format is already
|
|
675 |
IEE format - we need some more code here whenever ST/X is ported
|
|
676 |
to an IBM 370 or old VAX etc.
|
|
677 |
To date, all supported systems use IEE float numbers, so there should be
|
|
678 |
no problem.
|
|
679 |
"
|
|
680 |
^ self floatAt:index put:aFloat
|
|
681 |
!
|
|
682 |
|
|
683 |
quadWordAt:index MSB:msb
|
|
684 |
"return the 8-bytes starting at index as an (unsigned) Integer.
|
|
685 |
Depending on msb, the value is retrieved MSB or LSB-first."
|
|
686 |
|
|
687 |
|l
|
|
688 |
bIdx "{ Class: SmallInteger }"
|
|
689 |
delta "{ Class: SmallInteger }"|
|
|
690 |
|
|
691 |
l := LargeInteger basicNew numberOfDigits:8.
|
|
692 |
msb ifTrue:[
|
|
693 |
bIdx := index + 7.
|
|
694 |
delta := -1
|
|
695 |
] ifFalse:[
|
|
696 |
bIdx := index.
|
|
697 |
delta := 1
|
|
698 |
].
|
|
699 |
1 to:8 do:[:i |
|
|
700 |
l digitAt:i put:(self basicAt:bIdx).
|
|
701 |
bIdx := bIdx + delta
|
|
702 |
].
|
|
703 |
^ l normalize
|
|
704 |
|
|
705 |
"
|
|
706 |
|b|
|
|
707 |
|
|
708 |
b := ByteArray withAll:#(1 2 3 4 5 6 7 8).
|
|
709 |
(b quadWordAt:1 MSB:false) printStringRadix:16
|
|
710 |
"
|
|
711 |
!
|
|
712 |
|
|
713 |
quadWordAt:index put:anInteger MSB:msb
|
|
714 |
"set the 8-bytes starting at index from the (unsigned) Integer value.
|
|
715 |
The value must be in the range 0 to 16rFFFFFFFFFFFFFFFF.
|
|
716 |
Depending on msb, the value is stored MSB-first or LSB-first."
|
|
717 |
|
|
718 |
|bIdx "{ Class: SmallInteger }"
|
|
719 |
delta "{ Class: SmallInteger }"|
|
|
720 |
|
|
721 |
msb ifTrue:[
|
|
722 |
bIdx := index + 7.
|
|
723 |
delta := -1
|
|
724 |
] ifFalse:[
|
|
725 |
bIdx := index.
|
|
726 |
delta := 1
|
|
727 |
].
|
|
728 |
1 to:8 do:[:i |
|
|
729 |
self basicAt:bIdx put:(anInteger digitAt:i).
|
|
730 |
bIdx := bIdx + delta.
|
|
731 |
].
|
|
732 |
^ anInteger
|
|
733 |
|
|
734 |
"
|
|
735 |
|b|
|
|
736 |
b := ByteArray new:8.
|
|
737 |
b quadWordAtIndex:1 put:16r0807060504030201 MSB:false.
|
|
738 |
b inspect
|
|
739 |
"
|
|
740 |
!
|
|
741 |
|
54
|
742 |
signedDoubleWordAt:index
|
129
|
743 |
"return the 4-bytes starting at index as a signed Integer.
|
359
|
744 |
The value is retrieved in the machines natural byte order."
|
54
|
745 |
|
|
746 |
|w|
|
|
747 |
|
129
|
748 |
"
|
|
749 |
stupid: due to an STC bug, cannot currently have LargeInteger
|
|
750 |
constants - change to code below when fixed ...
|
|
751 |
"
|
54
|
752 |
w := self doubleWordAt:index.
|
|
753 |
(w > (16r7FFFFFF * 16r10 + 16rF)) ifTrue:[
|
155
|
754 |
^ w - (16r10000000 * 16r10)
|
54
|
755 |
].
|
|
756 |
^ w
|
|
757 |
"
|
|
758 |
w := self doubleWordAt:index.
|
|
759 |
(w > 16r7FFFFFFF) ifTrue:[
|
155
|
760 |
^ w - 16r100000000
|
54
|
761 |
].
|
|
762 |
^ w
|
|
763 |
"
|
|
764 |
|
|
765 |
"
|
129
|
766 |
|b|
|
|
767 |
b := ByteArray new:4.
|
|
768 |
b doubleWordAt:1 put:16rFFFFFFFF.
|
|
769 |
(b signedDoubleWordAt:1)
|
54
|
770 |
"
|
|
771 |
!
|
|
772 |
|
359
|
773 |
signedDoubleWordAt:index MSB:msb
|
|
774 |
"return the 4-bytes starting at index as a signed Integer.
|
|
775 |
Depending on msb, the value is retrieved MSB-first or LSB-first."
|
54
|
776 |
|
359
|
777 |
|w|
|
|
778 |
|
129
|
779 |
"
|
|
780 |
stupid: due to an STC bug, cannot currently have LargeInteger
|
|
781 |
constants - change to code below when fixed ...
|
|
782 |
"
|
359
|
783 |
w := self doubleWordAt:index MSB:msb.
|
|
784 |
(w > (16r7FFFFFF * 16r10 + 16rF)) ifTrue:[
|
|
785 |
^ w - (16r10000000 * 16r10)
|
|
786 |
].
|
|
787 |
^ w
|
|
788 |
"
|
|
789 |
w := self doubleWordAt:index.
|
|
790 |
(w > 16r7FFFFFFF) ifTrue:[
|
|
791 |
^ w - 16r100000000
|
|
792 |
].
|
|
793 |
^ w
|
54
|
794 |
"
|
359
|
795 |
|
|
796 |
"
|
|
797 |
|b|
|
|
798 |
b := ByteArray new:4.
|
|
799 |
b doubleWordAt:1 put:16rFFFFFFFF.
|
|
800 |
(b signedDoubleWordAt:1)
|
|
801 |
"
|
|
802 |
!
|
|
803 |
|
|
804 |
signedDoubleWordAt:index put:value
|
|
805 |
"set the 4-bytes starting at index from the signed Integer value.
|
|
806 |
The value is stored in the machines natural byte order."
|
|
807 |
|
|
808 |
|v|
|
|
809 |
|
|
810 |
value > 0 ifTrue:[
|
|
811 |
v := value
|
|
812 |
] ifFalse:[
|
|
813 |
"
|
|
814 |
stupid: due to an STC bug, cannot currently have LargeInteger
|
|
815 |
constants - change to code below when fixed ...
|
|
816 |
"
|
|
817 |
v := value + (16r10000000 * 16r10)
|
|
818 |
"//// v := value + 16r100000000
|
|
819 |
].
|
|
820 |
self doubleWordAt:index put:v.
|
|
821 |
^ value
|
|
822 |
|
|
823 |
"
|
|
824 |
|b|
|
|
825 |
b := ByteArray new:4.
|
|
826 |
b signedDoubleWordAt:1 put:-1.
|
|
827 |
(b doubleWordAt:1) printStringRadix:16
|
|
828 |
"
|
|
829 |
!
|
|
830 |
|
|
831 |
signedDoubleWordAt:index put:value MSB:msb
|
|
832 |
"set the 4-bytes starting at index from the signed Integer value.
|
|
833 |
Depending on msb, the value is stored MSB-first or LSB-first."
|
|
834 |
|
|
835 |
|v|
|
|
836 |
|
|
837 |
value > 0 ifTrue:[
|
|
838 |
v := value
|
|
839 |
] ifFalse:[
|
|
840 |
"
|
|
841 |
stupid: due to an STC bug, cannot currently have LargeInteger
|
|
842 |
constants - change to code below when fixed ...
|
|
843 |
"
|
|
844 |
v := value + (16r10000000 * 16r10)
|
|
845 |
"//// v := value + 16r100000000
|
|
846 |
].
|
|
847 |
self doubleWordAt:index put:v MSB:msb.
|
|
848 |
^ value
|
|
849 |
|
129
|
850 |
"
|
|
851 |
|b|
|
|
852 |
b := ByteArray new:4.
|
|
853 |
b signedDoubleWordAt:1 put:-1.
|
|
854 |
(b doubleWordAt:1) printStringRadix:16
|
|
855 |
"
|
|
856 |
!
|
54
|
857 |
|
563
|
858 |
signedWordAt:index
|
|
859 |
"return the 2-bytes starting at index as a signed Integer.
|
|
860 |
The value is retrieved in the machines natural byte order."
|
|
861 |
|
|
862 |
|w "{ Class: SmallInteger }"|
|
129
|
863 |
|
563
|
864 |
w := self wordAt:index.
|
|
865 |
(w > 16r7FFF) ifTrue:[
|
|
866 |
^ w - 16r10000
|
|
867 |
].
|
|
868 |
^ w
|
129
|
869 |
|
563
|
870 |
"
|
|
871 |
|b|
|
|
872 |
b := ByteArray new:2.
|
|
873 |
b wordAt:1 put:16rFFFF.
|
|
874 |
b signedWordAt:1
|
|
875 |
"
|
|
876 |
!
|
|
877 |
|
|
878 |
signedWordAt:index MSB:msb
|
|
879 |
"return the 2-bytes starting at index as a signed Integer.
|
|
880 |
The value is retrieved MSB-first if the msb-arg is true,
|
|
881 |
LSB-first otherwise"
|
|
882 |
|
|
883 |
|w "{ Class: SmallInteger }"|
|
|
884 |
|
|
885 |
w := self wordAt:index MSB:msb.
|
|
886 |
(w > 16r7FFF) ifTrue:[
|
|
887 |
^ w - 16r10000
|
395
|
888 |
].
|
563
|
889 |
^ w
|
129
|
890 |
|
|
891 |
"
|
|
892 |
|b|
|
563
|
893 |
b := ByteArray new:2.
|
|
894 |
b wordAt:1 put:16rFFFF.
|
|
895 |
b signedWordAt:1
|
129
|
896 |
"
|
|
897 |
!
|
|
898 |
|
563
|
899 |
signedWordAt:index put:value
|
|
900 |
"set the 2-bytes starting at index from the signed Integer value.
|
|
901 |
The stored value must be in the range -32768 .. +32676.
|
|
902 |
The value is stored in the machines natural byteorder."
|
129
|
903 |
|
563
|
904 |
|v|
|
129
|
905 |
|
563
|
906 |
value > 0 ifTrue:[
|
|
907 |
v := value
|
359
|
908 |
] ifFalse:[
|
563
|
909 |
v := 16r10000 + value
|
395
|
910 |
].
|
563
|
911 |
self wordAt:index put:v.
|
|
912 |
^ value
|
129
|
913 |
|
|
914 |
"
|
|
915 |
|b|
|
563
|
916 |
b := ByteArray new:4.
|
|
917 |
b signedWordAt:1 put:-1.
|
|
918 |
b signedWordAt:3 put:-2.
|
|
919 |
b inspect
|
|
920 |
"
|
|
921 |
!
|
|
922 |
|
|
923 |
signedWordAt:index put:value MSB:msb
|
|
924 |
"set the 2-bytes starting at index from the signed Integer value.
|
|
925 |
The stored value must be in the range -32768 .. +32676.
|
|
926 |
The value is stored MSB-first, if the msb-arg is true;
|
|
927 |
LSB-first otherwise"
|
|
928 |
|
|
929 |
|v|
|
|
930 |
|
|
931 |
value > 0 ifTrue:[
|
|
932 |
v := value
|
|
933 |
] ifFalse:[
|
|
934 |
v := 16r10000 + value
|
|
935 |
].
|
|
936 |
self wordAt:index put:v MSB:msb.
|
|
937 |
^ value
|
|
938 |
|
|
939 |
"
|
|
940 |
|b|
|
|
941 |
b := ByteArray new:4.
|
|
942 |
b signedWordAt:1 put:-1.
|
|
943 |
b signedWordAt:3 put:-2.
|
129
|
944 |
b inspect
|
|
945 |
"
|
54
|
946 |
!
|
|
947 |
|
563
|
948 |
wordAt:index
|
|
949 |
"return the 2-bytes starting at index as an (unsigned) Integer.
|
|
950 |
The value is retrieved in the machines natural byte order
|
|
951 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
|
|
952 |
|
|
953 |
%{ /* NOCONTEXT */
|
54
|
954 |
|
563
|
955 |
REGISTER int indx;
|
|
956 |
int nIndex;
|
|
957 |
union {
|
|
958 |
char u_char[2];
|
|
959 |
unsigned short u_ushort;
|
|
960 |
} val;
|
|
961 |
OBJ cls;
|
54
|
962 |
|
563
|
963 |
if (__isSmallInteger(index)) {
|
|
964 |
indx = _intVal(index);
|
|
965 |
if (indx > 0) {
|
|
966 |
if ((cls = __qClass(self)) != ByteArray)
|
|
967 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
968 |
nIndex = __byteArraySize(self);
|
|
969 |
if ((indx+1) <= nIndex) {
|
|
970 |
val.u_char[0] = _ByteArrayInstPtr(self)->ba_element[indx-1];
|
|
971 |
val.u_char[1] = _ByteArrayInstPtr(self)->ba_element[indx-1+1];
|
|
972 |
RETURN ( _MKSMALLINT(val.u_ushort) );
|
|
973 |
}
|
|
974 |
}
|
|
975 |
}
|
|
976 |
%}.
|
|
977 |
^ SubscriptOutOfBoundsSignal raise.
|
54
|
978 |
!
|
|
979 |
|
563
|
980 |
wordAt:index MSB:msb
|
|
981 |
"return the 2-bytes starting at index as an (unsigned) Integer.
|
|
982 |
The value is retrieved MSB (high 8 bits at lower index) if msb is true;
|
|
983 |
LSB-first (i.e. low 8-bits at lower byte index) if its false.
|
|
984 |
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
|
|
985 |
|
|
986 |
%{ /* NOCONTEXT */
|
|
987 |
|
|
988 |
REGISTER int indx;
|
|
989 |
int nIndex;
|
|
990 |
int val;
|
|
991 |
OBJ cls;
|
54
|
992 |
|
563
|
993 |
if (__isSmallInteger(index)) {
|
|
994 |
indx = _intVal(index);
|
|
995 |
if (indx > 0) {
|
|
996 |
if ((cls = __qClass(self)) != ByteArray)
|
|
997 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
998 |
nIndex = __byteArraySize(self);
|
|
999 |
if ((indx+1) <= nIndex) {
|
|
1000 |
if (msb == true) {
|
|
1001 |
val = _ByteArrayInstPtr(self)->ba_element[indx-1];
|
|
1002 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx-1+1];
|
|
1003 |
} else {
|
|
1004 |
val = _ByteArrayInstPtr(self)->ba_element[indx+1-1];
|
|
1005 |
val = (val << 8) + _ByteArrayInstPtr(self)->ba_element[indx-1];
|
|
1006 |
}
|
|
1007 |
RETURN ( _MKSMALLINT(val) );
|
|
1008 |
}
|
|
1009 |
}
|
|
1010 |
}
|
|
1011 |
%}.
|
|
1012 |
^ SubscriptOutOfBoundsSignal raise.
|
54
|
1013 |
!
|
|
1014 |
|
563
|
1015 |
wordAt:index put:value
|
|
1016 |
"set the 2-bytes starting at index from the (unsigned) Integer value.
|
|
1017 |
The stored value must be in the range 0 .. 16rFFFF.
|
|
1018 |
The value is stored in the machines natural byteorder.
|
|
1019 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
|
|
1020 |
|
|
1021 |
%{ /* NOCONTEXT */
|
54
|
1022 |
|
563
|
1023 |
REGISTER int indx;
|
|
1024 |
int nIndex;
|
|
1025 |
int v;
|
|
1026 |
union {
|
|
1027 |
char u_char[2];
|
|
1028 |
unsigned short u_ushort;
|
|
1029 |
} val;
|
|
1030 |
OBJ cls;
|
129
|
1031 |
|
563
|
1032 |
if (__bothSmallInteger(index, value)) {
|
|
1033 |
indx = _intVal(index);
|
|
1034 |
if (indx > 0) {
|
|
1035 |
if ((cls = __qClass(self)) != ByteArray)
|
|
1036 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1037 |
nIndex = __byteArraySize(self);
|
|
1038 |
if ((indx+1) <= nIndex) {
|
|
1039 |
val.u_ushort = v = _intVal(value);
|
|
1040 |
if ((v & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
|
|
1041 |
_ByteArrayInstPtr(self)->ba_element[indx-1] = val.u_char[0];
|
|
1042 |
_ByteArrayInstPtr(self)->ba_element[indx-1+1] = val.u_char[1];
|
|
1043 |
RETURN ( value );
|
|
1044 |
}
|
|
1045 |
}
|
|
1046 |
}
|
|
1047 |
}
|
|
1048 |
%}.
|
|
1049 |
((value < 0) or:[value > 16rFFFF]) ifTrue:[
|
|
1050 |
^ self elementBoundsError
|
|
1051 |
].
|
|
1052 |
^ SubscriptOutOfBoundsSignal raise.
|
129
|
1053 |
|
|
1054 |
"
|
563
|
1055 |
|b|
|
|
1056 |
b := ByteArray new:4.
|
|
1057 |
b wordAt:1 put:16r0102.
|
|
1058 |
b wordAt:3 put:16r0304.
|
|
1059 |
b inspect
|
129
|
1060 |
"
|
|
1061 |
!
|
|
1062 |
|
563
|
1063 |
wordAt:index put:value MSB:msb
|
|
1064 |
"set the 2-bytes starting at index from the (unsigned) Integer value.
|
|
1065 |
The stored value must be in the range 0 .. 16rFFFF.
|
|
1066 |
The value is stored LSB-first (i.e. the low 8bits are stored at the
|
|
1067 |
lower index) if msb is false, MSB-first otherwise.
|
|
1068 |
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
|
|
1069 |
|
|
1070 |
%{ /* NOCONTEXT */
|
|
1071 |
|
|
1072 |
REGISTER int indx;
|
|
1073 |
int nIndex;
|
|
1074 |
int val;
|
|
1075 |
OBJ cls;
|
|
1076 |
|
|
1077 |
if (__bothSmallInteger(index, value)) {
|
|
1078 |
indx = _intVal(index);
|
|
1079 |
if (indx > 0) {
|
|
1080 |
if ((cls = __qClass(self)) != ByteArray)
|
|
1081 |
indx += __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1082 |
nIndex = __byteArraySize(self);
|
|
1083 |
if ((indx+1) <= nIndex) {
|
|
1084 |
val = _intVal(value);
|
|
1085 |
if ((val & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
|
|
1086 |
if (msb == true) {
|
|
1087 |
_ByteArrayInstPtr(self)->ba_element[indx-1+1] = val & 0xFF;
|
|
1088 |
_ByteArrayInstPtr(self)->ba_element[indx-1] = (val>>8) & 0xFF;
|
|
1089 |
} else {
|
|
1090 |
_ByteArrayInstPtr(self)->ba_element[indx-1] = val & 0xFF;
|
|
1091 |
_ByteArrayInstPtr(self)->ba_element[indx+1-1] = (val>>8) & 0xFF;
|
|
1092 |
}
|
|
1093 |
RETURN ( value );
|
|
1094 |
}
|
|
1095 |
}
|
|
1096 |
}
|
|
1097 |
}
|
|
1098 |
%}.
|
|
1099 |
((value < 0) or:[value > 16rFFFF]) ifTrue:[
|
|
1100 |
^ self elementBoundsError
|
|
1101 |
].
|
|
1102 |
^ SubscriptOutOfBoundsSignal raise.
|
129
|
1103 |
|
|
1104 |
"
|
563
|
1105 |
|b|
|
|
1106 |
b := ByteArray new:8.
|
|
1107 |
b wordAt:1 put:16r0102 MSB:false.
|
|
1108 |
b wordAt:3 put:16r0304 MSB:false.
|
|
1109 |
b wordAt:5 put:16r0102 MSB:true.
|
|
1110 |
b wordAt:7 put:16r0304 MSB:true.
|
|
1111 |
b inspect
|
129
|
1112 |
"
|
1
|
1113 |
! !
|
|
1114 |
|
550
|
1115 |
!ByteArray methodsFor:'binary storage'!
|
|
1116 |
|
|
1117 |
storeBinaryDefinitionOn:stream manager:manager
|
|
1118 |
"append a binary representation of the receiver onto stream.
|
|
1119 |
Redefined since ByteArrays are stored with a special type code and
|
|
1120 |
in a more compact way."
|
|
1121 |
|
|
1122 |
"not, if I have named instance variables"
|
|
1123 |
self class instSize ~~ 0 ifTrue:[
|
|
1124 |
^ super storeBinaryDefinitionOn:stream manager:manager
|
|
1125 |
].
|
|
1126 |
manager putIdOfClass:(self class) on: stream.
|
|
1127 |
stream nextNumber:4 put:(self basicSize).
|
|
1128 |
stream nextPutAll:(self asByteArray)
|
|
1129 |
! !
|
|
1130 |
|
12
|
1131 |
!ByteArray methodsFor:'converting'!
|
|
1132 |
|
|
1133 |
asByteArray
|
|
1134 |
"return the receiver as a byteArray"
|
|
1135 |
|
|
1136 |
"could be an instance of a subclass..."
|
|
1137 |
self class == ByteArray ifTrue:[
|
155
|
1138 |
^ self
|
12
|
1139 |
].
|
|
1140 |
^ super asByteArray
|
129
|
1141 |
|
|
1142 |
"
|
|
1143 |
'hello world' asByteArray
|
|
1144 |
#(1 2 3 4 5 6 7) asByteArray
|
|
1145 |
#(1 2 256 4 5 6 7) asByteArray
|
|
1146 |
"
|
12
|
1147 |
! !
|
|
1148 |
|
92
|
1149 |
!ByteArray methodsFor:'copying'!
|
|
1150 |
|
|
1151 |
copyFrom:start to:stop
|
|
1152 |
"return the subcollection starting at index start, anInteger and ending
|
|
1153 |
at stop, anInteger.
|
|
1154 |
- reimplemented here for speed"
|
|
1155 |
|
|
1156 |
%{ /* NOCONTEXT */
|
|
1157 |
|
|
1158 |
#if !defined(FAST_MEMCPY)
|
|
1159 |
REGISTER unsigned char *srcp;
|
|
1160 |
#endif
|
|
1161 |
REGISTER unsigned char *dstp;
|
|
1162 |
REGISTER int count;
|
|
1163 |
int len, index1, index2, sz;
|
|
1164 |
OBJ newByteArray;
|
|
1165 |
|
|
1166 |
if (__isByteArray(self)
|
249
|
1167 |
&& __bothSmallInteger(start, stop)) {
|
|
1168 |
len = __byteArraySize(self);
|
155
|
1169 |
index1 = _intVal(start);
|
|
1170 |
index2 = _intVal(stop);
|
92
|
1171 |
|
155
|
1172 |
if ((index1 <= index2) && (index1 > 0)) {
|
|
1173 |
if (index2 <= len) {
|
|
1174 |
count = index2 - index1 + 1;
|
|
1175 |
PROTECT_CONTEXT
|
|
1176 |
sz = OHDR_SIZE + count;
|
|
1177 |
_qNew(newByteArray, sz, SENDER);
|
|
1178 |
UNPROTECT_CONTEXT
|
|
1179 |
if (newByteArray != nil) {
|
|
1180 |
_InstPtr(newByteArray)->o_class = ByteArray;
|
|
1181 |
dstp = _ByteArrayInstPtr(newByteArray)->ba_element;
|
92
|
1182 |
#ifdef FAST_MEMCPY
|
155
|
1183 |
bcopy(_ByteArrayInstPtr(self)->ba_element + index1 - 1, dstp, count);
|
92
|
1184 |
#else
|
155
|
1185 |
srcp = _ByteArrayInstPtr(self)->ba_element + index1 - 1;
|
|
1186 |
while (count--) {
|
|
1187 |
*dstp++ = *srcp++;
|
|
1188 |
}
|
92
|
1189 |
#endif
|
155
|
1190 |
RETURN ( newByteArray );
|
|
1191 |
}
|
|
1192 |
}
|
|
1193 |
}
|
92
|
1194 |
}
|
|
1195 |
%}.
|
|
1196 |
"
|
|
1197 |
fall back in case of non-integer index or out-of-bound index;
|
|
1198 |
will eventually lead to an out-of-bound signal raise
|
|
1199 |
"
|
|
1200 |
^ super copyFrom:start to:stop
|
|
1201 |
! !
|
|
1202 |
|
1
|
1203 |
!ByteArray methodsFor:'filling and replacing'!
|
|
1204 |
|
155
|
1205 |
from:start to:stop put:aNumber
|
|
1206 |
"fill part of the receiver with aNumber.
|
|
1207 |
- reimplemented here for speed"
|
|
1208 |
|
|
1209 |
%{ /* NOCONTEXT */
|
|
1210 |
|
|
1211 |
REGISTER unsigned char *dstp;
|
|
1212 |
REGISTER int count, value;
|
249
|
1213 |
int len, index1, index2;
|
|
1214 |
int nInst;
|
|
1215 |
OBJ cls;
|
155
|
1216 |
|
249
|
1217 |
if (__isSmallInteger(aNumber)
|
|
1218 |
&& __bothSmallInteger(start, stop)) {
|
|
1219 |
len = __byteArraySize(self);
|
155
|
1220 |
index1 = _intVal(start);
|
|
1221 |
index2 = _intVal(stop);
|
|
1222 |
|
249
|
1223 |
dstp = _ByteArrayInstPtr(self)->ba_element + index1 - 1;
|
328
|
1224 |
if ((cls = __qClass(self)) != ByteArray) {
|
249
|
1225 |
nInst = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1226 |
dstp += nInst;
|
|
1227 |
len -= nInst;
|
|
1228 |
}
|
|
1229 |
|
155
|
1230 |
value = _intVal(aNumber);
|
422
|
1231 |
if (((value & ~0xFF) == 0) /* i.e. (value >= 0) && (value <= 255) */
|
155
|
1232 |
&& (index1 <= index2)
|
|
1233 |
&& (index1 > 0)) {
|
|
1234 |
if (index2 <= len) {
|
|
1235 |
count = index2 - index1 + 1;
|
|
1236 |
#ifdef FAST_MEMSET
|
249
|
1237 |
memset(dstp, count, value);
|
155
|
1238 |
#else
|
422
|
1239 |
# ifdef UNROLL_LOOPS
|
|
1240 |
while (count >= 8) {
|
|
1241 |
dstp[0] = dstp[1] = dstp[2] = dstp[3] =
|
|
1242 |
dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
|
|
1243 |
dstp += 8;
|
|
1244 |
count -= 8;
|
|
1245 |
}
|
|
1246 |
# endif
|
155
|
1247 |
while (count--) {
|
|
1248 |
*dstp++ = value;
|
|
1249 |
}
|
|
1250 |
#endif
|
|
1251 |
RETURN (self);
|
|
1252 |
}
|
|
1253 |
}
|
|
1254 |
}
|
|
1255 |
%}.
|
|
1256 |
"
|
|
1257 |
fall back in case of non-integer index or out-of-bound index/value;
|
|
1258 |
will eventually lead to an out-of-bound signal raise
|
|
1259 |
"
|
|
1260 |
^ super from:start to:stop put:aNumber
|
|
1261 |
!
|
|
1262 |
|
249
|
1263 |
replaceBytesFrom:start to:stop with:aCollection startingAt:repStart
|
|
1264 |
"replace elements from another collection, which must be a ByteArray
|
|
1265 |
or String."
|
1
|
1266 |
|
54
|
1267 |
%{ /* NOCONTEXT */
|
1
|
1268 |
|
54
|
1269 |
int nIndex, repNIndex;
|
|
1270 |
int startIndex, stopIndex;
|
|
1271 |
REGISTER unsigned char *src;
|
|
1272 |
REGISTER int repStartIndex;
|
|
1273 |
int repStopIndex, count;
|
|
1274 |
REGISTER unsigned char *dst;
|
249
|
1275 |
OBJ cls;
|
|
1276 |
int nInst;
|
1
|
1277 |
|
249
|
1278 |
if (__isBytes(aCollection)
|
|
1279 |
&& __bothSmallInteger(start, stop)
|
|
1280 |
&& __isSmallInteger(repStart)) {
|
155
|
1281 |
startIndex = _intVal(start) - 1;
|
|
1282 |
if (startIndex >= 0) {
|
249
|
1283 |
dst = (_ByteArrayInstPtr(self)->ba_element) + startIndex;
|
|
1284 |
nIndex = __byteArraySize(self);
|
|
1285 |
|
328
|
1286 |
if ((cls = __qClass(self)) != ByteArray) {
|
249
|
1287 |
nInst = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1288 |
dst += nInst;
|
|
1289 |
nIndex -= nInst;
|
|
1290 |
}
|
|
1291 |
|
155
|
1292 |
stopIndex = _intVal(stop) - 1;
|
|
1293 |
count = stopIndex - startIndex + 1;
|
|
1294 |
if (count == 0) {
|
|
1295 |
RETURN ( self );
|
|
1296 |
}
|
|
1297 |
if ((count > 0) && (stopIndex < nIndex)) {
|
|
1298 |
repStartIndex = _intVal(repStart) - 1;
|
|
1299 |
if (repStartIndex >= 0) {
|
328
|
1300 |
repNIndex = __qSize(aCollection) - OHDR_SIZE;
|
249
|
1301 |
src = (_ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
|
328
|
1302 |
if ((cls = __qClass(aCollection)) != ByteArray) {
|
249
|
1303 |
nInst = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1304 |
src += nInst;
|
|
1305 |
repNIndex -= nInst;
|
|
1306 |
}
|
|
1307 |
|
155
|
1308 |
repStopIndex = repStartIndex + (stopIndex - startIndex);
|
|
1309 |
if (repStopIndex < repNIndex) {
|
|
1310 |
if (aCollection == self) {
|
|
1311 |
/* take care of overlapping copy */
|
|
1312 |
if (src < dst) {
|
|
1313 |
/* must do a reverse copy */
|
|
1314 |
src += count;
|
|
1315 |
dst += count;
|
|
1316 |
while (count-- > 0) {
|
|
1317 |
*--dst = *--src;
|
|
1318 |
}
|
|
1319 |
RETURN ( self );
|
|
1320 |
}
|
|
1321 |
}
|
1
|
1322 |
#ifdef FAST_MEMCPY
|
166
|
1323 |
# ifdef bcopy4
|
|
1324 |
if (((src & 3) == 0)
|
|
1325 |
&& ((dst & 3) == 0)) {
|
|
1326 |
/* copy aligned part */
|
|
1327 |
bcopy4(src, dst, count//4);
|
|
1328 |
/* copy rest */
|
|
1329 |
if (count & 3) {
|
|
1330 |
src += (count & ~3);
|
|
1331 |
dst += (count & ~3);
|
|
1332 |
count = count & 3;
|
|
1333 |
while (count--) {
|
|
1334 |
*dst++ = *src++;
|
|
1335 |
}
|
|
1336 |
}
|
|
1337 |
} else
|
|
1338 |
# endif /* bcopy4 */
|
|
1339 |
bcopy(src, dst, count);
|
1
|
1340 |
#else
|
155
|
1341 |
while (count-- > 0) {
|
|
1342 |
*dst++ = *src++;
|
|
1343 |
}
|
1
|
1344 |
#endif
|
155
|
1345 |
RETURN ( self );
|
|
1346 |
}
|
|
1347 |
}
|
|
1348 |
}
|
|
1349 |
}
|
54
|
1350 |
}
|
437
|
1351 |
%}.
|
|
1352 |
"
|
|
1353 |
fall back in case of non-ByteArray argument,
|
|
1354 |
or for the error report if any index is invalid
|
|
1355 |
"
|
|
1356 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
|
563
|
1357 |
!
|
|
1358 |
|
|
1359 |
replaceFrom:start to:stop with:aCollection startingAt:repStart
|
|
1360 |
"replace elements from another collection"
|
|
1361 |
|
|
1362 |
(aCollection class == self class) ifTrue:[
|
|
1363 |
^ self replaceBytesFrom:start to:stop with:aCollection startingAt:repStart
|
|
1364 |
].
|
|
1365 |
^ super replaceFrom:start to:stop with:aCollection startingAt:repStart
|
1
|
1366 |
! !
|
|
1367 |
|
129
|
1368 |
!ByteArray methodsFor:'image manipulation support'!
|
1
|
1369 |
|
129
|
1370 |
compressPixels:nBitsPerPixel width:width height:height into:aByteArray
|
155
|
1371 |
mapping:aMapByteArray
|
129
|
1372 |
|
|
1373 |
"given the receiver with 8-bit pixels, compress them into aByteArray
|
|
1374 |
with nBitsPerPixel-depth pixels. The width/height-arguments are needed
|
|
1375 |
to allow for any padding. On the fly, the source bytes are translated
|
|
1376 |
using aMapByteArray (if non-nil).
|
|
1377 |
Notice that smalltalk indexing begins at 1; thus the map-index for a byte
|
|
1378 |
value of n is found in map at:(n + 1).
|
|
1379 |
Output bits are filled left-to right, i.e. the first byte in the input
|
|
1380 |
corresponds to the high bit(s) if the first byte in the input.
|
|
1381 |
This method can be used to convert 8-bit image data to mono, 2-bit and 4-bit
|
|
1382 |
bitmaps.
|
|
1383 |
It can also be used to compress byte-arrays into bitArrays."
|
|
1384 |
|
|
1385 |
%{ /* NOCONTEXT */
|
|
1386 |
|
|
1387 |
REGISTER unsigned char *src, *dst;
|
|
1388 |
REGISTER int wrun;
|
|
1389 |
unsigned char *dstNext;
|
|
1390 |
int bytesPerRow, mask, shift0, shift;
|
|
1391 |
int w, h, hrun;
|
|
1392 |
int srcBytes, dstBytes;
|
|
1393 |
int bitsPerPixel;
|
|
1394 |
int bits;
|
|
1395 |
int ncells;
|
|
1396 |
unsigned char *map;
|
|
1397 |
|
328
|
1398 |
if ((__qClass(self) == ByteArray)
|
|
1399 |
&& (__qClass(aByteArray) == ByteArray)
|
249
|
1400 |
&& __isSmallInteger(nBitsPerPixel)
|
|
1401 |
&& __bothSmallInteger(height, width)) {
|
155
|
1402 |
if ((aMapByteArray != nil)
|
328
|
1403 |
&& (__Class(aMapByteArray) == ByteArray)) {
|
155
|
1404 |
map = _ByteArrayInstPtr(aMapByteArray)->ba_element;
|
|
1405 |
} else {
|
|
1406 |
map = (unsigned char *)0;
|
|
1407 |
}
|
129
|
1408 |
|
155
|
1409 |
bitsPerPixel = _intVal(nBitsPerPixel);
|
|
1410 |
w = _intVal(width);
|
|
1411 |
h = _intVal(height);
|
|
1412 |
src = _ByteArrayInstPtr(self)->ba_element;
|
|
1413 |
dst = _ByteArrayInstPtr(aByteArray)->ba_element;
|
|
1414 |
switch (bitsPerPixel) {
|
|
1415 |
case 1:
|
|
1416 |
mask = 0x01;
|
|
1417 |
break;
|
|
1418 |
case 2:
|
|
1419 |
mask = 0x03;
|
|
1420 |
break;
|
|
1421 |
case 4:
|
|
1422 |
mask = 0x0F;
|
|
1423 |
break;
|
|
1424 |
case 8:
|
|
1425 |
mask = 0xFF;
|
|
1426 |
break;
|
|
1427 |
default:
|
|
1428 |
goto fail;
|
|
1429 |
}
|
|
1430 |
if (map) {
|
|
1431 |
/*
|
|
1432 |
* if a map is present, it must have entries for
|
|
1433 |
* all possible byte-values (i.e. its size must be >= 256)
|
|
1434 |
*/
|
328
|
1435 |
if ((__qSize(aMapByteArray) - OHDR_SIZE) < 256)
|
155
|
1436 |
goto fail;
|
|
1437 |
}
|
129
|
1438 |
|
155
|
1439 |
bytesPerRow = (w * bitsPerPixel + 7) / 8;
|
|
1440 |
dstBytes = bytesPerRow * h;
|
|
1441 |
srcBytes = w * h;
|
129
|
1442 |
|
249
|
1443 |
if ((__byteArraySize(self) >= srcBytes)
|
|
1444 |
&& (__byteArraySize(aByteArray) >= dstBytes)) {
|
155
|
1445 |
for (hrun=h; hrun; hrun--) {
|
|
1446 |
dstNext = dst + bytesPerRow;
|
|
1447 |
bits = 0; shift = 8;
|
|
1448 |
if (map) {
|
|
1449 |
for (wrun=w; wrun; wrun--) {
|
|
1450 |
bits = (bits << bitsPerPixel) | (map[*src++] & mask);
|
|
1451 |
shift -= bitsPerPixel;
|
|
1452 |
if (shift == 0) {
|
|
1453 |
*dst++ = bits;
|
|
1454 |
bits = 0; shift = 8;
|
|
1455 |
}
|
|
1456 |
}
|
|
1457 |
} else {
|
|
1458 |
for (wrun=w; wrun; wrun--) {
|
|
1459 |
bits = (bits << bitsPerPixel) | (*src++ & mask);
|
|
1460 |
shift -= bitsPerPixel;
|
|
1461 |
if (shift == 0) {
|
|
1462 |
*dst++ = bits;
|
|
1463 |
bits = 0; shift = 8;
|
|
1464 |
}
|
|
1465 |
}
|
|
1466 |
}
|
|
1467 |
if (shift != 8) {
|
|
1468 |
*dst = bits;
|
|
1469 |
}
|
|
1470 |
dst = dstNext;
|
|
1471 |
}
|
|
1472 |
RETURN ( self );
|
|
1473 |
}
|
129
|
1474 |
}
|
|
1475 |
fail: ;
|
|
1476 |
%}
|
|
1477 |
.
|
|
1478 |
self primitiveFailed
|
|
1479 |
|
|
1480 |
"Example1:
|
|
1481 |
compress 1 byte-per-pixel bitmap to 1-bit-per-pixel bitmap
|
|
1482 |
"
|
|
1483 |
"
|
|
1484 |
|inBits outBits|
|
|
1485 |
|
|
1486 |
inBits := #[0 0 0 0 1 1 1 1
|
155
|
1487 |
0 0 1 1 0 0 1 1
|
|
1488 |
0 1 0 1 0 1 0 1
|
|
1489 |
1 1 1 1 0 0 0 0].
|
129
|
1490 |
outBits := ByteArray new:4.
|
|
1491 |
inBits compressPixels:1 width:8 height:4
|
155
|
1492 |
into:outBits mapping:nil.
|
129
|
1493 |
outBits inspect
|
|
1494 |
"
|
|
1495 |
|
|
1496 |
"Example2:
|
|
1497 |
compress byte-array into a bitArray, translating 99 to 0-bits,
|
|
1498 |
and 176 to 1-bits. (just a stupid example)
|
|
1499 |
"
|
|
1500 |
"
|
|
1501 |
|inBits outBits map|
|
|
1502 |
|
|
1503 |
inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
|
|
1504 |
map := ByteArray new:256.
|
|
1505 |
map at:176+1 put:1.
|
|
1506 |
|
|
1507 |
outBits := ByteArray new:2.
|
|
1508 |
inBits compressPixels:1 width:16 height:1
|
155
|
1509 |
into:outBits mapping:map.
|
129
|
1510 |
outBits inspect
|
|
1511 |
"
|
|
1512 |
|
|
1513 |
"Example3:
|
|
1514 |
compress byte-array into a bitArray, translating everything below 128 to 0-bits,
|
|
1515 |
and 128 to 255 to 1-bits.99 to 0-bits (another stupid example)
|
|
1516 |
"
|
|
1517 |
"
|
|
1518 |
|inBits outBits map|
|
|
1519 |
|
|
1520 |
inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
|
|
1521 |
map := ByteArray new:256.
|
|
1522 |
map atAll:(128+1 to:255+1) put:1.
|
|
1523 |
|
|
1524 |
outBits := ByteArray new:2.
|
|
1525 |
inBits compressPixels:1 width:16 height:1
|
155
|
1526 |
into:outBits mapping:map.
|
129
|
1527 |
outBits inspect
|
|
1528 |
"
|
563
|
1529 |
!
|
|
1530 |
|
|
1531 |
expandPixels:nBitsPerPixel width:width height:height into:aByteArray
|
|
1532 |
mapping:aMapByteArray
|
|
1533 |
|
|
1534 |
"given the receiver with nBitsPerPixel-depth pixels, expand them into
|
|
1535 |
aByteArray with 8-bit pixels. The width/height-arguments are needed
|
|
1536 |
to skip any padded src-bits. On the fly, the destination pixels
|
|
1537 |
are translated using aMapByteArray (if non-nil).
|
|
1538 |
Input bits are read left-to right, i.e. the first byte in the output
|
|
1539 |
corresponds to the high bit(s) in the inputs first byte.
|
|
1540 |
This is used to display mono, 2-bit and 4-bit bitmaps on grey-scale/color
|
|
1541 |
machines. With nBitsPerPixel==8, this is a translate operation.
|
|
1542 |
Notice that smalltalk indexing begins at 1; thus the map-index for a byte
|
|
1543 |
value of n is found in map at:(n + 1).
|
|
1544 |
It can also be used to expand bit-arrays into byteArrays.
|
|
1545 |
This method is specialized for ByteArray arguments - it will not handle
|
|
1546 |
anything else."
|
|
1547 |
|
|
1548 |
%{ /* NOCONTEXT */
|
|
1549 |
|
|
1550 |
REGISTER unsigned char *src, *dst;
|
|
1551 |
REGISTER int wrun;
|
|
1552 |
unsigned char *srcNext;
|
|
1553 |
int bytesPerRow, mask, shift0, shift;
|
|
1554 |
int w, h, hrun;
|
|
1555 |
int srcBytes, dstBytes;
|
|
1556 |
int bitsPerPixel;
|
|
1557 |
int bits;
|
|
1558 |
int ncells;
|
|
1559 |
unsigned char *map;
|
|
1560 |
|
|
1561 |
if ((__qClass(self) == ByteArray)
|
|
1562 |
&& (__qClass(aByteArray) == ByteArray)
|
|
1563 |
&& __isSmallInteger(nBitsPerPixel)
|
|
1564 |
&& __bothSmallInteger(height, width)) {
|
|
1565 |
if ((aMapByteArray != nil)
|
|
1566 |
&& (__Class(aMapByteArray) == ByteArray)) {
|
|
1567 |
map = _ByteArrayInstPtr(aMapByteArray)->ba_element;
|
|
1568 |
} else {
|
|
1569 |
map = (unsigned char *)0;
|
|
1570 |
}
|
|
1571 |
|
|
1572 |
bitsPerPixel = _intVal(nBitsPerPixel);
|
|
1573 |
w = _intVal(width);
|
|
1574 |
h = _intVal(height);
|
|
1575 |
src = _ByteArrayInstPtr(self)->ba_element;
|
|
1576 |
dst = _ByteArrayInstPtr(aByteArray)->ba_element;
|
|
1577 |
switch (bitsPerPixel) {
|
|
1578 |
case 1:
|
|
1579 |
mask = 0x01;
|
|
1580 |
break;
|
|
1581 |
case 2:
|
|
1582 |
mask = 0x03;
|
|
1583 |
break;
|
|
1584 |
case 4:
|
|
1585 |
mask = 0x0F;
|
|
1586 |
break;
|
|
1587 |
case 8:
|
|
1588 |
mask = 0xFF;
|
|
1589 |
break;
|
|
1590 |
default:
|
|
1591 |
goto fail;
|
|
1592 |
}
|
|
1593 |
ncells = mask + 1;
|
|
1594 |
if (map) {
|
|
1595 |
/*
|
|
1596 |
* if a map is present, it must have the correct size
|
|
1597 |
* (i.e. 2 raisedTo:nBitsPerPixel)
|
|
1598 |
*/
|
|
1599 |
if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells)
|
|
1600 |
goto fail;
|
|
1601 |
}
|
|
1602 |
|
|
1603 |
bytesPerRow = (w * bitsPerPixel + 7) / 8;
|
|
1604 |
shift0 = 8 - bitsPerPixel;
|
|
1605 |
srcBytes = bytesPerRow * h;
|
|
1606 |
dstBytes = w * h;
|
|
1607 |
|
|
1608 |
if ((__byteArraySize(self) >= srcBytes)
|
|
1609 |
&& (__byteArraySize(aByteArray) >= dstBytes)) {
|
|
1610 |
for (hrun=h; hrun; hrun--) {
|
|
1611 |
srcNext = src + bytesPerRow;
|
|
1612 |
shift = shift0;
|
|
1613 |
if (map) {
|
|
1614 |
for (wrun=w; wrun; wrun--) {
|
|
1615 |
if (shift == shift0) {
|
|
1616 |
bits = *src++;
|
|
1617 |
}
|
|
1618 |
*dst++ = map[(bits >> shift) & mask];
|
|
1619 |
shift -= bitsPerPixel;
|
|
1620 |
if (shift < 0) {
|
|
1621 |
shift = shift0;
|
|
1622 |
}
|
|
1623 |
}
|
|
1624 |
} else {
|
|
1625 |
for (wrun=w; wrun; wrun--) {
|
|
1626 |
if (shift == shift0) {
|
|
1627 |
bits = *src++;
|
|
1628 |
}
|
|
1629 |
*dst++ = (bits >> shift) & mask;
|
|
1630 |
shift -= bitsPerPixel;
|
|
1631 |
if (shift < 0) {
|
|
1632 |
shift = shift0;
|
|
1633 |
}
|
|
1634 |
}
|
|
1635 |
}
|
|
1636 |
src = srcNext;
|
|
1637 |
}
|
|
1638 |
RETURN ( self );
|
|
1639 |
}
|
|
1640 |
}
|
|
1641 |
fail: ;
|
|
1642 |
%}
|
|
1643 |
.
|
|
1644 |
self primitiveFailed
|
|
1645 |
|
|
1646 |
"Example1:
|
|
1647 |
expand 1-bit-per-pixel bitmap into a 1byte-per-pixel byteArray
|
|
1648 |
"
|
|
1649 |
"
|
|
1650 |
|inBits outBits|
|
|
1651 |
|
|
1652 |
inBits := #[2r11110000
|
|
1653 |
2r11001100
|
|
1654 |
2r01010101
|
|
1655 |
2r00001111].
|
|
1656 |
outBits := ByteArray new:(8*4).
|
|
1657 |
inBits expandPixels:1 width:8 height:4
|
|
1658 |
into:outBits mapping:nil.
|
|
1659 |
outBits inspect
|
|
1660 |
"
|
|
1661 |
|
|
1662 |
"Example2:
|
|
1663 |
expand bit-array into a byteArray, translating 0-bits to 99,
|
|
1664 |
1-bits to 176. (just a stupid example)
|
|
1665 |
"
|
|
1666 |
"
|
|
1667 |
|inBits outBits|
|
|
1668 |
|
|
1669 |
inBits := #[2r11110000 2r11001100].
|
|
1670 |
outBits := ByteArray new:16.
|
|
1671 |
inBits expandPixels:1 width:16 height:1
|
|
1672 |
into:outBits mapping:#[99 176].
|
|
1673 |
outBits inspect
|
|
1674 |
"
|
|
1675 |
!
|
|
1676 |
|
|
1677 |
invert
|
|
1678 |
"invert all bytes - used with image manipulations
|
|
1679 |
written as a primitive for speed.
|
|
1680 |
Q: is this really needed ?"
|
|
1681 |
|
|
1682 |
%{ /* NOCONTEXT */
|
|
1683 |
|
|
1684 |
REGISTER unsigned char *dst;
|
|
1685 |
REGISTER unsigned long *ldst;
|
|
1686 |
REGISTER int cnt;
|
|
1687 |
|
|
1688 |
if (__qClass(self) == ByteArray) {
|
|
1689 |
cnt = __byteArraySize(self);
|
|
1690 |
dst = _ByteArrayInstPtr(self)->ba_element;
|
|
1691 |
if (! ((int)dst & (sizeof(long)-1))) {
|
|
1692 |
ldst = (unsigned long *)dst;
|
|
1693 |
while (cnt >= sizeof(long)) {
|
|
1694 |
*ldst = ~(*ldst);
|
|
1695 |
ldst++;
|
|
1696 |
cnt -= sizeof(long);
|
|
1697 |
}
|
|
1698 |
dst = (unsigned char *)ldst;
|
|
1699 |
}
|
|
1700 |
while (cnt--) {
|
|
1701 |
*dst = ~(*dst);
|
|
1702 |
dst++;
|
|
1703 |
}
|
|
1704 |
RETURN ( self );
|
|
1705 |
}
|
|
1706 |
%}
|
|
1707 |
.
|
|
1708 |
self primitiveFailed
|
|
1709 |
!
|
|
1710 |
|
|
1711 |
reverse
|
|
1712 |
"reverse order of elements inplace -
|
|
1713 |
written as a primitive for speed on image manipulations (mirror)"
|
|
1714 |
|
|
1715 |
%{ /* NOCONTEXT */
|
|
1716 |
|
|
1717 |
REGISTER unsigned char *p1, *p2;
|
|
1718 |
REGISTER int cnt;
|
|
1719 |
REGISTER unsigned t;
|
|
1720 |
OBJ cls;
|
|
1721 |
|
|
1722 |
if (__qClass(self) == ByteArray) {
|
|
1723 |
cnt = __byteArraySize(self);
|
|
1724 |
p1 = _ByteArrayInstPtr(self)->ba_element;
|
|
1725 |
p2 = p1 + cnt - 1;
|
|
1726 |
while (cnt > 0) {
|
|
1727 |
t = *p1;
|
|
1728 |
*p1++ = *p2;
|
|
1729 |
*p2-- = t;
|
|
1730 |
cnt-=2;
|
|
1731 |
}
|
|
1732 |
RETURN ( self );
|
|
1733 |
}
|
|
1734 |
%}.
|
|
1735 |
^ super reverse
|
1
|
1736 |
! !
|
550
|
1737 |
|
|
1738 |
!ByteArray methodsFor:'printing & storing'!
|
|
1739 |
|
|
1740 |
asPackedString
|
|
1741 |
"ST-80 compatibility: encode the receiver into an ascii String
|
|
1742 |
with 6bits encoded per character. Each group of 6 bits is encoded
|
|
1743 |
as a corresponding character (32+value) and the resulting string
|
|
1744 |
is returned. The resulting string is always a multiple of 4 (since
|
|
1745 |
24 is the lcm of 6 and 8) and the number of remaining characters is
|
|
1746 |
encoded in the last character.
|
|
1747 |
ST-80 uses this encoding for Images ...
|
|
1748 |
PS: I dont like it ;-)"
|
|
1749 |
|
|
1750 |
|outStream
|
|
1751 |
index "{ Class:SmallInteger}"
|
|
1752 |
stop "{ Class:SmallInteger}"
|
|
1753 |
n "{ Class:SmallInteger}"|
|
|
1754 |
|
|
1755 |
outStream := WriteStream on:String new.
|
|
1756 |
index := 1.
|
|
1757 |
stop := self size.
|
|
1758 |
[index <= stop] whileTrue:[
|
|
1759 |
"take 3 source bytes"
|
|
1760 |
n := (self at:index) bitShift:16.
|
|
1761 |
(index < stop) ifTrue:[
|
|
1762 |
n := n bitOr:((self at:(index + 1)) bitShift:8).
|
|
1763 |
(index + 1 < stop) ifTrue:[
|
|
1764 |
n := n bitOr:(self at:(index + 2)).
|
|
1765 |
].
|
|
1766 |
].
|
|
1767 |
|
|
1768 |
"took me a while to find that one out ..."
|
|
1769 |
n := n bitXor:16r820820.
|
|
1770 |
|
|
1771 |
outStream nextPut:(Character value:(n bitShift:-18) + 32).
|
|
1772 |
outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
|
|
1773 |
outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
|
|
1774 |
outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
|
|
1775 |
index := index + 3.
|
|
1776 |
].
|
|
1777 |
stop \\ 3 ~~ 0 ifTrue:[
|
|
1778 |
outStream position:(outStream position - 1).
|
|
1779 |
outStream nextPut:(Character value:(stop \\ 3 + 96)).
|
|
1780 |
].
|
|
1781 |
^ outStream contents
|
563
|
1782 |
!
|
|
1783 |
|
|
1784 |
displayString
|
|
1785 |
^ self storeString
|
|
1786 |
|
|
1787 |
"Created: 25.10.1995 / 13:33:26 / cg"
|
|
1788 |
!
|
|
1789 |
|
|
1790 |
isLiteral
|
|
1791 |
"return true, if the receiver can be used as a literal
|
|
1792 |
(i.e. can be used in constant arrays)"
|
|
1793 |
|
|
1794 |
"no, simply returning true here is a mistake:
|
|
1795 |
it could be a subclass of ByteArray
|
|
1796 |
(of which the compiler does not know at all ...)"
|
|
1797 |
|
|
1798 |
^ self class == ByteArray
|
|
1799 |
!
|
|
1800 |
|
|
1801 |
storeOn:aStream
|
|
1802 |
"append a printed representation from which the receiver can be
|
|
1803 |
reconstructed to aStream. (reimplemented to make it look better)"
|
|
1804 |
|
|
1805 |
|first|
|
|
1806 |
|
|
1807 |
self class == ByteArray ifTrue:[
|
|
1808 |
aStream nextPutAll:'#['.
|
|
1809 |
first := true.
|
|
1810 |
self do:[:byte |
|
|
1811 |
first ifFalse:[aStream space]
|
|
1812 |
ifTrue:[first := false].
|
|
1813 |
byte storeOn:aStream.
|
|
1814 |
].
|
|
1815 |
aStream nextPutAll:']'.
|
|
1816 |
^ self
|
|
1817 |
].
|
|
1818 |
^ super storeOn:aStream
|
|
1819 |
|
|
1820 |
"
|
|
1821 |
#[1 2 3 4 5] storeOn:Transcript
|
|
1822 |
"
|
550
|
1823 |
! !
|
|
1824 |
|
|
1825 |
!ByteArray methodsFor:'queries'!
|
|
1826 |
|
|
1827 |
indexOf:aByte startingAt:start
|
|
1828 |
"return the index of the first occurrence of the argument, aByte
|
|
1829 |
in the receiver starting at start, anInteger; return 0 if not found.
|
|
1830 |
- reimplemented here for speed"
|
|
1831 |
|
|
1832 |
%{ /* NOCONTEXT */
|
|
1833 |
|
|
1834 |
REGISTER unsigned char *cp;
|
|
1835 |
REGISTER int index, byteValue;
|
|
1836 |
REGISTER int len;
|
|
1837 |
OBJ cls;
|
|
1838 |
|
|
1839 |
if (__isSmallInteger(aByte)) {
|
|
1840 |
byteValue = _intVal(aByte);
|
|
1841 |
|
|
1842 |
if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
|
|
1843 |
/*
|
|
1844 |
* searching for something which cannot be found
|
|
1845 |
*/
|
|
1846 |
RETURN ( _MKSMALLINT(0) );
|
|
1847 |
}
|
|
1848 |
|
|
1849 |
if (__isSmallInteger(start)) {
|
|
1850 |
index = _intVal(start);
|
|
1851 |
len = __byteArraySize(self);
|
|
1852 |
cp = _ByteArrayInstPtr(self)->ba_element;
|
|
1853 |
if ((cls = __qClass(self)) != ByteArray) {
|
|
1854 |
int nInst;
|
|
1855 |
|
|
1856 |
nInst = __OBJS2BYTES__(_intVal(_ClassInstPtr(cls)->c_ninstvars));
|
|
1857 |
cp += nInst;
|
|
1858 |
len -= nInst;
|
|
1859 |
}
|
|
1860 |
cp += index - 1;
|
|
1861 |
while (index <= len) {
|
|
1862 |
if (*cp == byteValue) {
|
|
1863 |
RETURN ( _MKSMALLINT(index) );
|
|
1864 |
}
|
|
1865 |
index++;
|
|
1866 |
cp++;
|
|
1867 |
}
|
|
1868 |
RETURN ( _MKSMALLINT(0) );
|
|
1869 |
}
|
|
1870 |
}
|
|
1871 |
%}.
|
|
1872 |
^ super indexOf:aByte startingAt:start
|
|
1873 |
|
|
1874 |
"
|
|
1875 |
#[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0
|
|
1876 |
"
|
|
1877 |
!
|
|
1878 |
|
563
|
1879 |
max
|
|
1880 |
"return the maximum value in the receiver -
|
|
1881 |
redefined to speedup image processing and sound-player
|
|
1882 |
(which need a fast method for this on byteArrays)"
|
550
|
1883 |
|
563
|
1884 |
%{ /* NOCONTEXT */
|
550
|
1885 |
|
|
1886 |
REGISTER unsigned char *cp;
|
563
|
1887 |
REGISTER int index, max;
|
|
1888 |
int len;
|
550
|
1889 |
|
|
1890 |
if (__qClass(self) == ByteArray) {
|
563
|
1891 |
max = 0;
|
|
1892 |
index = 0;
|
550
|
1893 |
len = __qSize(self) - OHDR_SIZE;
|
|
1894 |
cp = &(_ByteArrayInstPtr(self)->ba_element[0]);
|
563
|
1895 |
while (++index <= len) {
|
|
1896 |
if (*cp > max) max = *cp;
|
550
|
1897 |
cp++;
|
|
1898 |
}
|
563
|
1899 |
RETURN ( _MKSMALLINT(max) );
|
550
|
1900 |
}
|
563
|
1901 |
%}.
|
|
1902 |
^ super max
|
550
|
1903 |
|
|
1904 |
"
|
563
|
1905 |
#[1 2 3 1 2 3 1 2 19] max
|
550
|
1906 |
"
|
|
1907 |
!
|
|
1908 |
|
|
1909 |
usageCounts
|
|
1910 |
"return an array filled with value-counts -
|
|
1911 |
This is needed in the bitmap/image classes to get info on color usage.
|
|
1912 |
(i.e. to build up a histogram of color usage within an image)."
|
|
1913 |
|
|
1914 |
|counts|
|
|
1915 |
|
|
1916 |
counts := Array basicNew:256.
|
|
1917 |
|
|
1918 |
%{ /* STACK: 2000 */
|
|
1919 |
|
|
1920 |
REGISTER unsigned char *cp;
|
|
1921 |
REGISTER int nByte;
|
|
1922 |
REGISTER int index;
|
|
1923 |
int icounts[256];
|
|
1924 |
|
|
1925 |
if ((__qClass(self) == ByteArray) && __isArray(counts)) {
|
|
1926 |
/*
|
|
1927 |
* zero counts
|
|
1928 |
*/
|
|
1929 |
for (index=0; index<256; index++) {
|
|
1930 |
icounts[index] = 0;
|
|
1931 |
}
|
|
1932 |
|
|
1933 |
/*
|
|
1934 |
* count
|
|
1935 |
*/
|
|
1936 |
nByte = __qSize(self) - OHDR_SIZE;
|
|
1937 |
cp = &(_ByteArrayInstPtr(self)->ba_element[0]);
|
|
1938 |
while (nByte--) {
|
|
1939 |
icounts[*cp++]++;
|
|
1940 |
}
|
|
1941 |
|
|
1942 |
/*
|
|
1943 |
* make it real counts
|
|
1944 |
*/
|
|
1945 |
for (index=0; index<256; index++) {
|
|
1946 |
_ArrayInstPtr(counts)->a_element[index] = _MKSMALLINT(icounts[index]);
|
|
1947 |
}
|
|
1948 |
RETURN ( counts );
|
|
1949 |
}
|
|
1950 |
%}
|
|
1951 |
.
|
|
1952 |
self primitiveFailed
|
|
1953 |
|
|
1954 |
"
|
|
1955 |
#[1 2 3 1 2 3 1 2 250 251 250 251 255] usageCounts
|
|
1956 |
"
|
|
1957 |
!
|
|
1958 |
|
563
|
1959 |
usedValues
|
|
1960 |
"return a new ByteArray with all used values (actually a kind of Set);
|
|
1961 |
This is needed specially in the bitmap/Imageclasses to find used colors
|
|
1962 |
in an image."
|
550
|
1963 |
|
563
|
1964 |
|result l|
|
|
1965 |
|
|
1966 |
%{ /* STACK: 400 */
|
550
|
1967 |
|
|
1968 |
REGISTER unsigned char *cp;
|
563
|
1969 |
REGISTER int len;
|
|
1970 |
unsigned char flags[256];
|
|
1971 |
static struct inlineCache nw = _ILC1;
|
|
1972 |
extern OBJ ByteArray;
|
550
|
1973 |
|
|
1974 |
if (__qClass(self) == ByteArray) {
|
563
|
1975 |
memset(flags, 0, sizeof(flags));
|
550
|
1976 |
len = __qSize(self) - OHDR_SIZE;
|
|
1977 |
cp = &(_ByteArrayInstPtr(self)->ba_element[0]);
|
563
|
1978 |
|
|
1979 |
/* for each used byte, set flag */
|
|
1980 |
while (len > 0) {
|
|
1981 |
flags[*cp] = 1;
|
550
|
1982 |
cp++;
|
563
|
1983 |
len--;
|
550
|
1984 |
}
|
563
|
1985 |
/* count 1's */
|
|
1986 |
len = 0;
|
|
1987 |
for (cp=flags+255; cp >= flags; cp--)
|
|
1988 |
if (*cp) len++;
|
|
1989 |
|
|
1990 |
/* create ByteArray of used values */
|
|
1991 |
result = (*nw.ilc_func)(ByteArray,
|
|
1992 |
@symbol(new:),
|
|
1993 |
CON_COMMA nil, &nw,
|
|
1994 |
_MKSMALLINT(len));
|
|
1995 |
if (__Class(result) == ByteArray) {
|
|
1996 |
cp = &(_ByteArrayInstPtr(result)->ba_element[0]);
|
|
1997 |
for (len=0; len < 256; len++) {
|
|
1998 |
if (flags[len])
|
|
1999 |
*cp++ = len;
|
|
2000 |
}
|
|
2001 |
}
|
|
2002 |
RETURN ( result );
|
550
|
2003 |
}
|
563
|
2004 |
%}
|
|
2005 |
.
|
|
2006 |
^ self asSet
|
550
|
2007 |
|
|
2008 |
"
|
563
|
2009 |
#[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues
|
550
|
2010 |
"
|
|
2011 |
! !
|
|
2012 |
|