ByteArray.st
author Stefan Vogel <sv@exept.de>
Mon, 12 Aug 2013 12:09:48 +0200
changeset 15625 090e438cffe5
parent 15330 6e9281a08730
child 16620 9db0a09c71c0
child 18084 ab5b38bd8f81
permissions -rw-r--r--
class: ByteArray changed: #bitXor:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5425
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
    12
"{ Package: 'stx:libbasic' }"
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
    13
3208
2d71538b9fd5 now subclass of UIBytes - which contains common protocol
Claus Gittinger <cg@exept.de>
parents: 3205
diff changeset
    14
UninterpretedBytes variableByteSubclass:#ByteArray
1002
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    15
	instanceVariableNames:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    16
	classVariableNames:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    17
	poolDictionaries:''
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
    18
	category:'Collections-Arrayed'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
    21
!ByteArray class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    23
copyright
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    24
"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    26
	      All Rights Reserved
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    27
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    28
 This software is furnished under a license and may be used
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    29
 only in accordance with the terms of that license and with the
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    31
 be provided or otherwise made available to, or used by, any
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    32
 other person.  No title to or ownership of the software is
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    33
 hereby transferred.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    34
"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    35
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    36
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
    ByteArrays store integers in the range 0..255.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    40
    In contrast to normal arrays (which store pointers to their elements),
362
claus
parents: 359
diff changeset
    41
    byteArrays store the values in a dense & compact way. ByteArrays can
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    42
    be used to hold the data for bitmaps, images and other bulk data.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    43
    ByteArrays are also used to store the bytecode-instructions of an
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    44
    interpreted method and are used as superclass for Strings.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    45
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    46
    ByteArrays can be used as literals i.e. you can enter ByteArray-constants
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    47
    as #[ element1 element2 .... elementN] and also use byteArray constants
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    48
    as elements in a constant array.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    49
    As in: #( #[1 1 1] #[2 2 2] #[3 3 3])
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    50
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    51
    If you have to communicate structure-data (in the C-sense) with external
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    52
    programs/data-bases, see a companion class (Structure) in the goodies directory.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    53
    It allows the definition of subclasses of ByteArray, which transparently fetch
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
    54
    and store C-structure fields.
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    55
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
    56
    [memory requirements:]
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
    57
	OBJ-HEADER + size
4062
4959de96b06f documentation
Claus Gittinger <cg@exept.de>
parents: 4050
diff changeset
    58
2145
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1974
diff changeset
    59
    [warning:]
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
    60
	read the warning about 'growing fixed size collection'
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
    61
	in ArrayedCollection's documentation
2145
d243ffafeae3 more docu
Claus Gittinger <cg@exept.de>
parents: 1974
diff changeset
    62
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
    63
    [author:]
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
    64
	Claus Gittinger
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
    65
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
    66
    [See also:]
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
    67
	Array CharacterArray String
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    68
"
2
claus
parents: 1
diff changeset
    69
! !
claus
parents: 1
diff changeset
    70
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
    71
!ByteArray class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
uninitializedNew:anInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
    "return a new instance of the receiver with uninitialized
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
     (i.e. undefined) contents. The indexed elements have any random
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    76
     value. However, any named instance variables are still nilled.
75
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    77
     For use, when contents will be set anyway shortly after - this
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    78
     is a bit faster than the regular basicNew:, which clears the bytes.
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    79
     Of course, it only makes a difference for very big ByteArrays, such
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    80
     as used for images/bitmaps.
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    81
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    82
     Notice: if you want to port code using uninitializedNew: to another
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    83
     smalltalk, you have to add an 'uninitializedNew: -> basicNew:'-calling
75
2c61e28412de *** empty log message ***
claus
parents: 68
diff changeset
    84
     method to the ByteArray class of the other smalltalk."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
a27a279701f8 Initial revision
claus
parents:
diff changeset
    86
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
    87
    OBJ newobj;
a27a279701f8 Initial revision
claus
parents:
diff changeset
    88
    INT instsize, nInstVars, nindexedinstvars;
a27a279701f8 Initial revision
claus
parents:
diff changeset
    89
    REGISTER OBJ *op;
a27a279701f8 Initial revision
claus
parents:
diff changeset
    90
249
claus
parents: 221
diff changeset
    91
    if (__isSmallInteger(anInteger)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    92
	nindexedinstvars = __intVal(anInteger);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    93
	if (nindexedinstvars >= 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    94
	    if (self == ByteArray) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    95
		/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    96
		 * the most common case
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    97
		 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    98
		instsize = OHDR_SIZE + nindexedinstvars;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    99
		if (__CanDoQuickNew(instsize)) {        /* OBJECT ALLOCATION */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   100
		    __qCheckedNew(newobj, instsize);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   101
		    __InstPtr(newobj)->o_class = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   102
		    __qSTORE(newobj, self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   103
		    RETURN (newobj );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   104
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   105
	    } else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   106
		/*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   107
		 * Take care for subclasses like TwoByteString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   108
		 */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   109
		switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   110
		case BYTEARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   111
		    break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   112
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   113
		case WORDARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   114
		case SWORDARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   115
		    nindexedinstvars *= 2;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   116
		    break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   117
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   118
		case LONGARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   119
		case SLONGARRAY:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   120
		    nindexedinstvars *= 4;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   121
		    break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   122
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   123
		default:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   124
		    /* don't know about this array type, delegate to super */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   125
		    goto out;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   126
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   127
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   128
	    nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   129
	    instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   130
	    __PROTECT_CONTEXT__
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   131
	    __qNew(newobj, instsize);   /* OBJECT ALLOCATION */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   132
	    __UNPROTECT_CONTEXT__
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   133
	    if (newobj != nil) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   134
		__InstPtr(newobj)->o_class = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   135
		__qSTORE(newobj, self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   136
		if (nInstVars) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   137
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   138
		     * still have to nil out named instvars ...
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   139
		     */
788
e80f1c42b87b dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents: 628
diff changeset
   140
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   141
		    memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
#else
249
claus
parents: 221
diff changeset
   143
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   144
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   145
		     * knowing that nil is 0
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   146
		     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   147
		    memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
249
claus
parents: 221
diff changeset
   148
# else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   149
		    op = __InstPtr(newobj)->i_instvars;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   150
		    while (nInstVars--)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   151
			*op++ = nil;
249
claus
parents: 221
diff changeset
   152
# endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   154
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   155
		RETURN ( newobj );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   156
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   157
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
    }
8159
ac6725a62e17 #uninitializedNew: - take care of WORDARRAYS etc.
Stefan Vogel <sv@exept.de>
parents: 8096
diff changeset
   159
out:;
5425
9a2bb3d1cc82 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5355
diff changeset
   160
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   161
    ^ self basicNew:anInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
11502
64d1cb6c2062 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11265
diff changeset
   164
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
   165
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
   166
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
   167
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
   168
!ByteArray class methodsFor:'queries'!
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   169
13706
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   170
elementByteSize
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   171
    ^ 1
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   172
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   173
    "Created: / 15-09-2011 / 14:12:53 / cg"
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   174
!
62f6489aa2c6 faster elementByteSize query
Claus Gittinger <cg@exept.de>
parents: 13703
diff changeset
   175
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   176
isBuiltInClass
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   177
    "return true if this class is known by the run-time-system.
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   178
     Here, true is returned for myself, false for subclasses."
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   179
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   180
    ^ self == ByteArray
1266
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   181
cef9b3cd49df commentary
Claus Gittinger <cg@exept.de>
parents: 1261
diff changeset
   182
    "Modified: 23.4.1996 / 15:56:25 / cg"
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   183
! !
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   184
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
   185
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
   186
10884
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   187
!ByteArray methodsFor:'Compatibility-Squeak'!
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   188
12144
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   189
bitXor:aByteArray
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   190
    "return a new byteArray containing the bitWise-xor of the receiver's and the
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   191
     argument's bytes"
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   192
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   193
    |size size1|
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   194
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   195
    "size := self size min:aByteArray size"
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   196
    size := self size.
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   197
    size1 := aByteArray size.
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   198
    size1 < size ifTrue:[
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   199
        size := size1.
12144
cc0d6bd13d68 added: #bitXor:
Claus Gittinger <cg@exept.de>
parents: 12091
diff changeset
   200
    ].
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   201
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   202
    ^ self copy
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   203
        bitXorBytesFrom:1 to:size with:aByteArray startingAt:1;
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   204
        yourself.
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   205
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   206
    "
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   207
        #[0 1 2 3 4] bitXor:#[0 1 2 3 4]
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   208
        #[0 1 2 3 4] bitXor:#[0 1 2 3]
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
   209
    "
10884
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   210
! !
36e93aa5e790 +copyfromByteArray:
Claus Gittinger <cg@exept.de>
parents: 10821
diff changeset
   211
12091
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
   212
!ByteArray methodsFor:'Compatibility-VW'!
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
   213
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
   214
asByteString
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
   215
    ^ self asString
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
   216
! !
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
   217
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   218
!ByteArray methodsFor:'accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   219
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   220
basicAt:index
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   221
    "return the indexed instance variable with index, anInteger
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   222
     - redefined here to be slighly faster than the default in Object.
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   223
     Q: is it worth the extra code ?"
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   224
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   225
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   226
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   227
    REGISTER int indx;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   228
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   229
    REGISTER OBJ cls;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   230
    REGISTER int nIndex;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   231
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   232
    if (__isSmallInteger(index)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   233
	indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   234
	slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   235
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   236
	    if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   237
		!= __MASKSMALLINT(BYTEARRAY)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   238
		goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   239
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   240
	    if (indx < 0) goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   241
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   242
	}
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   243
	nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   244
	if ((unsigned)indx < (unsigned)nIndex) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   245
	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   246
	}
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   247
    }
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   248
  fail: ;
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   249
%}.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   250
    ^ super basicAt:index
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   251
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   252
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
basicAt:index put:value
1230
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   254
    "set the indexed instance variable with index, anInteger to value.
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   255
     Returns value (sigh).
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   256
     - redefined here to be slighly faster than the default in Object.
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   257
     Q: is it worth the extra code ?"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   258
a27a279701f8 Initial revision
claus
parents:
diff changeset
   259
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   260
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
    REGISTER int indx;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   262
    int nIndex;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
    int val;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   264
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   265
    REGISTER OBJ cls;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
249
claus
parents: 221
diff changeset
   267
    if (__bothSmallInteger(index, value)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   268
	val = __intVal(value);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   269
	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   270
	    indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   271
	    slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   272
	    if ((cls = __qClass(slf)) != @global(ByteArray)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   273
		if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   274
		    != __MASKSMALLINT(BYTEARRAY)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   275
		    goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   276
		}
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   277
		if (indx < 0) goto fail;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   278
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   279
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   280
	    nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   281
	    if ((unsigned)indx < (unsigned)nIndex) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   282
		__ByteArrayInstPtr(slf)->ba_element[indx] = val;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   283
		RETURN ( value );
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   284
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   285
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   286
    }
1019
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   287
  fail: ;
db8afc103e37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1002
diff changeset
   288
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
    ^ super basicAt:index put:value
1230
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   290
c349c4e9e594 commentary
Claus Gittinger <cg@exept.de>
parents: 1213
diff changeset
   291
    "Modified: 19.4.1996 / 11:14:40 / cg"
2
claus
parents: 1
diff changeset
   292
