ByteArray.st
changeset 15274 58d5c0f8d906
parent 14382 dcbff20f0a14
child 15280 96826a417ba5
equal deleted inserted replaced
15273:79888b6f4b20 15274:58d5c0f8d906
   160 %}.
   160 %}.
   161     ^ self basicNew:anInteger
   161     ^ self basicNew:anInteger
   162 ! !
   162 ! !
   163 
   163 
   164 
   164 
       
   165 
       
   166 
       
   167 
   165 !ByteArray class methodsFor:'queries'!
   168 !ByteArray class methodsFor:'queries'!
   166 
   169 
   167 elementByteSize
   170 elementByteSize
   168     ^ 1
   171     ^ 1
   169 
   172 
   176 
   179 
   177     ^ self == ByteArray
   180     ^ self == ByteArray
   178 
   181 
   179     "Modified: 23.4.1996 / 15:56:25 / cg"
   182     "Modified: 23.4.1996 / 15:56:25 / cg"
   180 ! !
   183 ! !
       
   184 
       
   185 
   181 
   186 
   182 !ByteArray methodsFor:'Compatibility-Squeak'!
   187 !ByteArray methodsFor:'Compatibility-Squeak'!
   183 
   188 
   184 bitXor:aByteArray
   189 bitXor:aByteArray
   185     "return a new byteArray containing the bitWise-xor of the receiver's and the
   190     "return a new byteArray containing the bitWise-xor of the receiver's and the
  2379     "
  2384     "
  2380 !
  2385 !
  2381 
  2386 
  2382 swapBytes
  2387 swapBytes
  2383     "swap bytes inplace -
  2388     "swap bytes inplace -
  2384      written as a primitive for speed on image grabbing (if display order is different)"
  2389      Expects that the receiver has an even number of bytes; 
       
  2390      if not, only the pairs excluding the last byte are swapped.
       
  2391      written as a primitive for speed on image grabbing (if display order is different)."
  2385 
  2392 
  2386 %{  /* NOCONTEXT */
  2393 %{  /* NOCONTEXT */
  2387 
  2394 
  2388     REGISTER unsigned char *p;
  2395     REGISTER unsigned char *p;
  2389     REGISTER int cnt;
  2396     REGISTER int cnt;
  2390     REGISTER unsigned t;
  2397     REGISTER unsigned t;
  2391 
  2398 
  2392     if (__qClass(self) == @global(ByteArray)) {
  2399     if (__qClass(self) == @global(ByteArray)) {
  2393 	cnt = __byteArraySize(self);
  2400         cnt = __byteArraySize(self);
  2394 	cnt = cnt & ~1; /* make it even */
  2401         cnt = cnt & ~1; /* make it even */
  2395 	p = __ByteArrayInstPtr(self)->ba_element;
  2402         p = __ByteArrayInstPtr(self)->ba_element;
  2396 	while (cnt > 0) {
  2403 
  2397 #ifdef OLD
  2404         while (cnt >= sizeof(INT)) {
  2398 	    t = p[0];
  2405             unsigned INT i = ((unsigned INT *)p)[0];
  2399 	    p[0] = p[1];
  2406 
  2400 	    p[1] = t;
  2407 #if __POINTER_SIZE__ == 8
       
  2408             i = ((i>>8) & 0x00FF00FF00FF00FF) | ((i & 0x00FF00FF00FF00FF) << 8);
  2401 #else
  2409 #else
  2402 	    unsigned short s;
  2410             i = ((i>>8) & 0x00FF00FF) | ((i & 0x00FF00FF) << 8);
  2403 
  2411 #endif /* __POINTER_SIZE__ */
  2404 	    s = ((unsigned short *)p)[0];
  2412             ((unsigned INT *)p)[0] = i;
  2405 	    s = (s >> 8) | (s << 8);
  2413             p += sizeof(INT);
  2406 	    ((unsigned short *)p)[0] = s;
  2414             cnt -= sizeof(INT);
  2407 #endif
  2415         }
  2408 	    p += 2;
  2416         while (cnt > 0) {
  2409 	    cnt -= 2;
  2417             unsigned short s;
  2410 	}
  2418 
  2411 	RETURN ( self );
  2419             s = ((unsigned short *)p)[0];
       
  2420             s = (s >> 8) | (s << 8);
       
  2421             ((unsigned short *)p)[0] = s;
       
  2422             p += 2;
       
  2423             cnt -= 2;
       
  2424         }
       
  2425         RETURN ( self );
  2412     }
  2426     }
  2413 %}.
  2427 %}.
  2414     ^ super swapBytes "/ rubbish - there is no one currenly
  2428     ^ super swapBytes "/ rubbish - there is no one currenly
  2415 
  2429 
  2416     "
  2430     "
  2417      #[1 2 3 4 5 6 7 8 9 10] copy swapBytes
  2431      #[1 2 3 4 5 6 7 8 9 10] copy swapBytes     -> #[2 1 4 3 6 5 8 7 10 9]
  2418      #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes
  2432      #[1 2 3 4 5 6 7 8 9 10 11] copy swapBytes  -> #[2 1 4 3 6 5 8 7 10 9 11]
       
  2433      #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] copy swapBytes   
  2419     "
  2434     "
  2420 !
  2435 !
  2421 
  2436 
  2422 swapIndex:i1 and:i2
  2437 swapIndex:i1 and:i2
  2423    "spap the bytes with i1 and i2"
  2438    "spap the bytes with i1 and i2"
  2905 
  2920 
  2906     "
  2921     "
  2907      #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues
  2922      #[1 2 3 1 2 3 1 2 3 1 2 3 4 5 6 4 5 6] usedValues
  2908     "
  2923     "
  2909 ! !
  2924 ! !
       
  2925 
  2910 
  2926 
  2911 !ByteArray methodsFor:'searching'!
  2927 !ByteArray methodsFor:'searching'!
  2912 
  2928 
  2913 indexOf:aByte startingAt:start
  2929 indexOf:aByte startingAt:start
  2914     "return the index of the first occurrence of the argument, aByte
  2930     "return the index of the first occurrence of the argument, aByte
  2971     "
  2987     "
  2972      #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
  2988      #[1 2 3 4 5 6 7 8 9 0 1 2 3 4 5] indexOf:0 startingAt:1
  2973     "
  2989     "
  2974 ! !
  2990 ! !
  2975 
  2991 
       
  2992 
  2976 !ByteArray methodsFor:'testing'!
  2993 !ByteArray methodsFor:'testing'!
  2977 
  2994 
  2978 isByteArray
  2995 isByteArray
  2979     "return true, if the receiver is some kind of bytearray;
  2996     "return true, if the receiver is some kind of bytearray;
  2980      true is returned here - the method is redefined from Object."
  2997      true is returned here - the method is redefined from Object."
  2998 ! !
  3015 ! !
  2999 
  3016 
  3000 !ByteArray class methodsFor:'documentation'!
  3017 !ByteArray class methodsFor:'documentation'!
  3001 
  3018 
  3002 version
  3019 version
  3003     ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.208 2012-10-10 17:00:30 cg Exp $'
  3020     ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.209 2013-05-27 08:10:49 cg Exp $'
  3004 !
  3021 !
  3005 
  3022 
  3006 version_CVS
  3023 version_CVS
  3007     ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.208 2012-10-10 17:00:30 cg Exp $'
  3024     ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.209 2013-05-27 08:10:49 cg Exp $'
  3008 ! !
  3025 ! !
       
  3026