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