OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPackedBits.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2004 Garrett Potts.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Garrett Potts
7 //
8 // Description:
9 //
10 // Contains class definition for ossimPackBits.
11 //*******************************************************************
12 // $Id: ossimPackedBits.cpp 9094 2006-06-13 19:12:40Z dburken $
14 #include <iostream>
15 
17  ossim_uint16 bits)
18  :thePackedBits(packedBits),
19  theBits(bits)
20 {
21  theBytes = theBits>>3;
22  theBitsLeft = theBits%8;
23 }
24 
26 {
27  ossim_uint32 value = 0;
28  ossim_uint32 tempBits = (theBitsLeft*idx);
29  ossim_uint32 tempBitShift = tempBits%8;
30  ossim_uint32 byteOffset = ( (idx*theBytes) + (tempBits>>3) );
31  ossim_uint32 bitCount = 0;
32  ossim_uint32 bitsSeen = tempBitShift;
33  ossim_uint8 bitmask = 1 << (7-tempBitShift);
34 
35  while(bitCount < theBits)
36  {
37  value |= (ossim_uint8)((bool)(thePackedBits[byteOffset]&bitmask));
38  ++bitCount;
39  ++bitsSeen;
40  if(bitsSeen >= 8)
41  {
42  bitsSeen = 0;
43  bitmask = 0x80; // binary pattern 10000000
44  ++byteOffset;
45  }
46  else
47  {
48  bitmask>>=1;
49  }
50  if(bitCount < theBits)
51  {
52  value <<=1;
53  }
54  }
55 
56  return value;
57 }
ossimPackedBits(const ossim_uint8 *packedBits, ossim_uint16 bits)
Constructor that takes packed bits array and word size in bits.
ossim_uint16 theBitsLeft
ossim_uint32 getValueAsUint32(ossim_uint32 idx) const
Extract out the value at offset indicated by idx and convert the the vale to an ossim_uint32.
unsigned short ossim_uint16
unsigned int ossim_uint32
ossim_uint16 theBits
ossim_uint16 theBytes
unsigned char ossim_uint8
const ossim_uint8 * thePackedBits