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