!
claus
parents: 1
diff changeset
   293
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   294
bitAt:index
11502
64d1cb6c2062 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11265
diff changeset
   295
    "return the bit at index (1 based index) as 0 or 1"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   296
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   297
    |byteIndex bitIndex0 byte|
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   298
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   299
%{  /* NOCONTEXT */
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   300
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   301
    REGISTER int indx;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   302
    REGISTER int byte;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   303
    int nIndex;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   304
    REGISTER OBJ slf;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   305
    REGISTER OBJ cls;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   306
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   307
    if (__isSmallInteger(index)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   308
	indx = __intVal(index) - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   309
	slf = self;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   310
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   311
	byte = indx / 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   312
	indx = indx % 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   313
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   314
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   315
	    if (indx < 0) goto badIndex;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   316
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   317
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   318
	nIndex = __byteArraySize(slf);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   319
	if ((unsigned)byte < (unsigned)nIndex) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   320
	    RETURN ( __mkSmallInteger(((__ByteArrayInstPtr(slf)->ba_element[byte] & (1 << indx)) != 0)) );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   321
	}
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   322
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   323
badIndex: ;
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   324
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   325
    byteIndex := ((index-1) // 8) + 1.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   326
    bitIndex0 := ((index-1) \\ 8).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   327
    byte := self at:byteIndex.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   328
    ^  byte bitTest:(1 bitShift:bitIndex0).
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   329
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   330
   "
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   331
     #[ 1 1 1 1 ] bitAt:9
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   332
     #[ 1 1 1 1 ] bitAt:11
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   333
     #[ 2 2 2 2 ] bitAt:10
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   334
   "
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   335
!
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   336
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   337
bitClearAt:index
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   338
    "clear the bit at index (index starts with 1)"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   339
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   340
    |byteIndex bitIndex0 byte|
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   341
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   342
%{  /* NOCONTEXT */
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   343
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   344
    REGISTER int indx;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   345
    REGISTER int byte;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   346
    int nIndex;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   347
    REGISTER OBJ slf;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   348
    REGISTER OBJ cls;
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   349
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   350
    if (0 /* __isSmallInteger(index) */) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   351
	indx = __intVal(index) - 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   352
	slf = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   353
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   354
	byte = indx / 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   355
	indx = indx % 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   356
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   357
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   358
	    if (indx < 0) goto badIndex;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   359
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   360
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   361
	nIndex = __byteArraySize(slf);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   362
	if ((unsigned)byte < (unsigned)nIndex) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   363
	    __ByteArrayInstPtr(slf)->ba_element[byte] &= ~(1 << indx);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   364
	    RETURN (slf);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   365
	}
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   366
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   367
badIndex: ;
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   368
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   369
    byteIndex := ((index-1) // 8) + 1.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   370
    bitIndex0 := ((index-1) \\ 8).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   371
    byte := self at:byteIndex.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   372
    byte := byte bitClear:(1 bitShift:bitIndex0).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   373
    self at:byteIndex put:byte.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   374
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   375
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   376
     #[0 0 0 0] copy bitClearAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   377
     #[0 0 0 0] copy bitClearAt:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   378
     #[0 0 0 0] copy bitClearAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   379
     #[0 0 0 0] copy bitClearAt:9
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   380
    "
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   381
   "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   382
     #[ 0 0 0 0 ] bitSetAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   383
     #[ 0 0 0 0 ] bitSetAt:4
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   384
     #[ 0 0 0 0 ] bitSetAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   385
     #[ 0 0 0 0 ] bitSetAt:9
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   386
     #[ 0 0 0 0 ] bitSetAt:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   387
     #[ 0 0 0 0 ] bitSetAt:11
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   388
   "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   389
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   390
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   391
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   392
!
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   393
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   394
bitSetAt:index
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   395
    "set the bit at index (index starts with 1)"
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   396
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   397
    |byteIndex bitIndex0 byte|
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   398
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   399
%{  /* NOCONTEXT */
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   400
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   401
    REGISTER int indx;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   402
    REGISTER int byte;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   403
    int nIndex;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   404
    REGISTER OBJ slf;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   405
    REGISTER OBJ cls;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   406
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   407
    if (0 /* __isSmallInteger(index) */) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   408
	indx = __intVal(index) - 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   409
	slf = self;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   410
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   411
	byte = indx / 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   412
	indx = indx % 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   413
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   414
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   415
	    if (indx < 0) goto badIndex;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   416
	    byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   417
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   418
	nIndex = __byteArraySize(slf);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   419
	if ((unsigned)byte < (unsigned)nIndex) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   420
	    __ByteArrayInstPtr(slf)->ba_element[byte] |= (1 << indx);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   421
	    RETURN (slf);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   422
	}
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   423
    }
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   424
badIndex: ;
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   425
%}.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   426
    byteIndex := ((index-1) // 8) + 1.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   427
    bitIndex0 := ((index-1) \\ 8).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   428
    byte := self at:byteIndex.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   429
    byte := byte bitOr:(1 bitShift:bitIndex0).
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   430
    self at:byteIndex put:byte.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   431
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   432
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   433
     #[0 0 0 0] copy bitSetAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   434
     #[0 0 0 0] copy bitSetAt:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   435
     #[0 0 0 0] copy bitSetAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   436
     #[0 0 0 0] copy bitSetAt:9
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   437
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   438
   "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   439
     #[ 0 0 0 0 ] bitSetAt:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   440
     #[ 0 0 0 0 ] bitSetAt:4
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   441
     #[ 0 0 0 0 ] bitSetAt:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   442
     #[ 0 0 0 0 ] bitSetAt:9
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   443
     #[ 0 0 0 0 ] bitSetAt:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   444
     #[ 0 0 0 0 ] bitSetAt:11
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   445
   "
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   446
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   447
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   448
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   449
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   450
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   451
!ByteArray methodsFor:'accessing-bytes'!
4128
05106536fc3a New: #bitAt: and #bitSetAt:
Stefan Vogel <sv@exept.de>
parents: 4087
diff changeset
   452
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   453
byteAt:index
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   454
    "return the byte at index.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   455
     For ByteArray, this is the same as basicAt:;
249
claus
parents: 221
diff changeset
   456
     however, for strings or symbols, this returns a numeric byteValue
claus
parents: 221
diff changeset
   457
     instead of a character."
claus
parents: 221
diff changeset
   458
claus
parents: 221
diff changeset
   459
%{  /* NOCONTEXT */
claus
parents: 221
diff changeset
   460
claus
parents: 221
diff changeset
   461
    REGISTER int indx;
claus
parents: 221
diff changeset
   462
    int nIndex;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   463
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   464
    REGISTER OBJ cls;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   465
249
claus
parents: 221
diff changeset
   466
    if (__isSmallInteger(index)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   467
	indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   468
	slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   469
	if ((cls = __qClass(slf)) != @global(ByteArray)) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   470
	    if (indx < 0) goto badIndex;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   471
	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   472
	}
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   473
	nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   474
	if ((unsigned)indx < (unsigned)nIndex) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   475
	    RETURN ( __mkSmallInteger((__ByteArrayInstPtr(slf)->ba_element[indx])) );
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   476
	}
249
claus
parents: 221
diff changeset
   477
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   478
badIndex: ;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   479
%}.
249
claus
parents: 221
diff changeset
   480
    ^ (super basicAt:index) asInteger
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   481
!
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   482
249
claus
parents: 221
diff changeset
   483
byteAt:index put:value
claus
parents: 221
diff changeset
   484
    "set the byte at index. For ByteArray, this is the same as basicAt:put:.
claus
parents: 221
diff changeset
   485
     However, for Strings, this expects a byteValue to be stored."
claus
parents: 221
diff changeset
   486
claus
parents: 221
diff changeset
   487
%{  /* NOCONTEXT */
claus
parents: 221
diff changeset
   488
claus
parents: 221
diff changeset
   489
    REGISTER int indx;
claus
parents: 221
diff changeset
   490
    int nIndex;
claus
parents: 221
diff changeset
   491
    int val;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   492
    REGISTER OBJ slf;
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   493
    REGISTER OBJ cls;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   494
249
claus
parents: 221
diff changeset
   495
    if (__bothSmallInteger(index, value)) {
4661
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   496
	val = __intVal(value);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   497
	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   498
	    indx = __intVal(index) - 1;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   499
	    slf = self;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   500
	    if ((cls = __qClass(slf)) != ByteArray) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   501
		if (indx < 0) goto badIndex;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   502
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   503
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   504
	    nIndex = __byteArraySize(slf);
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   505
	    if ((unsigned)indx < (unsigned)nIndex) {
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   506
		__ByteArrayInstPtr(slf)->ba_element[indx] = val;
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   507
		RETURN ( value );
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   508
	    }
9ebc7608738d comment
Claus Gittinger <cg@exept.de>
parents: 4386
diff changeset
   509
	}
249
claus
parents: 221
diff changeset
   510
    }
4386
ecc88f1c1169 oops - subclasses with instVars allowed for index-less-than-1-access
Claus Gittinger <cg@exept.de>
parents: 4367
diff changeset
   511
badIndex: ;
1147
a83c86d02b59 can do low..hi index check with one compare
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   512
%}.
249
claus
parents: 221
diff changeset
   513
    ^ super basicAt:index put:value
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   514
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   515
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   516
!ByteArray methodsFor:'accessing-longs'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   517
2
claus
parents: 1
diff changeset
   518
doubleWordAt:index put:value
claus
parents: 1
diff changeset
   519
    "set the 4-bytes starting at index from the (unsigned) Integer value.
359
claus
parents: 343
diff changeset
   520
     The value should be in the range 0 to 16rFFFFFFFF
claus
parents: 343
diff changeset
   521
     (for negative values, the stored value is not defined).
claus
parents: 343
diff changeset
   522
     The value is stored in the machines natural byte order.
claus
parents: 343
diff changeset
   523
     Q: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
claus
parents: 343
diff changeset
   524
claus
parents: 343
diff changeset
   525
    |t|
claus
parents: 343
diff changeset
   526
claus
parents: 343
diff changeset
   527
