1
0

id3_int28.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // The authors have released ID3Lib as Public Domain (PD) and claim no copyright,
  2. // patent or other intellectual property protection in this work. This means that
  3. // it may be modified, redistributed and used in commercial and non-commercial
  4. // software and hardware without restrictions. ID3Lib is distributed on an "AS IS"
  5. // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. // Mon Nov 23 18:34:01 1998
  7. #include "id3_int28.h"
  8. #include <bfc/platform/types.h>
  9. int28::int28(uint32_t val)
  10. {
  11. set ( val );
  12. }
  13. int28::int28(const uchar *val)
  14. {
  15. for ( int i = 0; i < sizeof ( uint32_t ); i++ )
  16. value[ i ] = val[ i ];
  17. }
  18. void int28::set(uint32_t val)
  19. {
  20. for ( int i = 0; i < sizeof ( uint32_t ); i++ )
  21. value[ sizeof ( uint32_t ) - 1 - i ] = (uint8_t) ( ( val >> ( i * 7 ) ) & 127 ) & 0xFF;
  22. return;
  23. }
  24. int28 &int28::setFromFile(uint32_t val)
  25. {
  26. for ( int i = 0; i < sizeof ( uint32_t ); i++ )
  27. value[sizeof(uint32_t) - 1 - i] = (uint8_t) (val >>(i*8)) & 0xFF;
  28. return *this;
  29. }
  30. luint int28::get ( void )
  31. {
  32. luint newSize = 0L;
  33. uchar bytes [ 4 ];
  34. bytes[ 3 ] = value[ 3 ] | ( ( value[ 2 ] & 1 ) << 7 );
  35. bytes[ 2 ] = ( ( value[ 2 ] >> 1 ) & 63 ) | ( ( value[ 1 ] & 3 ) << 6 );
  36. bytes[ 1 ] = ( ( value[ 1 ] >> 2 ) & 31 ) | ( ( value[ 0 ] & 7 ) << 5 );
  37. bytes[ 0 ] = ( ( value[ 0 ] >> 3 ) & 15 );
  38. newSize = bytes[ 3 ] | ( (luint) bytes[ 2 ] << 8 ) | ( (luint) bytes[ 1 ] << 16 ) | ( (luint) bytes[ 0 ] << 24 );
  39. return newSize;
  40. }
  41. uchar int28::operator[] ( luint posn )
  42. {
  43. return value[ posn ];
  44. }