xref: /haiku/src/add-ons/media/plugins/ape_reader/MAClib/BitArray.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
1 #ifndef APE_BITARRAY_H
2 #define APE_BITARRAY_H
3 
4 #include "IO.h"
5 #include "MD5.h"
6 
7 //#define BUILD_RANGE_TABLE
8 
9 struct RANGE_CODER_STRUCT_COMPRESS
10 {
11     unsigned int low;        // low end of interval
12     unsigned int range;        // length of interval
13     unsigned int help;        // bytes_to_follow resp. intermediate value
14     unsigned char buffer;    // buffer for input / output
15 };
16 
17 struct BIT_ARRAY_STATE
18 {
19     uint32    k;
20     uint32    nKSum;
21 };
22 
23 class CBitArray
24 {
25 public:
26 
27     // construction / destruction
28     CBitArray(CIO *pIO);
29     ~CBitArray();
30 
31     // encoding
32     int EncodeUnsignedLong(unsigned int n);
33     int EncodeValue(int nEncode, BIT_ARRAY_STATE & BitArrayState);
34     int EncodeBits(unsigned int nValue, int nBits);
35 
36     // output (saving)
37     int OutputBitArray(BOOL bFinalize = FALSE);
38 
39     // other functions
40     void Finalize();
41     void AdvanceToByteBoundary();
42     inline uint32 GetCurrentBitIndex() { return m_nCurrentBitIndex; }
43     void FlushState(BIT_ARRAY_STATE & BitArrayState);
44     void FlushBitArray();
45     inline CMD5Helper & GetMD5Helper() { return m_MD5; }
46 
47 private:
48 
49     // data members
50     uint32 *            m_pBitArray;
51     CIO    *                        m_pIO;
52     uint32            m_nCurrentBitIndex;
53     RANGE_CODER_STRUCT_COMPRESS    m_RangeCoderInfo;
54     CMD5Helper                    m_MD5;
55 
56 #ifdef BUILD_RANGE_TABLE
57     void OutputRangeTable();
58 #endif
59 
60 };
61 
62 #endif // #ifndef APE_BITARRAY_H
63