ZenLib

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

BitStream_LE.h
Go to the documentation of this file.
1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
2 *
3 * Use of this source code is governed by a zlib-style license that can
4 * be found in the License.txt file in the root of the source tree.
5 */
6
7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 //
9 // Read a stream bit per bit, Little Endian version (rarely used!!!)
10 // Can read up to 32 bits at once
11 //
12 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
14 //---------------------------------------------------------------------------
15 #ifndef ZenBitStream_LEH
16 #define ZenBitStream_LEH
17 //---------------------------------------------------------------------------
18
19 //---------------------------------------------------------------------------
20 #include "ZenLib/BitStream.h"
21 //---------------------------------------------------------------------------
22
23 namespace ZenLib
24 {
25
26 class BitStream_LE : public BitStream
27 {
28 public:
29 BitStream_LE () :BitStream() {};
30 BitStream_LE (const int8u* Buffer_, size_t Size_) :BitStream(Buffer_, Size_) {};
31
32 void Attach(const int8u* Buffer_, size_t Size_)
33 {
34 endbyte=0;
35 endbit=0;
36 buffer=Buffer_;
37 ptr=Buffer_;
38 storage=(long)Size_;
39 };
40
41 int32u Get (size_t HowMany)
42 {
43 ptr_BeforeLastCall=ptr;
44
45 long ret;
46 static const int32u Mask[33]={
47 0x00000000,
48 0x00000001, 0x00000003, 0x00000007, 0x0000000f,
49 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
50 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
51 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
52 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff,
53 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff,
54 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
55 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff,
56 };
57 unsigned long m=Mask[HowMany];
58
59 HowMany+=endbit;
60
61 if(endbyte+4>=storage){
62 ret=-1L;
63 if(endbyte*8+(long)HowMany>storage*8){
64 Attach(NULL, 0);
65 goto overflow;
66 }
67 }
68
69 ret=ptr[0]>>endbit;
70 if(HowMany>8){
71 ret|=ptr[1]<<(8-endbit);
72 if(HowMany>16){
73 ret|=ptr[2]<<(16-endbit);
74 if(HowMany>24){
75 ret|=ptr[3]<<(24-endbit);
76 if(HowMany>32 && endbit){
77 ret|=ptr[4]<<(32-endbit);
78 }
79 }
80 }
81 }
82 ret&=m;
83
84 ptr+=HowMany/8;
85 endbyte+=(long)HowMany/8;
86 endbit=(long)HowMany&7;
87
88 overflow:
89
90 return(ret);
91 };
92
93 void Skip(size_t bits)
94 {
95 Get(bits);
96 }
97
98 int32u Remain () //How many bits remain?
99 {
100 return storage*8-(endbyte*8+endbit);
101 };
102
103 void Byte_Align()
104 {
105 };
106
107 size_t Offset_Get()
108 {
109 return ptr-buffer;
110 };
111
112 size_t BitOffset_Get()
113 {
114 return endbit;
115 };
116
117 size_t OffsetBeforeLastCall_Get()
118 {
119 return ptr_BeforeLastCall-buffer;
120 };
121
122 private :
123 long endbyte;
124 int endbit;
125
126 const unsigned char *buffer;
127 const unsigned char *ptr;
128 const unsigned char *ptr_BeforeLastCall;
129 long storage;
130 };
131
132 } //namespace ZenLib
133 #endif
ZenLib::BitStream_LE::Byte_Align
void Byte_Align()
Definition: BitStream_LE.h:103
ZenLib::BitStream_LE::Remain
int32u Remain()
Definition: BitStream_LE.h:98
ZenLib::BitStream_LE::Skip
void Skip(size_t bits)
Definition: BitStream_LE.h:93
ZenLib::BitStream_LE::BitStream_LE
BitStream_LE()
Definition: BitStream_LE.h:29
ZenLib::BitStream
Definition: BitStream.h:30
BitStream.h
ZenLib::BitStream_LE::Offset_Get
size_t Offset_Get()
Definition: BitStream_LE.h:107
NULL
#define NULL
Definition: HTTPClientWrapper.h:93
ZenLib
Definition: BitStream.h:23
ZenLib::BitStream_LE::Get
int32u Get(size_t HowMany)
Definition: BitStream_LE.h:41
ZenLib::BitStream_LE::BitOffset_Get
size_t BitOffset_Get()
Definition: BitStream_LE.h:112
ZenLib::BitStream_LE::BitStream_LE
BitStream_LE(const int8u *Buffer_, size_t Size_)
Definition: BitStream_LE.h:30
ZenLib::BitStream_LE::OffsetBeforeLastCall_Get
size_t OffsetBeforeLastCall_Get()
Definition: BitStream_LE.h:117
ZenLib::BitStream_LE::Attach
void Attach(const int8u *Buffer_, size_t Size_)
Definition: BitStream_LE.h:32
ZenLib::BitStream_LE
Definition: BitStream_LE.h:26