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