%{  /* NOCONTEXT */
claus
parents: 343
diff changeset
   528
claus
parents: 343
diff changeset
   529
    REGISTER int indx;
claus
parents: 343
diff changeset
   530
    int nIndex;
claus
parents: 343
diff changeset
   531
    union {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   532
	unsigned char u_char[4];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   533
	unsigned int u_uint;
359
claus
parents: 343
diff changeset
   534
    } val;
claus
parents: 343
diff changeset
   535
    OBJ cls;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   536
    unsigned char *byteP;
359
claus
parents: 343
diff changeset
   537
claus
parents: 343
diff changeset
   538
    if (__isSmallInteger(index)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   539
	if (__isSmallInteger(value)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   540
	    val.u_uint = __intVal(value);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   541
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   542
	    val.u_uint = __longIntVal(value);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   543
	    if (val.u_uint == 0) goto error;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   544
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   545
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   546
	indx = __intVal(index);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   547
	if (indx > 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   548
	    if ((cls = __qClass(self)) != @global(ByteArray))
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   549
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   550
	    nIndex = __qSize(self) - OHDR_SIZE;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   551
	    if ((indx+3) <= nIndex) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   552
		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   553
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   554
		((unsigned int *)byteP)[0] = val.u_uint;
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   555
#else
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   556
		if (((unsigned INT)byteP & 3) == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   557
		    ((unsigned int *)byteP)[0] = val.u_uint;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   558
		} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   559
		    byteP[0] = val.u_char[0];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   560
		    byteP[1] = val.u_char[1];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   561
		    byteP[2] = val.u_char[2];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   562
		    byteP[3] = val.u_char[3];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   563
		}
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   564
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   565
		RETURN ( value );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   566
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   567
	}
359
claus
parents: 343
diff changeset
   568
    }
claus
parents: 343
diff changeset
   569
  error: ;
claus
parents: 343
diff changeset
   570
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   571
    ^ super doubleWordAt:index put:value.
359
claus
parents: 343
diff changeset
   572
claus
parents: 343
diff changeset
   573
    "
claus
parents: 343
diff changeset
   574
     |b|
claus
parents: 343
diff changeset
   575
     b := ByteArray new:4.
claus
parents: 343
diff changeset
   576
     b doubleWordAt:1 put:16r04030201.
claus
parents: 343
diff changeset
   577
     b inspect
claus
parents: 343
diff changeset
   578
    "
claus
parents: 343
diff changeset
   579
!
claus
parents: 343
diff changeset
   580
claus
parents: 343
diff changeset
   581
doubleWordAt:index put:value MSB:msb
claus
parents: 343
diff changeset
   582
    "set the 4-bytes starting at index from the (unsigned) Integer value.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   583
     The value must be in the range 0 to 16rFFFFFFFF.
359
claus
parents: 343
diff changeset
   584
     The value is stored MSB-first if msb is true; LSB-first otherwise.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   585
     question: should it store signed values ? (see ByteArray signedDoubleWordAt:put:)"
2
claus
parents: 1
diff changeset
   586
claus
parents: 1
diff changeset
   587
    |t|
claus
parents: 1
diff changeset
   588
claus
parents: 1
diff changeset
   589
%{  /* NOCONTEXT */
claus
parents: 1
diff changeset
   590
claus
parents: 1
diff changeset
   591
    REGISTER int indx;
claus
parents: 1
diff changeset
   592
    int nIndex;
claus
parents: 1
diff changeset
   593
    int val;
249
claus
parents: 221
diff changeset
   594
    OBJ cls;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   595
    unsigned char *byteP;
2
claus
parents: 1
diff changeset
   596
359
claus
parents: 343
diff changeset
   597
    if (__isSmallInteger(index)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   598
	if (__isSmallInteger(value)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   599
	    val = __intVal(value);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   600
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   601
	    val = __longIntVal(value);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   602
	    if (val == 0) goto error;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   603
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   604
	indx = __intVal(index);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   605
	if (indx > 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   606
	    if ((cls = __qClass(self)) != @global(ByteArray))
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   607
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   608
	    nIndex = __qSize(self) - OHDR_SIZE;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   609
	    if ((indx+3) <= nIndex) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   610
		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   611
		if (msb == true) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   612
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   613
		     * most significant byte first (i.e sparc order)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   614
		     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   615
#if defined(__MSBFIRST__)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   616
		    if (((INT)byteP & 3) == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   617
			((int *)byteP)[0] = val;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   618
		    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   619
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   620
		    {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   621
			byteP[3] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   622
			val >>= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   623
			byteP[2] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   624
			val >>= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   625
			byteP[1] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   626
			val >>= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   627
			byteP[0] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   628
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   629
		} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   630
		    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   631
		     * least significant byte first (i.e i386/alpha order)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   632
		     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   633
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   634
		    ((int *)byteP)[0] = val;
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   635
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   636
# if defined(__LSBFIRST__)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   637
		    if (((unsigned INT)byteP & 3) == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   638
			((int *)byteP)[0] = val;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   639
		    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   640
# endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   641
		    {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   642
			byteP[0] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   643
			val >>= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   644
			byteP[1] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   645
			val >>= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   646
			byteP[2] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   647
			val >>= 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   648
			byteP[3] = val & 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   649
		    }
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   650
#endif
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   651
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   652
		RETURN ( value );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   653
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   654
	}
2
claus
parents: 1
diff changeset
   655
    }
359
claus
parents: 343
diff changeset
   656
  error: ;
claus
parents: 343
diff changeset
   657
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   658
    ^ super doubleWordAt:index put:value MSB:msb
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   659
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   660
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   661
     |b|
359
claus
parents: 343
diff changeset
   662
     b := ByteArray new:8.
claus
parents: 343
diff changeset
   663
     b doubleWordAt:1 put:16r04030201 MSB:true.
claus
parents: 343
diff changeset
   664
     b doubleWordAt:5 put:16r04030201 MSB:false.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   665
     b inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   666
    "
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   667
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   668
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
   669
!ByteArray methodsFor:'accessing-shorts'!
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   670
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   671
wordAt:index
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   672
    "return the 2-bytes starting at index as an (unsigned) Integer.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   673
     The value is retrieved in the machines natural byte order
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   674
     Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   675
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   676
%{  /* NOCONTEXT */
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   677
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   678
    REGISTER int indx;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   679
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   680
    union {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   681
	unsigned char u_char[2];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   682
	unsigned short u_ushort;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   683
    } val;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   684
    unsigned char *byteP;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   685
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   686
    if (__isSmallInteger(index)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   687
	indx = __intVal(index);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   688
	if (indx > 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   689
	    if (!__isByteArrayLike(self))
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   690
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   691
	    nIndex = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   692
	    if ((indx+1) <= nIndex) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   693
		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   694
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   695
		val.u_ushort = ((unsigned short *)byteP)[0];
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   696
#else
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   697
		/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   698
		 * mhmh to be measured:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   699
		 *   the if may hurt more than the additional
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   700
		 *   memory cycles on some machines ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   701
		 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   702
		if (((INT)byteP & 1) == 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   703
		    /* aligned */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   704
		    val.u_ushort = ((unsigned short *)byteP)[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   705
		} else {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   706
		    val.u_char[0] = byteP[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   707
		    val.u_char[1] = byteP[1];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   708
		}
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   709
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   710
		RETURN ( __mkSmallInteger((val.u_ushort)) );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   711
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   712
	}
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   713
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   714
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   715
    ^ super wordAt:index
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   716
!
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   717
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   718
wordAt:index MSB:msb
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   719
    "return the 2-bytes starting at index as an (unsigned) Integer.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   720
     The value is retrieved MSB (high 8 bits at lower index) if msb is true;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   721
     LSB-first (i.e. low 8-bits at lower byte index) if its false.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   722
     Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   723
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   724
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   725
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   726
    REGISTER int indx;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   727
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   728
    int val;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   729
    unsigned char *byteP;
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   730
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   731
    if (__isSmallInteger(index)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   732
	indx = __intVal(index);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   733
	if (indx > 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   734
	    if (!__isByteArrayLike(self))
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   735
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   736
	    nIndex = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   737
	    if ((indx+1) <= nIndex) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   738
		byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   739
		if (msb == true) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   740
		    /*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   741
		     * most significant byte first (i.e sparc order)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   742
		     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   743
#if defined(__MSBFIRST__)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   744
		    /*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   745
		     * mhmh to be measured:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   746
		     *   the if may hurt more than the additional
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   747
		     *   memory cycles on some machines ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   748
		     */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   749
		    if (((INT)byteP & 1) == 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   750
			/* aligned */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   751
			val = ((unsigned short *)byteP)[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   752
		    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   753
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   754
		    {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   755
			val = byteP[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   756
			val = (val << 8) + byteP[1];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   757
		    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   758
		} else {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   759
		    /*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   760
		     * least significant byte first (i.e i386/alpha order)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   761
		     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   762
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   763
		    val = ((unsigned short *)byteP)[0];
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   764
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   765
# if defined(__LSBFIRST__)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   766
		    /*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   767
		     * mhmh to be measured:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   768
		     *   the if may hurt more than the additional
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   769
		     *   memory cycles on some machines ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   770
		     */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   771
		    if (((INT)byteP & 1) == 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   772
			/* aligned */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   773
			val = ((unsigned short *)byteP)[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   774
		    } else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   775
# endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   776
		    {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   777
			val = byteP[1];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   778
			val = (val << 8) + byteP[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   779
		    }
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   780
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   781
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   782
		RETURN ( __mkSmallInteger(val) );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   783
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   784
	}
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   785
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   786
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   787
    ^ super wordAt:index MSB:msb
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   788
!
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   789
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   790
wordAt:index put:value
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   791
    "set the 2-bytes starting at index from the (unsigned) Integer value.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   792
     The stored value must be in the range 0 .. 16rFFFF.
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   793
     The value is stored in the machines natural byteorder,
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   794
     i.e. this method should only be used to fill byteArrays which are
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   795
     used internally (not passed to other machines).
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   796
     Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   797
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   798
%{  /* NOCONTEXT */
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 37
diff changeset
   799
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   800
    REGISTER int indx;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   801
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   802
    int v;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   803
    union {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   804
	unsigned char u_char[2];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   805
	unsigned short u_ushort;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   806
    } val;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   807
    unsigned char *byteP;
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   808
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   809
    if (__bothSmallInteger(index, value)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   810
	indx = __intVal(index);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   811
	if (indx > 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   812
	    if (!__isByteArrayLike(self))
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   813
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   814
	    nIndex = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   815
	    if ((indx+1) <= nIndex) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   816
		val.u_ushort = v = __intVal(value);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   817
		if ((v & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   818
		    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   819
#if defined(__i386__) || defined(UNALIGNED_FETCH_OK)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   820
		    ((unsigned short *)byteP)[0] = val.u_ushort;
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   821
#else
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   822
		    /*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   823
		     * mhmh to be measured:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   824
		     *   the if may hurt more than the additional
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   825
		     *   memory cycles on some machines ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   826
		     */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   827
		    if (((INT)byteP & 1) == 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   828
			/* aligned */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   829
			((unsigned short *)byteP)[0] = val.u_ushort;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   830
		    } else {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   831
			byteP[0] = val.u_char[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   832
			byteP[1] = val.u_char[1];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   833
		    }
3422
09c13ab58bb2 i386 can do unaligned accesses
Claus Gittinger <cg@exept.de>
parents: 3345
diff changeset
   834
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   835
		    RETURN ( value );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   836
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   837
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   838
	}
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   839
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   840
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   841
    ^ super wordAt:index put:value
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   842
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   843
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   844
     |b|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   845
     b := ByteArray new:4.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   846
     b wordAt:1 put:16r0102.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   847
     b wordAt:3 put:16r0304.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   848
     b inspect
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   849
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   850
!
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   851
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   852
wordAt:index put:value MSB:msb
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   853
    "set the 2-bytes starting at index from the (unsigned) Integer value.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   854
     The stored value must be in the range 0 .. 16rFFFF.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   855
     The value is stored LSB-first (i.e. the low 8bits are stored at the
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   856
     lower index) if msb is false, MSB-first otherwise.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   857
     Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   858
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   859
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   860
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   861
    REGISTER int indx;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   862
    int nIndex;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   863
    int val;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   864
    OBJ cls;
2950
d5fae0fb75d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2915
diff changeset
   865
    unsigned char *byteP;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   866
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   867
    if (__bothSmallInteger(index, value)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   868
	indx = __intVal(index);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   869
	if (indx > 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   870
	    if (!__isByteArrayLike(self))
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   871
		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(__qClass(self))->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   872
	    nIndex = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   873
	    if ((indx+1) <= nIndex) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   874
		val = __intVal(value);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   875
		if ((val & ~0xFFFF) == 0 /* i.e. (val >= 0) && (val <= 0xFFFF) */) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   876
		    byteP = (unsigned char *)(__ByteArrayInstPtr(self)->ba_element) + indx - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   877
		    if (msb == true) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   878
			/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   879
			 * most significant byte first (i.e sparc order)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   880
			 */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   881
#if defined(__MSBFIRST__)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   882
			/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   883
			 * mhmh to be measured:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   884
			 *   the if may hurt more than the additional
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   885
			 *   memory cycles on some machines ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   886
			 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   887
			if (((INT)byteP & 1) == 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   888
			    /* aligned */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   889
			    ((unsigned short *)byteP)[0] = val;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   890
			} else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   891
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   892
			{
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   893
			    byteP[1] = val & 0xFF;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   894
			    byteP[0] = (val>>8) & 0xFF;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   895
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   896
		    } else {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   897
			/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   898
			 * least significant byte first (i.e i386/alpha order)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   899
			 */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   900
#if defined(__i386__) || (defined(__LSBFIRST__) && defined(UNALIGNED_FETCH_OK))
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   901
			((unsigned short *)byteP)[0] = val;
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   902
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
   903
# if defined(__LSBFIRST__)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   904
			/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   905
			 * mhmh to be measured:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   906
			 *   the if may hurt more than the additional
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   907
			 *   memory cycles on some machines ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   908
			 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   909
			if (((INT)byteP & 1) == 0) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   910
			    /* aligned */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   911
			    ((unsigned short *)byteP)[0] = val;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   912
			} else
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
   913
# endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   914
			{
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   915
			    byteP[0] = val & 0xFF;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   916
			    byteP[1] = (val>>8) & 0xFF;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   917
			}
3425
f7faef75f0d8 tuned word & doubleWord access for i386
Claus Gittinger <cg@exept.de>
parents: 3422
diff changeset
   918
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   919
		    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   920
		    RETURN ( value );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   921
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   922
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   923
	}
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   924
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   925
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
   926
    ^ super wordAt:index put:value MSB:msb
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   927
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   928
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   929
     |b|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   930
     b := ByteArray new:8.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   931
     b wordAt:1 put:16r0102 MSB:false.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   932
     b wordAt:3 put:16r0304 MSB:false.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   933
     b wordAt:5 put:16r0102 MSB:true.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   934
     b wordAt:7 put:16r0304 MSB:true.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   935
     b inspect
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
   936
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   937
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   938
11502
64d1cb6c2062 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 11265
diff changeset
   939
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   940
!ByteArray methodsFor:'comparing'!
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   941
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   942
= aByteArray
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   943
    "Compare the receiver with the argument and return true if the
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   944
     receiver is equal to the argument (i.e. has the same size and elements).
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   945
     Otherwise return false."
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   946
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   947
%{  /* NOCONTEXT */
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   948
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   949
    int l1, l2;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   950
    REGISTER OBJ s = aByteArray;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   951
    unsigned char *cp1, *cp2;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   952
    OBJ cls;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   953
    OBJ myCls;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   954
    INT addrDelta;
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   955
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   956
    if (s == self) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   957
	RETURN ( true );
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   958
    }
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   959
    if (! __isNonNilObject(s)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   960
	RETURN ( false );
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   961
    }
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   962
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   963
    cls = __qClass(s);
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   964
    myCls = __qClass(self);
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   965
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
   966
    if (cls == myCls) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   967
	l2 = __byteArraySize(s);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   968
	l1 = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   969
	if (l1 != l2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   970
	    RETURN ( false );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   971
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   972
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   973
	cp1 = __byteArrayVal(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   974
	cp2 = __byteArrayVal(s);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   975
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   976
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   977
	 * care for instances of subclasses ...
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   978
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   979
	if (cls != ByteArray) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   980
	    int n = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   981
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   982
	    cp2 += n;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   983
	    cp1 += n;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   984
	    l1 -= n;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   985
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   986
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   987
	addrDelta = cp2 - cp1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   988
	while (l1 >= (sizeof(unsigned INT) * 4)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   989
	    if (((unsigned INT *)cp1)[0] != ((unsigned INT *)(cp1+addrDelta))[0]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   990
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   991
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   992
	    if (((unsigned INT *)cp1)[1] != ((unsigned INT *)(cp1+addrDelta))[1]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   993
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   994
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   995
	    if (((unsigned INT *)cp1)[2] != ((unsigned INT *)(cp1+addrDelta))[2]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   996
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   997
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   998
	    if (((unsigned INT *)cp1)[3] != ((unsigned INT *)(cp1+addrDelta))[3]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
   999
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1000
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1001
	    l1 -= sizeof(unsigned INT)*4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1002
	    cp1 += sizeof(unsigned INT)*4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1003
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1004
	while (l1 >= sizeof(unsigned INT)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1005
	    if (*((unsigned INT *)cp1) != *((unsigned INT *)(cp1+addrDelta))) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1006
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1007
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1008
	    l1 -= sizeof(unsigned INT);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1009
	    cp1 += sizeof(unsigned INT);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1010
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1011
	if (l1 >= sizeof(unsigned short)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1012
	    if (*((unsigned short *)cp1) != *((unsigned short *)(cp1+addrDelta))) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1013
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1014
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1015
	    l1 -= sizeof(unsigned short);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1016
	    cp1 += sizeof(unsigned short);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1017
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1018
	while (l1) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1019
	    if (*cp1 != *(cp1+addrDelta)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1020
		RETURN (false);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1021
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1022
	    l1--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1023
	    cp1++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1024
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1025
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1026
	RETURN (true);
3345
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1027
    }
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1028
%}.
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1029
    ^ super = aByteArray
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1030
! !
6cbaa948a813 added tuned version of #=
Claus Gittinger <cg@exept.de>
parents: 3325
diff changeset
  1031
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1032
!ByteArray methodsFor:'converting'!
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1033
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1034
asByteArray
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1035
    "return the receiver as a byteArray"
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1036
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1037
    "could be an instance of a subclass..."
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1038
    self class == ByteArray ifTrue:[
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1039
	^ self
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1040
    ].
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1041
    ^ super asByteArray
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1042
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1043
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1044
     'hello world' asByteArray
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1045
     #(1 2 3 4 5 6 7) asByteArray
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1046
     #(1 2 256 4 5 6 7) asByteArray
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1047
    "
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1048
!
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1049
12453
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1050
asImmutableByteArray
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1051
    "return a write-protected copy of myself"
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1052
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1053
    self assert:(ImmutableByteArray notNil).
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1054
    ^ self copy changeClassTo:ImmutableByteArray
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1055
!
74715f6d4cbe added: #asImmutableByteArray
Claus Gittinger <cg@exept.de>
parents: 12276
diff changeset
  1056
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1057
asInteger
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1058
    "convert myself to an integer - the first byte is most significant.
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1059
     This is also in Squeak."
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1060
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1061
    ^ (LargeInteger digitBytes:self MSB:true) compressed
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1062
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1063
    "
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1064
        #[ 2 ] asInteger hexPrintString
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1065
        #[ 16r1 16r2 ] asInteger hexPrintString
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1066
        #[4 0 0 0 0 0 0 0] asInteger hexPrintString
12276
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1067
    "
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1068
!
6a8f5042befc added: #asInteger
Stefan Vogel <sv@exept.de>
parents: 12144
diff changeset
  1069
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1070
asIntegerMSB:isMSBFirst
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1071
    "convert myself to an integer - the first byte is most significant.
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1072
     This is also in Squeak."
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1073
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1074
    ^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1075
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1076
    "
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1077
        (#[ 2 ] asIntegerMSB:true) hexPrintString
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1078
        (#[ 16r1 16r2 ] asIntegerMSB:true) hexPrintString
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1079
        (#[ 16r1 16r2 ] asIntegerMSB:false) hexPrintString
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  1080
        (#[4 0 0 0 0 0 0 0] asIntegerMSB:true) hexPrintString
12621
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1081
    "
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1082
!
Stefan Vogel <sv@exept.de>
parents: 12550
diff changeset
  1083
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1084
asPackedString
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1085
    "ST-80 compatibility: encode the receiver into an ascii String
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1086
     with 6bits encoded per character. Each group of 6 bits is encoded
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1087
     as a corresponding character (32+value) and the resulting string
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1088
     is returned. The resulting string is always a multiple of 4 (since
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1089
     24 is the lcm of 6 and 8) and the number of remaining characters is
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1090
     encoded in the last character.
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1091
     ST-80 uses this encoding for Images ...
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1092
     This is very similar (but not equal) to the algorithm used in RFC1421.
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1093
     PS: I dont like it ;-)"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1094
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1095
    |outStream
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1096
     index     "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1097
     nextIndex "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1098
     stop      "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1099
     n         "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1100
     mod       "{ Class:SmallInteger}"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1101
     cpl|
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1102
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1103
    outStream := WriteStream on:String new.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1104
    index := 1.
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1105
    stop := self size.
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1106
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1107
    stop > 100 ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1108
	"/ cg:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1109
	"/ initial lineBreak
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1110
	outStream cr.
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1111
    ].
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1112
    cpl := 0.
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1113
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1114
    [index <= stop] whileTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1115
	"take 3 source bytes"
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1116
	n := (self at:index) bitShift:16.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1117
	(index < stop) ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1118
	    nextIndex := index + 1.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1119
	    n := n bitOr:((self at:nextIndex) bitShift:8).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1120
	    (nextIndex < stop) ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1121
		n := n bitOr:(self at:(index + 2)).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1122
	    ].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1123
	].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1124
	index := index + 3.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1125
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1126
	"took me a while to find that one out ..."
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1127
	n := n bitXor:16r820820.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1128
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1129
	outStream nextPut:(Character value:((n bitShift:-18) bitAnd:16r3F) + 32).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1130
	outStream nextPut:(Character value:((n bitShift:-12) bitAnd:16r3F) + 32).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1131
	outStream nextPut:(Character value:((n bitShift:-6) bitAnd:16r3F) + 32).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1132
	outStream nextPut:(Character value:(n bitAnd:16r3F) + 32).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1133
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1134
	"/ cg:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1135
	"/ lineBreak after every 120 characters
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1136
	"/ fromPackedString will ignore those
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1137
	cpl := cpl + 4.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1138
	cpl >= 120 ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1139
	    outStream cr.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1140
	    cpl := 0.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1141
	].
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1142
    ].
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1143
    (mod := stop \\ 3) ~~ 0 ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1144
	outStream backStep.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1145
	outStream nextPut:(Character value:(mod + 96)).
7117
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1146
    ].
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1147
    ^ outStream contents
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1148
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1149
    "Modified: 12.11.1996 / 15:45:02 / cg"
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1150
!
9c008ffeeb75 comments
Claus Gittinger <cg@exept.de>
parents: 7049
diff changeset
  1151
5900
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1152
asString
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1153
    "speed up string conversions"
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1154
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1155
    |size|
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1156
5901
Stefan Vogel <sv@exept.de>
parents: 5900
diff changeset
  1157
    self class == ByteArray ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1158
	size := self size.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1159
	^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
5901
Stefan Vogel <sv@exept.de>
parents: 5900
diff changeset
  1160
    ].
Stefan Vogel <sv@exept.de>
parents: 5900
diff changeset
  1161
    ^ super asString
5900
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1162
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1163
    "
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1164
      #[60 61 62 63] asString
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1165
    "
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1166
!
3c3aba588e94 Speedup ByteArray>>asString
Stefan Vogel <sv@exept.de>
parents: 5554
diff changeset
  1167
4807
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1168
decodeAsLiteralArray
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1169
    "given a literalEncoding in the receiver,
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1170
     create & return the corresponding object.
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1171
     The inverse operation to #literalArrayEncoding."
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1172
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1173
    ^ self
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1174
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1175
!
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
  1176
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1177
literalArrayEncoding
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1178
    "encode myself as an array literal, from which a copy of the receiver
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1179
     can be reconstructed with #decodeAsLiteralArray."
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1180
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  1181
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  1182
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  1183
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1184
	^ self
11063
ca134030dff4 changed #literalArrayEncoding: self is onlz ok for realByteArrays
fm
parents: 11010
diff changeset
  1185
    ].
ca134030dff4 changed #literalArrayEncoding: self is onlz ok for realByteArrays
fm
parents: 11010
diff changeset
  1186
    ^ super literalArrayEncoding
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1187
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1188
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1189
     #[1 2 3] literalArrayEncoding
4778
df6189d4909e literalArrayEncoding is self.
Stefan Vogel <sv@exept.de>
parents: 4777
diff changeset
  1190
    "
12
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1191
! !
8e03bd717355 *** empty log message ***
claus
parents: 10
diff changeset
  1192
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1193
!ByteArray methodsFor:'copying'!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1194
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1195
copy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1196
    "redefined for a bit more speed"
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1197
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1198
    self class == ByteArray ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1199
	^ self copyFrom:1 to:(self size)
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1200
    ].
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1201
    ^ super copy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1202
!
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1203
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1204
copyFrom:start to:stop
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1205
    "return the subcollection starting at index start, anInteger and ending
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1206
     at stop, anInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1207
     - reimplemented here for speed"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1208
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1209
%{  /* NOCONTEXT */
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1210
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1211
    REGISTER unsigned char *srcp;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1212
    REGISTER unsigned char *dstp;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1213
    REGISTER int count;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1214
    int len, index1, index2, sz;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1215
    OBJ newByteArray;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1216
12466
353502b2baa9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12453
diff changeset
  1217
    if (__isByteArrayLike(self)
249
claus
parents: 221
diff changeset
  1218
     && __bothSmallInteger(start, stop)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1219
	len = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1220
	index1 = __intVal(start);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1221
	index2 = __intVal(stop);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1222
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1223
	if ((index1 <= index2) && (index1 > 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1224
	    if (index2 <= len) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1225
		count = index2 - index1 + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1226
		__PROTECT_CONTEXT__
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1227
		sz = OHDR_SIZE + count;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1228
		__qNew(newByteArray, sz);       /* OBJECT ALLOCATION */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1229
		__UNPROTECT_CONTEXT__
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1230
		if (newByteArray != nil) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1231
		    __InstPtr(newByteArray)->o_class = ByteArray;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1232
		    __qSTORE(newByteArray, ByteArray);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1233
		    dstp = __ByteArrayInstPtr(newByteArray)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1234
		    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
2648
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1235
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1236
#ifdef bcopy4
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1237
		    if (((unsigned INT)srcp & 3) == ((unsigned INT)dstp & 3)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1238
			int nW;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1239
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1240
			/* copy unaligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1241
			while (count && (((unsigned INT)srcp & 3) != 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1242
			    *dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1243
			    count--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1244
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1245
			if (count) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1246
			    /* copy aligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1247
			    nW = count >> 2;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1248
			    if (count & 3) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1249
				nW++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1250
			    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1251
			    bcopy4(srcp, dstp, nW);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1252
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1253
			RETURN ( newByteArray );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1254
		    }
2648
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1255
#endif /* bcopy4 */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
  1256
#if __POINTER_SIZE__ == 8
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1257
		    if (((unsigned INT)srcp & 7) == ((unsigned INT)dstp & 7)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1258
			int nW;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1259
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1260
			/* copy unaligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1261
			while (count && (((unsigned INT)srcp & 7) != 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1262
			    *dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1263
			    count--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1264
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1265
			/* copy aligned part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1266
			while (count >= 8) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1267
			    ((unsigned INT *)dstp)[0] = ((unsigned INT *)srcp)[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1268
			    dstp += 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1269
			    srcp += 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1270
			    count -= 8;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1271
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1272
			/* copy remaining part */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1273
			while (count) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1274
			    *dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1275
			    count--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1276
			}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1277
			RETURN ( newByteArray );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1278
		    }
4943
8e51d34f2b3a slightly tuned #copyFrom:to: and #replaceBytesFrom:to:with:startingAt:
Claus Gittinger <cg@exept.de>
parents: 4941
diff changeset
  1279
#endif /* bcopy4 */
2648
a544a64491a7 better use of bcopy4
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
  1280
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1281
#ifdef FAST_MEMCPY
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1282
		    bcopy(srcp, dstp, count);
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1283
#else
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1284
		    while (count--) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1285
			*dstp++ = *srcp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1286
		    }
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1287
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1288
		    RETURN ( newByteArray );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1289
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1290
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1291
	}
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1292
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1293
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1294
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1295
     fall back in case of non-integer index or out-of-bound index;
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1296
     will eventually lead to an out-of-bound signal raise
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1297
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1298
    ^ super copyFrom:start to:stop
4941
7674fdddb1db better byteArray copy on Intel
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1299
7674fdddb1db better byteArray copy on Intel
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1300
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1301
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:1 to:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1302
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1303
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1304
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:5 to:11
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1305
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1306
     #[1 2 3 4 5 6 7 8 9 10] copyFrom:0 to:9
4941
7674fdddb1db better byteArray copy on Intel
Claus Gittinger <cg@exept.de>
parents: 4931
diff changeset
  1307
    "
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1308
!
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1309
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1310
shallowCopy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1311
    "redefined for a bit more speed"
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1312
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1313
    self class == ByteArray ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1314
	^ self copyFrom:1 to:(self size)
5024
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1315
    ].
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1316
    ^ super shallowCopy
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1317
!
abff1ede34d1 faster copy/shallowCopy
Claus Gittinger <cg@exept.de>
parents: 5019
diff changeset
  1318
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1319
symbolFrom:start to:stop
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1320
    "make a symbol from the characters of the subcollection starting
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1321
     at index start, anInteger and ending at stop, anInteger.
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1322
     This saves us garbage and character copying."
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1323
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1324
    |sym|
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1326
%{  /* STACK:1024 */
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1327
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1328
    REGISTER unsigned char *srcp;
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1329
    REGISTER unsigned char *endp;
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1330
    REGISTER int count;
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1331
    int len, index1, index2;
4086
4b3a61a4e35d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
  1332
    unsigned char scratchBuffer[1024], savec;
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1333
12466
353502b2baa9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12453
diff changeset
  1334
    if (__isByteArrayLike(self) && __bothSmallInteger(start, stop)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1335
	len = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1336
	index1 = __intVal(start);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1337
	index2 = __intVal(stop);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1338
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1339
	if ((index1 <= index2) && (index1 > 0) && (index2 <= len)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1340
	    count = index2 - index1 + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1341
	    srcp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1342
	    if (index2 < len) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1343
		/* temporarily stuff in a '\0' */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1344
		endp = srcp + count + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1345
		savec = *endp;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1346
		*endp = '\0';
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1347
		sym = __MKSYMBOL(srcp, 0);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1348
		/* must refetch endp (in case of a GC */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1349
		endp = __ByteArrayInstPtr(self)->ba_element + index1 + count;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1350
		*endp = savec;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1351
	    } else {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1352
		/* not enough space for '\0', copy the bytes */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1353
		if (count < sizeof(scratchBuffer)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1354
		    bcopy(srcp, scratchBuffer, count);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1355
		    scratchBuffer[count] = '\0';
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1356
		    sym = __MKSYMBOL(scratchBuffer, 0);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1357
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1358
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1359
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1360
	if (sym != nil)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1361
	    RETURN(sym);
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1362
    }
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1363
%}.
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1364
    "
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1365
     fall back in case of non-integer index or out-of-bound index
4086
4b3a61a4e35d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
  1366
     or not enough stack-memory available;
4b3a61a4e35d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4062
diff changeset
  1367
     may eventually lead to an out-of-bound signal raise
3325
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1368
    "
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1369
    ^ (super copyFrom:start to:stop) asString asSymbol
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1370
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1371
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1372
    "
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1373
     'abcdefghijklmnop' symbolFrom:1 to:3
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1374
     'abcdefghijklmnop' symbolFrom:3 to:16
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1375
     'abcdefghijklmnop' symbolFrom:3 to:17
e958a341f41d Add #from: and #with:form:to class methods.
Stefan Vogel <sv@exept.de>
parents: 3234
diff changeset
  1376
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1377
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1378
4154
6938d9274ee4 category rename
Claus Gittinger <cg@exept.de>
parents: 4128
diff changeset
  1379
!ByteArray methodsFor:'filling & replacing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1380
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1381
from:start to:stop put:aNumber
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1382
    "fill part of the receiver with aNumber.
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1383
     - reimplemented here for speed"
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1384
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1385
%{  /* NOCONTEXT */
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1386
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1387
    REGISTER unsigned char *dstp;
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1388
    REGISTER int count, value;
249
claus
parents: 221
diff changeset
  1389
    int len, index1, index2;
claus
parents: 221
diff changeset
  1390
    OBJ cls;
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1391
249
claus
parents: 221
diff changeset
  1392
    if (__isSmallInteger(aNumber)
1002
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
  1393
     && __bothSmallInteger(start, stop)
c44e50c09986 care for 16bit subclass instances (in tuned methods)
Claus Gittinger <cg@exept.de>
parents: 931
diff changeset
  1394
     && __isBytes(self)) {
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1395
	len = __byteArraySize(self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1396
	index1 = __intVal(start);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1397
	index2 = __intVal(stop);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1398
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1399
	dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1400
	if ((cls = __qClass(self)) != @global(ByteArray)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1401
	    int nInst;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1402
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1403
	    nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1404
	    dstp += nInst;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1405
	    len -= nInst;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1406
	}
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1407
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1408
	value = __intVal(aNumber);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1409
	if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1410
	 && (index1 <= index2)
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1411
	 && (index1 > 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1412
	    if (index2 <= len) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1413
		count = index2 - index1 + 1;
2579
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1414
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1415
#ifdef memset4
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1416
		if (count > 20) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1417
		    /* fill unaligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1418
		    while (((unsigned INT)dstp & 3) != 0) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1419
			*dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1420
			count--;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1421
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1422
		    /* fill aligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1423
		    {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1424
			int n4 = count & ~3;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1425
			int v4, nW;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1426
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1427
			v4 = (value << 8) | value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1428
			v4 = (v4 << 16) | v4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1429
			nW = n4>>2;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1430
			memset4(dstp, v4, nW);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1431
			count -= n4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1432
			dstp += n4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1433
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1434
		    while (count--) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1435
			*dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1436
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1437
		    RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1438
		}
2579
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1439
#endif /* memset4 */
7e0783458c2f much faster #from:to:put: and #replaceBytes on i386 platforms
Claus Gittinger <cg@exept.de>
parents: 2464
diff changeset
  1440
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1441
#if (__POINTER_SIZE__ == 8)
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1442
		{
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1443
		    INT v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1444
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1445
		    v8 = (value << 8) | value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1446
		    v8 = (v8 << 16) | v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1447
		    v8 = (v8 << 32) | v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1448
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1449
		    /* fill unaligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1450
		    while ((count > 0) && (((unsigned INT)dstp & 3) != 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1451
			*dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1452
			count--;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1453
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1454
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1455
		    if ((count >= 4) && (((unsigned INT)dstp & 7) != 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1456
			((unsigned int *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1457
			dstp += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1458
			count -= 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1459
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1460
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1461
		    /* fill aligned part */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1462
		    while (count >= 8) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1463
			((unsigned INT *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1464
			dstp += 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1465
			count -= 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1466
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1467
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1468
		    /* fill rest */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1469
		    if (count >= 4) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1470
			((unsigned int *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1471
			dstp += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1472
			count -= 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1473
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1474
		    if (count >= 2) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1475
			((unsigned short *)dstp)[0] = v8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1476
			dstp += 2;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1477
			count -= 2;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1478
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1479
		    if (count) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1480
			*dstp = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1481
		    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1482
		    RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1483
		}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1484
#endif /* 64bit */
4945
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1485
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1486
#ifdef FAST_MEMSET
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1487
		memset(dstp, value, count);
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1488
#else
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1489
# ifdef __UNROLL_LOOPS__
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1490
		while (count >= 8) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1491
		    dstp[0] = dstp[1] = dstp[2] = dstp[3] =
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1492
		    dstp[4] = dstp[5] = dstp[6] = dstp[7] = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1493
		    dstp += 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1494
		    count -= 8;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1495
		}
8919
707a9ff7f9b2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1496
# endif /* __UNROLL_LOOPS__ */
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1497
		while (count--) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1498
		    *dstp++ = value;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1499
		}
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1500
#endif
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1501
		RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1502
	    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1503
	}
155
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1504
    }
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1505
%}.
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1506
    "
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1507
     fall back in case of non-integer index or out-of-bound index/value;
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1508
     will eventually lead to an out-of-bound signal raise
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1509
    "
edd7fc34e104 *** empty log message ***
claus
parents: 148
diff changeset
  1510
    ^ super from:start to:stop put:aNumber
4945
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1511
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1512
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1513
     (ByteArray new:10) from:1 to:10 put:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1514
     (ByteArray new:20) from:10 to:20 put:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1515
     (ByteArray new:20) from:1 to:10 put:1
4945
2e67ed09d194 tuned filling for alpha
Claus Gittinger <cg@exept.de>
parents: 4944
diff changeset
  1516
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1517
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1518
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1519
!ByteArray methodsFor:'image manipulation support'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1520
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1521
bitAndBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1522
    "replace bytes in the receiver with the result of a bitAnd operation.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1523
     Warning: this is a destructive operation - elements in the receiver are overwritten."
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1524
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1525
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitAnd:
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1526
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1527
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1528
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1529
	bitAndBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1530
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1531
	bitAndBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1532
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1533
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1534
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1535
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1536
bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:ruleSymbol
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1537
    "perform a special case of an aligned bitBlit operation.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1538
     Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1539
     of some logical operation, as specified by the ruleSymbol.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1540
     SourceBytes are fetched starting at sourceOffset.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1541
     Valid rule symbols are:
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1542
	#copy    - trivial;  same as replaceBytesFrom:to:with:startingAt:
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1543
	#bitXor: - xoring;   byte[dI] = byte[dI] bitXor:(srcByte[sI])
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1544
	#bitAnd: - anding;   byte[dI] = byte[dI] bitAnd:(srcByte[sI])
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1545
	#bitOr:  - oring;    byte[dI] = byte[dI] bitOr:(srcByte[sI])
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1546
	#+       - adding;   byte[dI] = (byte[dI] + (srcByte[sI])) mod: 256
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1547
	#-       - subtract; byte[dI] = (byte[dI] - (srcByte[sI])) mod: 256
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1548
     Warning: this is a destructive operation - elements in the receiver are overwritten.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1549
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1550
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1551
    |srcIdx|
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1552
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1553
%{
12466
353502b2baa9 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 12453
diff changeset
  1554
    if ((__isByteArrayLike(sourceBytes))
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1555
     && (__qClass(self) == ByteArray)
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1556
     && __isSmallInteger(dstStart)
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1557
     && __isSmallInteger(dstEnd)
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1558
     && __isSmallInteger(sourceStart)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1559
	unsigned char *srcP = __ByteArrayInstPtr(sourceBytes)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1560
	unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1561
	int srcLen = __byteArraySize(sourceBytes);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1562
	int dstLen = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1563
	int __srcStart = __intVal(sourceStart);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1564
	int __dstStart = __intVal(dstStart);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1565
	int count = __intVal(dstEnd) - __dstStart + 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1566
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1567
	if ((__dstStart >= 1)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1568
	 && (__srcStart >= 1)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1569
	 && ((__dstStart + count - 1) <= dstLen)
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1570
	 && ((__srcStart + count - 1) <= srcLen)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1571
	    srcP += __srcStart - 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1572
	    dstP += __dstStart - 1;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1573
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1574
#define OP_LOOP_BYTES(OP) \
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1575
    while (count > 0) {                                              \
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1576
	*dstP OP (*srcP);                                            \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1577
	srcP++;                                                      \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1578
	dstP++;                                                      \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1579
	count--;                                                     \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1580
    }
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1581
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1582
#define OP_LOOP(OP) \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1583
    while (count >= 16) {                                            \
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1584
	((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]);    \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1585
	((unsigned int *)dstP)[1] OP (((unsigned int *)srcP)[1]);    \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1586
	((unsigned int *)dstP)[2] OP (((unsigned int *)srcP)[2]);    \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1587
	((unsigned int *)dstP)[3] OP (((unsigned int *)srcP)[3]);    \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1588
	srcP += 16;                                                  \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1589
	dstP += 16;                                                  \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1590
	count -= 16;                                                 \
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1591
    }                                                                \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1592
    while (count >= 4) {                                             \
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1593
	((unsigned int *)dstP)[0] OP (((unsigned int *)srcP)[0]);    \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1594
	srcP += 4;                                                   \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1595
	dstP += 4;                                                   \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1596
	count -= 4;                                                  \
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1597
    }                                                                \
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1598
    while (count > 0) {                                              \
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1599
	*dstP OP (*srcP);                                            \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1600
	srcP++;                                                      \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1601
	dstP++;                                                      \
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1602
	count--;                                                     \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1603
    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1604
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1605
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1606
	    if (ruleSymbol == @symbol(bitXor:)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1607
		OP_LOOP( ^= )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1608
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1609
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1610
	    if (ruleSymbol == @symbol(bitXorNot:)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1611
		OP_LOOP( ^=~ )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1612
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1613
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1614
	    if (ruleSymbol == @symbol(bitAnd:)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1615
		OP_LOOP( &= )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1616
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1617
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1618
	    if (ruleSymbol == @symbol(bitAndNot:)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1619
		OP_LOOP( &=~ )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1620
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1621
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1622
	    if (ruleSymbol == @symbol(bitOr:)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1623
		OP_LOOP( |= )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1624
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1625
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1626
	    if (ruleSymbol == @symbol(bitOrNot:)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1627
		OP_LOOP( |=~ )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1628
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1629
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1630
	    if (ruleSymbol == @symbol(copy)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1631
		OP_LOOP( = )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1632
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1633
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1634
	    if (ruleSymbol == @symbol(copyNot)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1635
		OP_LOOP( =~ )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1636
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1637
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1638
	    if (ruleSymbol == @symbol(+)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1639
		OP_LOOP_BYTES( += )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1640
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1641
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1642
	    if (ruleSymbol == @symbol(-)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1643
		OP_LOOP_BYTES( -= )
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1644
		RETURN (self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1645
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1646
	}
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1647
    }
5549
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1648
#undef OP_LOOP_BYTES
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1649
#undef OP_LOOP
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1650
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1651
%}.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1652
    ruleSymbol == #copy ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1653
	self replaceFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1654
	^ self
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1655
    ].
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1656
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1657
    srcIdx := sourceStart.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1658
    dstStart to:dstEnd do:[:dstIdx |
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1659
	self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:(sourceBytes at:srcIdx)).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1660
	srcIdx := srcIdx + 1.
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1661
    ].
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1662
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1663
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1664
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1665
	bitBlitBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1666
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1667
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#bitXor:
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1668
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1669
	bitBlitBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#bitAnd:
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1670
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1671
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1672
     #[255 0 0 0 0 0 0 0]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1673
	bitBlitBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1 rule:#+
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1674
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1675
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 1 1 1 1] startingAt:1 rule:#+
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  1676
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1677
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1678
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1679
	bitBlitBytesFrom:1 to:4 with:#[1 1 1 1 2 2 2 2] startingAt:5 rule:#copyNot
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1680
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1681
     #[1 2 3 4 5 6 7 8]
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  1682
	bitBlitBytesFrom:1 to:8 with:(1 to:8) startingAt:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1683
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1684
!
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1685
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1686
bitBlitBytesFrom:dstStart to:dstEnd withConstant:sourceByte rule:ruleSymbol
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1687
    "perform a special case of an aligned bitBlit operation.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1688
     Bytes in the receiver from dstStart to dstEnd are destructively replaced by the result
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1689
     of some logical operation, as specified by the ruleSymbol.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1690
     Valid rule symbols are:
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1691
	#copy    - trivial;  same as from:to:put:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1692
	#bitXor: - xoring;   byte[dI] = byte[dI] bitXor:sourceConst
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1693
	#bitAnd: - anding;   byte[dI] = byte[dI] bitAnd:sourceConst
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1694
	#bitOr:  - oring;    byte[dI] = byte[dI] bitOr:sourceConst
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1695
	#+       - adding;   byte[dI] = (byte[dI] + sourceConst) mod: 256
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1696
	#-       - subtract; byte[dI] = (byte[dI] - sourceConst) mod: 256
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1697
     Warning: this is a destructive operation - elements in the receiver are overwritten.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1698
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1699
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1700
    |srcIdx|
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1701
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1702
%{
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1703
    if ((__qClass(self) == ByteArray)
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1704
     && __isSmallInteger(dstStart)
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1705
     && __isSmallInteger(dstEnd)
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1706
     && __isSmallInteger(sourceByte)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1707
	unsigned char srcByte = __intVal(sourceByte);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1708
	unsigned srcWord;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1709
	unsigned char *dstP = __ByteArrayInstPtr(self)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1710
	int dstLen = __byteArraySize(self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1711
	int __dstStart = __intVal(dstStart);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1712
	int count = __intVal(dstEnd) - __dstStart + 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1713
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1714
	srcWord = (srcByte << 8) | srcByte;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1715
	srcWord = (srcWord << 16) | srcWord;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1716
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1717
	if ((__dstStart >= 1)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1718
	 && ((__dstStart + count - 1) <= dstLen)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1719
	    dstP += __dstStart - 1;
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1720
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1721
#define OP_LOOP_BYTES(OP) \
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1722
    while (count > 0) {                          \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1723
	*dstP OP srcByte;                        \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1724
	dstP++;                                  \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1725
	count--;                                 \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1726
    }
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1727
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1728
#define OP_LOOP(OP) \
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1729
    while (count >= 16) {                        \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1730
	((unsigned int *)dstP)[0] OP srcWord;    \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1731
	((unsigned int *)dstP)[1] OP srcWord;    \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1732
	((unsigned int *)dstP)[2] OP srcWord;    \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1733
	((unsigned int *)dstP)[3] OP srcWord;    \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1734
	dstP += 16;                              \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1735
	count -= 16;                             \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1736
    }                                            \
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1737
    while (count >= 4) {                         \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1738
	((unsigned int *)dstP)[0] OP srcWord;    \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1739
	dstP += 4;                               \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1740
	count -= 4;                              \
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1741
    }                                            \
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1742
    while (count > 0) {                          \
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1743
	*dstP OP srcByte;                        \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1744
	dstP++;                                  \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1745
	count--;                                 \
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1746
    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1747
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1748
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1749
	    if (ruleSymbol == @symbol(bitXor:)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1750
		OP_LOOP( ^= )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1751
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1752
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1753
	    if (ruleSymbol == @symbol(bitXorNot:)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1754
		OP_LOOP( ^=~ )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1755
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1756
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1757
	    if (ruleSymbol == @symbol(bitAnd:)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1758
		OP_LOOP( &= )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1759
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1760
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1761
	    if (ruleSymbol == @symbol(bitAndNot:)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1762
		OP_LOOP( &=~ )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1763
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1764
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1765
	    if (ruleSymbol == @symbol(bitOr:)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1766
		OP_LOOP( |= )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1767
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1768
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1769
	    if (ruleSymbol == @symbol(bitOrNot:)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1770
		OP_LOOP( |=~ )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1771
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1772
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1773
	    if (ruleSymbol == @symbol(copy)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1774
		OP_LOOP( = )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1775
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1776
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1777
	    if (ruleSymbol == @symbol(copyNot)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1778
		OP_LOOP( =~ )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1779
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1780
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1781
	    if (ruleSymbol == @symbol(+)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1782
		OP_LOOP_BYTES( += )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1783
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1784
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1785
	    if (ruleSymbol == @symbol(-)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1786
		OP_LOOP_BYTES( -= )
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1787
		RETURN (self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1788
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1789
	}
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1790
    }
5549
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1791
#undef OP_LOOP_BYTES
30a2dde72cf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5468
diff changeset
  1792
#undef OP_LOOP
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1793
%}.
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1794
    ruleSymbol == #copy ifTrue:[
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1795
	self from:dstStart to:dstEnd put:sourceByte.
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1796
	^ self
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1797
    ].
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1798
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1799
    dstStart to:dstEnd do:[:dstIdx |
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1800
	self at:dstIdx put:((self at:dstIdx) perform:ruleSymbol with:sourceByte).
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1801
    ].
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1802
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1803
    "
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1804
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1805
	bitBlitBytesFrom:1 to:3 withConstant:1 rule:#bitXor:
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1806
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1807
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitXor:
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1808
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1809
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#bitAnd:
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1810
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1811
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1812
     #[255 0 0 0 0 0 0 0]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1813
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1814
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1815
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#+
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1816
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1817
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#-
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1818
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1819
	bitBlitBytesFrom:1 to:4 withConstant:1 rule:#copyNot
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1820
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  1821
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1822
	bitBlitBytesFrom:1 to:8 withConstant:1 rule:#+
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1823
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1824
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1825
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1826
bitOrBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1827
    "replace bytes in the receiver with the result of a bitOr operation.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1828
     Warning: this is a destructive operation - elements in the receiver are overwritten."
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1829
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1830
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitOr:
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1831
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1832
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1833
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1834
	bitOrBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1835
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1836
	bitOrBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1837
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1838
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1839
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1840
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1841
bitXorBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1842
    "replace bytes in the receiver with the result of an bitXor operation.
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1843
     Warning: this is a destructive operation - elements in the receiver are overwritten."
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1844
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1845
    ^ self bitBlitBytesFrom:dstStart to:dstEnd with:sourceBytes startingAt:sourceStart rule:#bitXor:
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1846
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1847
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1848
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1849
	bitXorBytesFrom:1 to:3 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1850
     #[1 2 3 4 5 6 7 8]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1851
	bitXorBytesFrom:1 to:8 with:#[1 2 3 4 5 6 7 8] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1852
     #[1 2 3 4 5 6 7 8]
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  1853
	bitXorBytesFrom:1 to:8 with:#[1 1 1 1 1 1 1 1] startingAt:1
4919
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1854
    "
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1855
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1856
!
ba0dbdaceab1 special cased bitBlit.
Claus Gittinger <cg@exept.de>
parents: 4829
diff changeset
  1857
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  1858
compressPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1859
    "given the receiver with 8-bit pixels, compress them into aByteArray
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1860
     with nBitsPerPixel-depth pixels. The width/height-arguments are needed
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1861
     to allow for any padding. On the fly, the source bytes are translated
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1862
     using aMapByteArray (if non-nil).
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1863
     Notice that smalltalk indexing begins at 1; thus the map-index for a byte
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1864
     value of n is found in map at:(n + 1).
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1865
     Output bits are filled left-to right, i.e. the first byte in the input
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1866
     corresponds to the high bit(s) if the first byte in the input.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1867
     This method can be used to convert 8-bit image data to mono, 2-bit and 4-bit
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1868
     bitmaps.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1869
     It can also be used to compress byte-arrays into bitArrays."
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1870
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1871
%{  /* NOCONTEXT */
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1872
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1873
    REGISTER unsigned char *src, *dst;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1874
    REGISTER int wrun;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1875
    unsigned char *dstNext;
1472
abaa73dc0e9a check for destination overrun
Claus Gittinger <cg@exept.de>
parents: 1459
diff changeset
  1876
    unsigned char *dstEnd;
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1877
    int bytesPerRow, mask, shift0, shift;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1878
    int w, h, hrun;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1879
    int srcBytes, dstBytes;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1880
    int bitsPerPixel;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1881
    int bits;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1882
    int ncells;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1883
    unsigned char *map;
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1884
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1885
    if ((__qClass(self) == @global(ByteArray))
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  1886
     && (__qClass(aByteArray) == @global(ByteArray))
249
claus
parents: 221
diff changeset
  1887
     && __isSmallInteger(nBitsPerPixel)
claus
parents: 221
diff changeset
  1888
     && __bothSmallInteger(height, width)) {
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1889
	if ((aMapByteArray != nil)
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1890
	 && (__Class(aMapByteArray) == @global(ByteArray))) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1891
	    map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1892
	} else {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1893
	    map = (unsigned char *)0;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1894
	}
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1895
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1896
	bitsPerPixel = __intVal(nBitsPerPixel);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1897
	w = __intVal(width);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1898
	h = __intVal(height);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1899
	src = __ByteArrayInstPtr(self)->ba_element;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1900
	dst = __ByteArrayInstPtr(aByteArray)->ba_element;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1901
	dstEnd = dst + __byteArraySize(aByteArray);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1902
	switch (bitsPerPixel) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1903
	    case 1:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1904
		mask = 0x01;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1905
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1906
	    case 2:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1907
		mask = 0x03;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1908
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1909
	    case 4:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1910
		mask = 0x0F;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1911
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1912
	    case 8:
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1913
		mask = 0xFF;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1914
		break;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1915
	    default:
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  1916
		console_printf("invalid depth in compressPixels\n");
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1917
		goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1918
	}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1919
	if (map) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1920
	    /*
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1921
	     * if a map is present, it must have entries for
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1922
	     * all possible byte-values (i.e. its size must be >= 256)
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1923
	     */
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1924
	    if ((__qSize(aMapByteArray) - OHDR_SIZE) < 256) {
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  1925
		console_printf("invalid map in compressPixels\n");
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1926
		goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1927
	    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1928
	}
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1929
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1930
	bytesPerRow = (w * bitsPerPixel + 7) / 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1931
	dstBytes = bytesPerRow * h;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1932
	srcBytes = w * h;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  1933
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1934
	if ((__byteArraySize(self) >= srcBytes)
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1935
	 && (__byteArraySize(aByteArray) >= dstBytes)) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1936
	    for (hrun=h; hrun; hrun--) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1937
		dstNext = dst + bytesPerRow;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1938
		bits = 0; shift = 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1939
		if (map) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1940
		    for (wrun=w; wrun; wrun--) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1941
			bits = (bits << bitsPerPixel) | (map[*src++] & mask);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1942
			shift -= bitsPerPixel;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1943
			if (shift == 0) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1944
			    if (dst == dstEnd) goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1945
			    *dst++ = bits;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1946
			    bits = 0; shift = 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1947
			}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1948
		    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1949
		} else {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1950
		    for (wrun=w; wrun; wrun--) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1951
			bits = (bits << bitsPerPixel) | (*src++ & mask);
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1952
			shift -= bitsPerPixel;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1953
			if (shift == 0) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1954
			    if (dst == dstEnd) goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1955
			    *dst++ = bits;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1956
			    bits = 0; shift = 8;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1957
			}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1958
		    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1959
		}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1960
		if (shift != 8) {
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1961
		    if (dst == dstEnd) goto fail;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1962
		    *dst = bits;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1963
		}
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1964
		dst = dstNext;
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1965
	    }
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1966
	    RETURN ( self );
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1967
	}
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1968
    }
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1969
fail: ;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  1970
%}.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1971
    self primitiveFailed
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1972
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1973
    "Example1:
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1974
     compress 1 byte-per-pixel bitmap to 1-bit-per-pixel bitmap
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1975
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1976
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1977
     |inBits outBits|
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1978
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1979
     inBits := #[0 0 0 0 1 1 1 1
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1980
		 0 0 1 1 0 0 1 1
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1981
		 0 1 0 1 0 1 0 1
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1982
		 1 1 1 1 0 0 0 0].
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1983
     outBits := ByteArray new:4.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1984
     inBits compressPixels:1 width:8 height:4
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  1985
		    into:outBits mapping:nil.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1986
     outBits inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1987
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1988
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1989
    "Example2:
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1990
     compress byte-array into a bitArray, translating 99 to 0-bits,
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1991
     and 176 to 1-bits. (just a stupid example)
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1992
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1993
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1994
     |inBits outBits map|
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1995
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1996
     inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1997
     map := ByteArray new:256.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1998
     map at:176+1 put:1.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  1999
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2000
     outBits := ByteArray new:2.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2001
     inBits compressPixels:1 width:16 height:1
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2002
		    into:outBits mapping:map.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2003
     outBits inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2004
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2005
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2006
    "Example3:
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2007
     compress byte-array into a bitArray, translating everything below 128 to 0-bits,
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2008
     and 128 to 255 to 1-bits.99 to 0-bits (another stupid example)
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2009
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2010
    "
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2011
     |inBits outBits map|
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2012
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2013
     inBits := #[176 176 176 176 99 99 99 99 176 176 99 99 176 99 176 99].
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2014
     map := ByteArray new:256.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2015
     map atAll:(128+1 to:255+1) put:1.
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2016
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2017
     outBits := ByteArray new:2.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2018
     inBits compressPixels:1 width:16 height:1
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2019
		    into:outBits mapping:map.
129
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2020
     outBits inspect
e451571780b7 added compressPixels;
claus
parents: 92
diff changeset
  2021
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2022
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2023
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2024
expandPixels:nBitsPerPixel width:width height:height into:aByteArray mapping:aMapByteArray
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2025
    "given the receiver with nBitsPerPixel-depth pixels, expand them into
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2026
     aByteArray with 8-bit pixels. The width/height-arguments are needed
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2027
     to skip any padded src-bits. On the fly, the destination pixels
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2028
     are translated using aMapByteArray (if non-nil).
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2029
     Input bits are read left-to right, i.e. the first byte in the output
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2030
     corresponds to the high bit(s) in the inputs first byte.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2031
     This is used to display mono, 2-bit and 4-bit bitmaps on grey-scale/color
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2032
     machines. With nBitsPerPixel==8, this is a translate operation.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2033
     Notice that smalltalk indexing begins at 1; thus the map-index for a byte
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2034
     value of n is found in map at:(n + 1).
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2035
     It can also be used to expand bit-arrays into byteArrays.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2036
     This method is specialized for ByteArray arguments - it will not handle
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2037
     anything else."
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2038
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2039
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2040
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2041
    REGISTER unsigned char *src, *dst;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2042
    REGISTER int wrun;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2043
    unsigned char *srcNext;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2044
    int bytesPerRow, mask, shift0, shift;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2045
    int w, h, hrun;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2046
    int srcBytes, dstBytes;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2047
    int bitsPerPixel;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2048
    int bits;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2049
    int ncells;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2050
    unsigned char *map;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2051
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2052
    if ((__qClass(self) == @global(ByteArray))
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2053
     && (__qClass(aByteArray) == @global(ByteArray))
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2054
     && __isSmallInteger(nBitsPerPixel)
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2055
     && __bothSmallInteger(height, width)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2056
	if ((aMapByteArray != nil)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2057
	 && (__Class(aMapByteArray) == @global(ByteArray))) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2058
	    map = __ByteArrayInstPtr(aMapByteArray)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2059
	} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2060
	    map = (unsigned char *)0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2061
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2062
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2063
	bitsPerPixel = __intVal(nBitsPerPixel);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2064
	w = __intVal(width);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2065
	h = __intVal(height);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2066
	src = __ByteArrayInstPtr(self)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2067
	dst = __ByteArrayInstPtr(aByteArray)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2068
	switch (bitsPerPixel) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2069
	    case 1:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2070
		mask = 0x01;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2071
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2072
	    case 2:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2073
		mask = 0x03;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2074
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2075
	    case 4:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2076
		mask = 0x0F;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2077
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2078
	    case 8:
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2079
		mask = 0xFF;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2080
		break;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2081
	    default:
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2082
		console_printf("expandPixels: invalid depth\n");
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2083
		goto fail;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2084
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2085
	ncells = mask + 1;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2086
	if (map) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2087
	    /*
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2088
	     * if a map is present, it must have the correct size
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2089
	     * (i.e. 2 raisedTo:nBitsPerPixel)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2090
	     */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2091
	    if ((__qSize(aMapByteArray) - OHDR_SIZE) < ncells) {
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2092
		console_printf("expandPixels: invalid map\n");
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2093
		goto fail;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2094
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2095
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2096
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2097
	bytesPerRow = (w * bitsPerPixel + 7) / 8;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2098
	shift0 = 8 - bitsPerPixel;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2099
	srcBytes = bytesPerRow * h;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2100
	dstBytes = w * h;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2101
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2102
	if ((__byteArraySize(self) >= srcBytes)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2103
	 && (__byteArraySize(aByteArray) >= dstBytes)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2104
	    for (hrun=h; hrun; hrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2105
		srcNext = src + bytesPerRow;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2106
		shift = shift0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2107
		if (map) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2108
		    if (shift0 == 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2109
			/* translate only */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2110
			for (wrun=w; wrun; wrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2111
			    bits = *src++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2112
			    *dst++ = map[bits];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2113
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2114
		    } else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2115
			for (wrun=w; wrun; wrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2116
			    if (shift == shift0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2117
				bits = *src++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2118
			    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2119
			    *dst++ = map[(bits >> shift) & mask];
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2120
			    shift -= bitsPerPixel;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2121
			    if (shift < 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2122
				shift = shift0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2123
			    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2124
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2125
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2126
		} else {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2127
		    for (wrun=w; wrun; wrun--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2128
			if (shift == shift0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2129
			    bits = *src++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2130
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2131
			*dst++ = (bits >> shift) & mask;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2132
			shift -= bitsPerPixel;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2133
			if (shift < 0) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2134
			    shift = shift0;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2135
			}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2136
		    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2137
		}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2138
		src = srcNext;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2139
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2140
	    RETURN ( self );
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2141
	}
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2142
	console_printf("expandPixels: buffer size: self:%d expect at least:%d\n",
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2143
		__byteArraySize(self), srcBytes);
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2144
	console_printf("expandPixels: buffer size: arg:%d expect at least:%d\n",
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2145
		__byteArraySize(aByteArray), dstBytes);
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2146
    }
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2147
    console_printf("expandPixels: invalid args\n");
1527
af119b16aa16 better handle the translate-only case in #expandPixels:
ca
parents: 1505
diff changeset
  2148
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2149
fail: ;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2150
%}.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2151
    self primitiveFailed
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2152
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2153
    "Example1:
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2154
     expand 1-bit-per-pixel bitmap into a 1byte-per-pixel byteArray
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2155
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2156
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2157
     |inBits outBits|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2158
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2159
     inBits := #[2r11110000
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2160
		 2r11001100
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2161
		 2r01010101
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2162
		 2r00001111].
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2163
     outBits := ByteArray new:(8*4).
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2164
     inBits expandPixels:1 width:8 height:4
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2165
		    into:outBits mapping:nil.
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2166
     outBits inspect
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2167
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2168
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2169
    "Example2:
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2170
     expand bit-array into a byteArray, translating 0-bits to 99,
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2171
     1-bits to 176. (just a stupid example)
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2172
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2173
    "
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2174
     |inBits outBits|
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2175
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2176
     inBits := #[2r11110000 2r11001100].
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2177
     outBits := ByteArray new:16.
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2178
     inBits expandPixels:1 width:16 height:1
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2179
		    into:outBits mapping:#[99 176].
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2180
     outBits inspect
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2181
    "
4978
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2182
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2183
    "This Can also be used to extract nibbles ..."
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2184
    "
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2185
     |inBits outBits|
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2186
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2187
     inBits := #[ 16r12 16r34 16r56 16r78 16r9A 16rBC 16rDE 16rF0 ].
4978
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2188
     outBits := ByteArray new:(inBits size * 2).
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2189
     inBits expandPixels:4 width:outBits size height:1 into:outBits mapping:nil.
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2190
     outBits inspect
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2191
    "
0d75a92f1e56 comment
Claus Gittinger <cg@exept.de>
parents: 4969
diff changeset
  2192
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2193
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2194
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2195
invert
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2196
    "invert all bytes - used with image manipulations
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2197
     written as a primitive for speed.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2198
     Q: is this really needed ?"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2199
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2200
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2201
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2202
    REGISTER unsigned char *dst;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2203
    REGISTER unsigned long *ldst;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2204
    REGISTER int cnt;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2205
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2206
    if (__qClass(self) == @global(ByteArray)) {
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2207
	cnt = __byteArraySize(self);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2208
	dst = __ByteArrayInstPtr(self)->ba_element;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2209
	if (! ((INT)dst & (sizeof(long)-1))) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2210
	    ldst = (unsigned long *)dst;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2211
	    while (cnt >= (sizeof(long))*4) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2212
		ldst[0] = ~(ldst[0]);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2213
		ldst[1] = ~(ldst[1]);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2214
		ldst[2] = ~(ldst[2]);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2215
		ldst[3] = ~(ldst[3]);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2216
		ldst += 4;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2217
		cnt -= (sizeof(long))*4;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2218
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2219
	    while (cnt >= sizeof(long)) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2220
		*ldst = ~(*ldst);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2221
		ldst++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2222
		cnt -= sizeof(long);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2223
	    }
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2224
	    dst = (unsigned char *)ldst;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2225
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2226
	while (cnt--) {
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2227
	    *dst = ~(*dst);
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2228
	    dst++;
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2229
	}
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2230
	RETURN ( self );
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2231
    }
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2232
%}.
5439
956c8095c4ff rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5425
diff changeset
  2233
    self bitBlitBytesFrom:1 to:self size withConstant:16rFF rule:#bitXor:
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2234
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2235
    "
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2236
     #[1 2 3 4 5 6 7 8 9 10] copy invert
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2237
     #[1 2 3 4 5 6 7 8 9 10] copy
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2238
	bitBlitBytesFrom:1 to:10 withConstant:16rFF rule:#bitXor:
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2239
    "
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2240
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2241
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2242
reverse
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2243
    "reverse the order of my elements inplace -
7338
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7245
diff changeset
  2244
     WARNING: this is a destructive operation, which modifies the receiver.
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2245
	      Please use reversed (with a d) for a functional version.
7338
7a1a2514b6aa comment
Claus Gittinger <cg@exept.de>
parents: 7245
diff changeset
  2246
     Written as a primitive for speed on image manipulations (mirror)"
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2247
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2248
%{  /* NOCONTEXT */
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2249
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2250
    REGISTER unsigned char *p1, *p2;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2251
    REGISTER int cnt;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2252
    REGISTER unsigned t;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2253
    OBJ cls;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2254
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2255
    if (__qClass(self) == @global(ByteArray)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2256
	cnt = __byteArraySize(self);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2257
	p1 = __ByteArrayInstPtr(self)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2258
	p2 = p1 + cnt - 1;
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2259
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2260
#if defined(__BSWAP)
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2261
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2262
	 * can we use the bswap instruction ?
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2263
	 * notice - not all CPUs have it (the HAS_BSWAP checks this).
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2264
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2265
	if (__HAS_BSWAP()
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2266
	 && ((cnt & 3) == 0)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2267
	    unsigned int *ip1, *ip2;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2268
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2269
	    ip1 = (unsigned int *)p1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2270
	    ip2 = (unsigned int *)(p2 - 3);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2271
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2272
	    ip2 -= 7;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2273
	    while (ip1 <= ip2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2274
		int t1, t2;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2275
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2276
		t1 = ip1[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2277
		t2 = ip2[7];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2278
		ip2[7] = __BSWAP(t1);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2279
		ip1[0] = __BSWAP(t2);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2280
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2281
		t1 = ip1[1];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2282
		t2 = ip2[6];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2283
		ip2[6] = __BSWAP(t1);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2284
		ip1[1] = __BSWAP(t2);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2285
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2286
		t1 = ip1[2];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2287
		t2 = ip2[5];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2288
		ip2[5] = __BSWAP(t1);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2289
		ip1[2] = __BSWAP(t2);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2290
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2291
		t1 = ip1[3];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2292
		t2 = ip2[4];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2293
		ip2[4] = __BSWAP(t1);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2294
		ip1[3] = __BSWAP(t2);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2295
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2296
		ip1 += 4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2297
		ip2 -= 4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2298
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2299
	    ip2 += 7;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2300
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2301
	    while (ip1 < ip2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2302
		int t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2303
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2304
		t = __BSWAP(*ip1);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2305
		*ip1++ = __BSWAP(*ip2);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2306
		*ip2-- = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2307
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2308
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2309
	    if (ip1 == ip2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2310
		int t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2311
		t = *ip1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2312
		t = __BSWAP(t);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2313
		*ip1 = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2314
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2315
	    RETURN ( self );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2316
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8623
diff changeset
  2317
#endif /* __i386__ && __GNUC__ */
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2318
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2319
	p2 -= 7;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2320
	while (p1 <= p2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2321
	    t = p1[0];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2322
	    p1[0] = p2[7];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2323
	    p2[7] = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2324
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2325
	    t = p1[1];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2326
	    p1[1] = p2[6];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2327
	    p2[6] = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2328
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2329
	    t = p1[2];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2330
	    p1[2] = p2[5];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2331
	    p2[5] = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2332
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2333
	    t = p1[3];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2334
	    p1[3] = p2[4];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2335
	    p2[4] = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2336
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2337
	    p1 += 4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2338
	    p2 -= 4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2339
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2340
	p2 += 7;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2341
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2342
	while (p1 < p2) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2343
	    t = *p1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2344
	    *p1++ = *p2;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2345
	    *p2-- = t;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2346
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2347
	RETURN ( self );
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2348
    }
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2349
%}.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2350
    ^ super reverse
2585
6c25622320aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2579
diff changeset
  2351
6c25622320aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2579
diff changeset
  2352
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2353
     #[1 2 3 4 5] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2354
     #[1 2 3 4] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2355
     #[1 2 3 4 5] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2356
     #[1 2 3 4 5 6] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2357
     #[1 2 3 4 5 6 7] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2358
     #[1 2 3 4 5 6 7 8] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2359
     #[1 2 3 4 5 6 7 8 9] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2360
     #[1 2 3 4 5 6 7 8 9 10] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2361
     #[1 2 3 4 5 6 7 8 9 10 11 12] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2362
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2363
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] reverse
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2364
     (1 to:255) asByteArray reverse
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2365
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2366
     1 to:1024 do:[:i|
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2367
	|bytes test rBytes|
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2368
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2369
	bytes := ((1 to:i) asArray collect:[:i | i bitAnd:255]) asByteArray.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2370
	test := ((i to:1 by:-1) asArray collect:[:i | i bitAnd:255]) asByteArray.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2371
	rBytes := bytes copy.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2372
	rBytes reverse ~= test ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2373
	    self halt
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2374
	].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2375
	rBytes := bytes copy.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2376
	rBytes reverse reverse ~= bytes ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2377
	    self halt
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2378
	]
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2379
     ].
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2380
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2381
     Time millisecondsToRun:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2382
	10000000 timesRepeat:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2383
	    #[1 2 3 4 5 6 7 8] reverse
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2384
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2385
     ]
4924
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2386
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2387
     |b|
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2388
     b := (0 to:255) asByteArray.
9bec9689f646 reverse - 50% speedup on i386; 30% on all others
Claus Gittinger <cg@exept.de>
parents: 4919
diff changeset
  2389
     Time millisecondsToRun:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2390
	10000000 timesRepeat:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2391
	    b reverse
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2392
	]
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2393
     ]
2585
6c25622320aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2579
diff changeset
  2394
    "
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2395
!
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2396
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2397
swapBytes
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2398
    "swap bytes inplace -
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2399
     Expects that the receiver has an even number of bytes; 
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2400
     if not, only the pairs excluding the last byte are swapped.
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2401
     written as a primitive for speed on image grabbing (if display order is different)."
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2402
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2403
%{  /* NOCONTEXT */
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2404
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2405
    REGISTER unsigned char *p;
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2406
    REGISTER int cnt;
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2407
    REGISTER unsigned t;
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2408
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1082
diff changeset
  2409
    if (__qClass(self) == @global(ByteArray)) {
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2410
        cnt = __byteArraySize(self);
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2411
        cnt = cnt & ~1; /* make it even */
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2412
        p = __ByteArrayInstPtr(self)->ba_element;
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2413
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2414
        while (cnt >= sizeof(INT)) {
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2415
            unsigned INT i = ((unsigned INT *)p)[0];
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2416
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2417
#if __POINTER_SIZE__ == 8
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2418
            i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8);
4274
52fe89c37b2e tuned wordAt/doubleWordAt & atPut methods
Claus Gittinger <cg@exept.de>
parents: 4269
diff changeset
  2419
#else
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2420
            i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8);
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2421
#endif /* __POINTER_SIZE__ */
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2422
            ((unsigned INT *)p)[0] = i;
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2423
            p += sizeof(INT);
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2424
            cnt -= sizeof(INT);
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2425
        }
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2426
        while (cnt > 0) {
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2427
            unsigned short s;
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2428
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2429
            s = ((unsigned short *)p)[0];
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2430
            s = (s >> 8) | (s << 8);
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2431
            ((unsigned short *)p)[0] = s;
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2432
            p += 2;
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2433
            cnt -= 2;
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2434
        }
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2435
        RETURN ( self );
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2436
    }
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2437
%}.
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2438
    ^ super swapBytes "/ rubbish - there is no one currenly
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2439
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2440
    "
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2441
     #[1 2 3 4 5 6 7 8 9 10] copy swapBytes     -> #[2 1 4 3 6 5 8 7 10 9]
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2442
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes  -> #[2 1 4 3 6 5 8 7 10 9 11]
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2443
     #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes   
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2444
    "
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2445
!
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2446
4983
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2447
swapIndex:i1 and:i2
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2448
   "spap the bytes with i1 and i2"
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2449
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2450
%{  /* NOCONTEXT */
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2451
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2452
    REGISTER unsigned char *p;
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2453
    unsigned int __i1, __i2;
15330
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2454
    int sz;
4983
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2455
    unsigned int t;
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2456
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2457
    if (__qClass(self) == @global(ByteArray) && __bothSmallInteger(i1, i2)) {
15330
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2458
        __i1 = __intVal(i1) - 1;
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2459
        __i2 = __intVal(i2) - 1;
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2460
        sz = __byteArraySize(self);
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2461
        p = __ByteArrayInstPtr(self)->ba_element;
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2462
        if (__i1 < sz && __i2 < sz) {
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2463
            t = p[__i1];
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2464
            p[__i1] = p[__i2];
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2465
            p[__i2] = t;
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2466
        }
6e9281a08730 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 15324
diff changeset
  2467
        RETURN ( self );
4983
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2468
    }
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2469
%}.
11265
dd57cc0a379b comment
Claus Gittinger <cg@exept.de>
parents: 11263
diff changeset
  2470
    ^ super swapIndex:i1 and:i2 "/ rubbish - there is no one currently
4983
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2471
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2472
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2473
     #[1 2 3 4 5 6 7 8 9 10] copy swapIndex:1 and:10
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2474
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapIndex:5 and:6
4983
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2475
    "
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2476
!
07e6aab900d9 #swapIndex:and:
Stefan Vogel <sv@exept.de>
parents: 4978
diff changeset
  2477
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2478
swapLongs
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2479
    "swap long bytes inplace
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2480
     - any partial longs at the end are not swapped."
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2481
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2482
    self swapLongsFrom:1 to:self size
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2483
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2484
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2485
     #[1 2 3 4 5 6 7 8 9] copy swapLongs
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2486
     #[1 2 3 4 5 6 7 8 9 10] copy swapLongs
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2487
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapLongs
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2488
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy swapLongs
930
dd2ba4051d6a added swapBytes & swapLongs (needed when grabbing depth8/depth16 image from screen)
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
  2489
    "
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2490
!
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2491
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2492
swapLongsFrom:startIndex to:endIndex
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2493
    "swap longs inplace
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2494
     - any partial longs at the end are not swapped.
4367
3d481db099ec oops - swapLongsFrom:to: was wrong
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2495
     Swapping is from startIndex to (exclusiv) endIndex;
3d481db099ec oops - swapLongsFrom:to: was wrong
Claus Gittinger <cg@exept.de>
parents: 4365
diff changeset
  2496
     indexing starts at 1."
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2497
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2498
%{  /* NOCONTEXT */
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2499
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2500
    REGISTER unsigned char *p;
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2501
    REGISTER int limit;
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2502
    REGISTER unsigned t;
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2503
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2504
    if ((__qClass(self) == @global(ByteArray))
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2505
     && __isSmallInteger(startIndex)
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2506
     && __isSmallInteger(endIndex)) {
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2507
	int __idx = __intVal(startIndex);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2508
	int __endIdx = __intVal(endIndex);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2509
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2510
	limit = __byteArraySize(self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2511
	if (__endIdx < limit) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2512
	    limit = __endIdx;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2513
	}
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2514
	p = __ByteArrayInstPtr(self)->ba_element;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2515
	p = p + __idx - 1;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2516
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2517
	limit = limit - 4 + 1;
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2518
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2519
#if defined(__BSWAP)
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2520
	/*
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2521
	 * can we use the bswap instruction ?
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2522
	 * notice - not all CPUs have it (the HAS_BSWAP checks this).
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2523
	 */
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2524
	if (__HAS_BSWAP()
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2525
	 && (((unsigned int)p & 3) == 0)) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2526
	    unsigned int *ip;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2527
	    ip = (unsigned int *)p;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2528
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2529
	    while (__idx <= limit) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2530
		*ip = __BSWAP(*ip);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2531
		ip++;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2532
		__idx += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2533
	    }
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2534
	    RETURN (self);
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2535
	}
4927
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2536
#endif /* __BSWAP */
9d67bf3f4009 made the BSWAP macro public
Claus Gittinger <cg@exept.de>
parents: 4925
diff changeset
  2537
4969
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2538
	while (__idx <= limit) {
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2539
	    t = p[0];
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2540
	    p[0] = p[3];
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2541
	    p[3] = t;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2542
	    t = p[1];
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2543
	    p[1] = p[2];
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2544
	    p[2] = t;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2545
	    p += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2546
	    __idx += 4;
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2547
	}
bd9f02a6a74f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4945
diff changeset
  2548
	RETURN ( self );
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2549
    }
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2550
%}.
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2551
    ^ super swapLongsFrom:startIndex to:endIndex "/ rubbish - there is no one currenly
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2552
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2553
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2554
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:3
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2555
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:4
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2556
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:5
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2557
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:6
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2558
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:7
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2559
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:1 to:8
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2560
     #[1 2 3 4 5 6 7 8 9 10] copy swapLongsFrom:1 to:11
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2561
     #[1 2 3 4 5 6 7 8 9 10 11] copy swapLongsFrom:1 to:12
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2562
     #[1 2 3 4 5 6 7 8 9 10 11 12] copy swapLongsFrom:1 to:13
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2563
     #[1 2 3 4 5 6 7 8 9] copy swapLongsFrom:5 to:10
4365
da0d377442c8 added #swapLongsFrom:to:
Claus Gittinger <cg@exept.de>
parents: 4275
diff changeset
  2564
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2565
! !
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2566
10028
f43a291eabd6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9659
diff changeset
  2567
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2568
!ByteArray methodsFor:'printing & storing'!
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2569
13078
7934a86b395b Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 12932
diff changeset
  2570
displayOn:aGCOrStream
1244
dc9dd731258c commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  2571
    "return a printed representation of the receiver for displaying"
dc9dd731258c commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  2572
13078
7934a86b395b Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 12932
diff changeset
  2573
    (self class == ByteArray and:[aGCOrStream isStream or:[aGCOrStream == Transcript]]) ifTrue:[
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2574
	self storeOn:aGCOrStream.
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2575
	^ self
6513
d7bc1d1dab4b displayString fix for subclasses
Claus Gittinger <cg@exept.de>
parents: 6125
diff changeset
  2576
    ].
13078
7934a86b395b Implement display with #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents: 12932
diff changeset
  2577
    ^ super displayOn:aGCOrStream
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2578
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2579
    "Created: 25.10.1995 / 13:33:26 / cg"
1244
dc9dd731258c commentary
Claus Gittinger <cg@exept.de>
parents: 1230
diff changeset
  2580
    "Modified: 22.4.1996 / 12:54:06 / cg"
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2581
!
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2582
7172
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2583
hexPrintOn:aStream
7245
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2584
    "print as hex string, eg: 'FF0243'.
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2585
     This string can be used in #fromHexString: to recreate the byteArray"
7172
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2586
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2587
    self do:[:byte|
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2588
	byte printOn:aStream base:16 size:2 fill:$0.
7172
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2589
    ].
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2590
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2591
    "
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2592
      #[1 2 3 4 10 17] hexPrintOn:Transcript
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2593
    "
7245
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2594
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2595
    "
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2596
     |s|
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2597
     s := String streamContents:[:s | #[1 2 3 4 10 17] hexPrintOn:s].
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2598
     ByteArray fromHexString:s
7245
0a085a2048e1 comments
Claus Gittinger <cg@exept.de>
parents: 7194
diff changeset
  2599
    "
7172
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2600
!
0eae969b6ff5 #hexPrintOn:
Stefan Vogel <sv@exept.de>
parents: 7117
diff changeset
  2601
9379
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2602
hexPrintOn:aStream withSeparator:aSeparatorStringOrCharacter
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2603
    "print as hex string, eg: 'FF:02:43'"
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2604
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2605
    self do:[:byte|
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2606
	byte printOn:aStream base:16 size:2 fill:$0.
9379
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2607
    ] separatedBy:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2608
	aSeparatorStringOrCharacter printOn:aStream
9379
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2609
    ].
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2610
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2611
    "
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2612
      #[1 2 3 4 10 17] hexPrintOn:Transcript withSeparator:$:
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2613
    "
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2614
!
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2615
9368
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2616
hexPrintString
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2617
    "print as hex string, eg: 'FF0243'.
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2618
     This string can be used in #fromHexString: to recreate the byteArray"
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2619
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2620
    |s|
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2621
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2622
    s := '' writeStream.
12932
f9f432d64dd9 changed: #hexPrintString
Claus Gittinger <cg@exept.de>
parents: 12879
diff changeset
  2623
    self do:[:byteOrCharacter |
13703
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2624
	|byte|
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2625
	byte := byteOrCharacter isCharacter
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2626
		    ifTrue:[byteOrCharacter codePoint]
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2627
		    ifFalse:[byteOrCharacter].
Claus Gittinger <cg@exept.de>
parents: 13219
diff changeset
  2628
	byte printOn:s base:16 size:2 fill:$0.
9368
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2629
    ].
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2630
    ^ s contents.
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2631
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2632
    "
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2633
      #[1 2 3 4 10 17] hexPrintString
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2634
    "
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2635
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2636
    "
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2637
     ByteArray fromHexString:#[1 2 3 4 10 17] hexPrintString
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2638
    "
12932
f9f432d64dd9 changed: #hexPrintString
Claus Gittinger <cg@exept.de>
parents: 12879
diff changeset
  2639
f9f432d64dd9 changed: #hexPrintString
Claus Gittinger <cg@exept.de>
parents: 12879
diff changeset
  2640
    "Modified: / 03-07-2010 / 01:59:19 / cg"
9368
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2641
!
c5a70cfa0f18 New: #hexPrintString
Stefan Vogel <sv@exept.de>
parents: 8996
diff changeset
  2642
9379
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2643
hexPrintStringWithSeparator:aSeparatorStringOrCharacter
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2644
    "print as hex string, eg: 'FF:02:43'."
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2645
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2646
    |s|
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2647
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2648
    s := '' writeStream.
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2649
    self hexPrintOn:s withSeparator:aSeparatorStringOrCharacter.
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2650
    ^ s contents.
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2651
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2652
    "
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2653
      #[1 2 3 4 10 17] hexPrintStringWithSeparator:$:
11860
6c07323b8fa2 comment
Claus Gittinger <cg@exept.de>
parents: 11796
diff changeset
  2654
      #[1 2 3 4 10 17] hexPrintStringWithSeparator:Character space
9379
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2655
    "
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2656
!
b7e6cbe411f7 #hexPrintXX:withSeparator:
Stefan Vogel <sv@exept.de>
parents: 9368
diff changeset
  2657
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2658
printOn:aStream
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2659
    "append a printed representation to aStream"
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2660
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2661
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2662
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2663
    "/ care for subclasses
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2664
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2665
	aStream nextPutAll:'#['.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2666
	self
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2667
	    do:[:byte | byte printOn:aStream]
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2668
	    separatedBy:[aStream space].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2669
	aStream nextPut:$].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2670
	^ self
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2671
    ].
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2672
    ^ super printOn:aStream
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2673
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2674
    "
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2675
     #[1 2 3 4 5] printOn:Transcript
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2676
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2677
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2678
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2679
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2680
     #[1 2 3 4 5] printString
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2681
    "
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2682
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2683
    "Modified: / 12.9.1997 / 22:11:33 / cg"
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2684
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2685
!
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2686
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2687
printOn:aStream base:radix
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2688
    "append a printed representation to aStream in the given number base."
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2689
6125
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2690
    ^ self printOn:aStream base:radix showRadix:false
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2691
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2692
    "
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2693
     #[1 2 3 4 5] printOn:Transcript base:2
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2694
     'Hello World' printOn:Transcript base:2
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2695
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2696
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2697
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2698
     #[1 2 3 4 5] printString
6125
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2699
    "
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2700
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2701
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2702
    "Modified: / 31.10.2001 / 09:43:56 / cg"
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2703
!
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2704
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2705
printOn:aStream base:radix showRadix:showRadix
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2706
    "append a printed representation to aStream in the given number base."
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2707
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2708
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2709
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2710
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2711
	"/ care for subclasses
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2712
	aStream nextPutAll:'#['.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2713
	self
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2714
	    do:[:byte | byte printOn:aStream base:radix showRadix:showRadix]
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2715
	    separatedBy:[aStream space].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2716
	aStream nextPut:$].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2717
	^ self
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2718
    ].
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2719
    ^ self printOn:aStream
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2720
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2721
    "
5019
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2722
     #[1 2 3 4 5] printOn:Transcript base:2
4cd8b02e26e1 Redefine #PrintOn: to print in #[] notation.
Stefan Vogel <sv@exept.de>
parents: 4983
diff changeset
  2723
     'Hello World' printOn:Transcript base:2
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2724
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2725
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2726
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2727
     #[1 2 3 4 5] printString
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2728
    "
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2729
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2730
    "Modified: / 12.9.1997 / 22:11:33 / cg"
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2731
    "Modified: / 17.3.1999 / 17:01:31 / stefan"
6125
f5ca6209cd4d + printOn:radix:showRadix:
Claus Gittinger <cg@exept.de>
parents: 5901
diff changeset
  2732
    "Created: / 31.10.2001 / 09:43:41 / cg"
4050
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2733
!
463c0355416d New method printOn:base:
Stefan Vogel <sv@exept.de>
parents: 4019
diff changeset
  2734
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2735
storeOn:aStream
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2736
    "append a printed representation from which the receiver can be
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2737
     reconstructed to aStream. (reimplemented to make it look better)"
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2738
12487
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2739
    |cls|
d0c7ee0b0fb4 more immutability stuff
Claus Gittinger <cg@exept.de>
parents: 12466
diff changeset
  2740
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2741
    ((cls := self class) == ByteArray or:[cls == ImmutableByteArray]) ifTrue:[
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2742
	"/ care for subclasses
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2743
	aStream nextPutAll:'#['.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2744
	self
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2745
	    do:[:byte | byte storeOn:aStream]
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2746
	    separatedBy:[aStream space].
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2747
	aStream nextPutAll:']'.
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2748
	^ self
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2749
    ].
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2750
    ^ super storeOn:aStream
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2751
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2752
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2753
     #[1 2 3 4 5] storeOn:Transcript
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2754
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2755
     #[1 2 3 4 5] storeString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2756
     #[1 2 3 4 5] displayString
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2757
     #[1 2 3 4 5] printString
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2758
    "
1082
b186a68fff0e category change
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  2759
2915
fdfc6c64bf60 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2898
diff changeset
  2760
    "Modified: 12.9.1997 / 22:11:33 / cg"
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2761
! !
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2762
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2763
!ByteArray methodsFor:'queries'!
1082
b186a68fff0e category change
Claus Gittinger <cg@exept.de>
parents: 1019
diff changeset
  2764
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2765
max
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2766
    "return the maximum value in the receiver -
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2767
     redefined to speedup image processing and sound-player
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2768
     (which need a fast method for this on byteArrays)"
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2769
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2770
%{  /* NOCONTEXT */
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2771
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2772
    REGISTER unsigned char *cp;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2773
    REGISTER int index, max;
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2774
    int len;
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2775
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2776
    if (__isByteArrayLike(self)) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2777
        max = 0;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2778
        index = 0;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2779
        len = __qSize(self) - OHDR_SIZE;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2780
        cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2781
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2782
        while (++index <= len) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2783
            unsigned int byte;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2784
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2785
            byte = *cp;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2786
            cp++;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2787
            if (byte > max) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2788
                max = byte;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2789
                if (byte == 255) break;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2790
            }
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2791
        }
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2792
        RETURN ( __mkSmallInteger(max) );
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2793
    }
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2794
%}.
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2795
    ^ super max
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2796
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2797
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2798
     #[1 2 3 1 2 3 1 2 19] max
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2799
    "
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  2800
!
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2801
10819
3d7bea065ca5 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10029
diff changeset
  2802
referencesAny:aCollection
10821
2b017f37f185 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10819
diff changeset
  2803
    "redefined to speed up searching when many byteArray instances are present"
2b017f37f185 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10819
diff changeset
  2804
10819
3d7bea065ca5 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10029
diff changeset
  2805
    self class == ByteArray ifTrue:[^ false].
3d7bea065ca5 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10029
diff changeset
  2806
    ^ super referencesAny:aCollection
3d7bea065ca5 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10029
diff changeset
  2807
!
3d7bea065ca5 faster referencesAny
Claus Gittinger <cg@exept.de>
parents: 10029
diff changeset
  2808
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2809
usageCounts
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2810
    "return an array filled with value-counts -
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2811
     This is needed in the bitmap/image classes to get info on color usage.
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2812
     (i.e. to build up a histogram of color usage within an image)."
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2813
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2814
    |counts|
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2815
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2816
    counts := Array basicNew:256.
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2817
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2818
%{  /* STACK: 2000 */
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2819
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2820
    REGISTER unsigned char *cp;
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2821
    REGISTER int nByte;
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2822
    REGISTER int index;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2823
    INT icounts[256];
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2824
12768
4c56c6dd923d Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents: 12719
diff changeset
  2825
    if (__isByteArrayLike(self) && __isArray(counts)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2826
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2827
	 * zero counts
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2828
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2829
	for (index=0; index<256; index++) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2830
	    icounts[index] = 0;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2831
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2832
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2833
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2834
	 * count
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2835
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2836
	nByte = __qSize(self) - OHDR_SIZE;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2837
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2838
	while (nByte--) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2839
	    icounts[*cp++]++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2840
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2841
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2842
	/*
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2843
	 * make it real counts
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2844
	 */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2845
	for (index=0; index<256; index++) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2846
	    __ArrayInstPtr(counts)->a_element[index] = __mkSmallInteger(icounts[index]);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2847
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2848
	RETURN ( counts );
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2849
    }
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2850
%}
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2851
.
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2852
    self primitiveFailed
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2853
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2854
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2855
     #[1 2 3 1 2 3 1 2 250 251 250 251 255] usageCounts
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2856
    "
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2857
!
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2858
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2859
usedValues
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2860
    "return a new ByteArray with all used values (actually a kind of Set);
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2861
     This is needed specially in the bitmap/Imageclasses to find used colors
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2862
     of an image."
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2863
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2864
%{  /* STACK: 400 */
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2865
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2866
    REGISTER unsigned char *cp;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2867
    unsigned char *endp;
563
593f73e7c52c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
  2868
    REGISTER int len;
2890
fa0418a0f896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2866
diff changeset
  2869
    OBJ result;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2870
    union {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2871
	unsigned char flags[256];
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2872
	int toForceAlignmentOfFlags;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2873
    } f;
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2874
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2875
#ifdef TO_BE_MEASURED
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2876
    int coverage = 0;
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2877
#endif
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2878
12768
4c56c6dd923d Prepare for changing superclass of CharacterArray from ByteArray to UninterpretedBytes
Stefan Vogel <sv@exept.de>
parents: 12719
diff changeset
  2879
    if (__isByteArrayLike(self)) {
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2880
	memset(f.flags, 0, sizeof(f.flags));
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2881
	len = __qSize(self) - OHDR_SIZE;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2882
	cp = &(__ByteArrayInstPtr(self)->ba_element[0]);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2883
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2884
	/* for each used byte, set flag */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2885
	while (len > 0) {
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2886
#ifdef TO_BE_MEASURED
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2887
	    unsigned  byte;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2888
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2889
	    byte = *cp;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2890
	    if (! f.flags[byte]) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2891
		f.flags[byte] = 1;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2892
		coverage++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2893
		if (coverage == 256) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2894
		    /* no need to scan rest */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2895
		    break;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2896
		}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2897
	    }
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2898
#else
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2899
	    f.flags[*cp] = 1;
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2900
#endif
12879
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2901
	    cp++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2902
	    len--;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2903
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2904
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2905
	/* count 1's */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2906
	len = 0;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2907
	for (cp=f.flags, endp=f.flags+256; cp < endp;) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2908
	    if ( *((unsigned int *)cp)) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2909
		if (cp[0]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2910
		if (cp[1]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2911
		if (cp[2]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2912
		if (cp[3]) len++;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2913
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2914
	    cp += 4;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2915
	}
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2916
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2917
	/* create ByteArray of used values */
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2918
	result = __BYTEARRAY_UNINITIALIZED_NEW_INT(len);
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2919
	if (result) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2920
	    cp = __ByteArrayInstPtr(result)->ba_element;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2921
	    for (len=0; len < 256; len++) {
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2922
		if (f.flags[len])
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2923
		    *cp++ = len;
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2924
	    }
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2925
	    RETURN ( result );
ca913786d412 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 12768
diff changeset
  2926
	}
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2927
    }
2866
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2928
%}.
0d1b10026aa8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2782
diff changeset
  2929
    ^ self asIdentitySet asByteArray
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2930
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2931
    "
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2932
     #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues
550
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2933
    "
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2934
! !
b40ca6a280c1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2935
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  2936
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2937
!ByteArray methodsFor:'searching'!
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2938
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2939
indexOf:aByte startingAt:start
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2940
    "return the index of the first occurrence of the argument, aByte
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2941
     in the receiver starting at start, anInteger; return 0 if not found.
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2942
     - reimplemented here for speed"
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2943
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2944
%{  /* NOCONTEXT */
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2945
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2946
    REGISTER unsigned char *cp;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2947
    REGISTER INT index;
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2948
    REGISTER int byteValue;
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2949
    REGISTER int len;
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2950
    OBJ cls;
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2951
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2952
    if (__isSmallInteger(aByte) &&__isBytes(self)) {
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2953
        byteValue = __intVal(aByte);
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2954
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2955
        if (byteValue & ~0xFF /* i.e. (byteValue < 0) || (byteValue > 255) */) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2956
            /*
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2957
             * searching for something which cannot be found
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2958
             */
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2959
            RETURN ( __mkSmallInteger(0) );
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2960
        }
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2961
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2962
        if (__isSmallInteger(start)) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2963
            index = __intVal(start);
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2964
            len = __byteArraySize(self);
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2965
            cp = __ByteArrayInstPtr(self)->ba_element;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2966
            if ((cls = __qClass(self)) != @global(ByteArray)) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2967
                int nInst;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2968
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2969
                nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2970
                cp += nInst;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2971
                len -= nInst;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2972
            }
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2973
            cp += index - 1;
14382
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2974
#ifdef __UNROLL_LOOPS__
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2975
            while ((index+4) < len) {
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2976
                if (cp[0] == byteValue) { RETURN ( __mkSmallInteger(index) ); }
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2977
                if (cp[1] == byteValue) { RETURN ( __mkSmallInteger(index+1) ); }
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2978
                if (cp[2] == byteValue) { RETURN ( __mkSmallInteger(index+2) ); }
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2979
                if (cp[3] == byteValue) { RETURN ( __mkSmallInteger(index+3) ); }
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2980
                index += 4;
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2981
                cp += 4;
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2982
            }
dcbff20f0a14 changed: #indexOf:startingAt:
Claus Gittinger <cg@exept.de>
parents: 14135
diff changeset
  2983
#endif
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2984
            while (index <= len) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2985
                if (*cp == byteValue) {
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2986
                    RETURN ( __mkSmallInteger(index) );
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2987
                }
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2988
                index++;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2989
                cp++;
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2990
            }
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2991
            RETURN ( __mkSmallInteger(0) );
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2992
        }
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2993
    }
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2994
%}.
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2995
    ^ super indexOf:aByte startingAt:start
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2996
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2997
    "
14135
bc011ad68efb changed:
Stefan Vogel <sv@exept.de>
parents: 13706
diff changeset
  2998
     #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
7822
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  2999
    "
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3000
! !
2e2141fffed2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  3001
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  3002
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3003
!ByteArray methodsFor:'testing'!
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3004
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3005
isByteArray
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3006
    "return true, if the receiver is some kind of bytearray;
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3007
     true is returned here - the method is redefined from Object."
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3008
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3009
    ^ true
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3010
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3011
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3012
!
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3013
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3014
isLiteral
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3015
    "return true, if the receiver can be used as a literal constant in ST syntax
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3016
     (i.e. can be used in constant arrays)"
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3017
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3018
    "/ no, simply returning true here is a mistake:
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3019
    "/ it could be a subclass of ByteArray
5554
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3020
    "/ (of which the compiler does not know at all ...)
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3021
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3022
    ^ self class == ByteArray
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3023
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3024
    "Modified: 22.4.1996 / 12:55:30 / cg"
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3025
! !
28520e96cca9 category changes
Claus Gittinger <cg@exept.de>
parents: 5549
diff changeset
  3026
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1695
diff changeset
  3027
!ByteArray class methodsFor:'documentation'!
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3028
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3029
version
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
  3030
    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.211 2013-08-12 10:09:48 stefan Exp $'
12091
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
  3031
!
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
  3032
c9906aca7a7a added: #asByteString
Claus Gittinger <cg@exept.de>
parents: 11860
diff changeset
  3033
version_CVS
15625
090e438cffe5 class: ByteArray
Stefan Vogel <sv@exept.de>
parents: 15330
diff changeset
  3034
    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.211 2013-08-12 10:09:48 stefan Exp $'
628
7aa563e4c64a version at the end
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3035
! !
15274
58d5c0f8d906 class: ByteArray
Claus Gittinger <cg@exept.de>
parents: 14382
diff changeset
  3036