Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/ZenLib/BitStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class BitStream
do
{
Skip(32);
if (BufferUnderRun)
return;
HowMany-=32;
}
while(HowMany>32);
Expand Down
18 changes: 18 additions & 0 deletions Source/ZenLib/BitStream_Fast.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class BitStream_Fast
0x1f, 0x3f, 0x7f, 0xff,
};

if (HowMany==0 || HowMany>8)
return 0;

if (HowMany<=(Buffer_Size%8))
{
Buffer_Size-=HowMany;
Expand Down Expand Up @@ -117,6 +120,9 @@ class BitStream_Fast
0x1fff, 0x3fff, 0x7fff, 0xffff,
};

if (HowMany==0 || HowMany>16)
return 0;

if (HowMany<=(Buffer_Size%8))
{
Buffer_Size-=HowMany;
Expand Down Expand Up @@ -164,6 +170,9 @@ class BitStream_Fast
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff,
};

if (HowMany==0 || HowMany>32)
return 0;

if (HowMany<=(Buffer_Size%8))
{
Buffer_Size-=HowMany;
Expand Down Expand Up @@ -263,6 +272,9 @@ class BitStream_Fast
0x1f, 0x3f, 0x7f, 0xff,
};

if (HowMany==0 || HowMany>8)
return 0;

if (HowMany<=(Buffer_Size%8))
return (LastByte>>((Buffer_Size-HowMany)%8))&Mask[HowMany];

Expand Down Expand Up @@ -295,6 +307,9 @@ class BitStream_Fast
0x1fff, 0x3fff, 0x7fff, 0xffff,
};

if (HowMany==0 || HowMany>16)
return 0;

if (HowMany<=(Buffer_Size%8))
return (LastByte>>((Buffer_Size-HowMany)%8))&Mask[HowMany];

Expand Down Expand Up @@ -341,6 +356,9 @@ class BitStream_Fast
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff,
};

if (HowMany==0 || HowMany>32)
return 0;

if (HowMany<=(Buffer_Size%8))
return (LastByte>>((Buffer_Size-HowMany)%8))&Mask[HowMany];

Expand Down
24 changes: 21 additions & 3 deletions Source/ZenLib/BitStream_LE.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class BitStream_LE : public BitStream

int32u Get (size_t HowMany)
{
ptr_BeforeLastCall=ptr;

long ret;
static const int32u Mask[33]={
0x00000000,
Expand All @@ -65,6 +63,12 @@ class BitStream_LE : public BitStream
0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff,
0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff,
};

if (HowMany==0 || HowMany>32)
return 0;

ptr_BeforeLastCall=ptr;

unsigned long m=Mask[HowMany];

HowMany+=endbit;
Expand Down Expand Up @@ -103,6 +107,20 @@ class BitStream_LE : public BitStream

void Skip(size_t bits)
{
if (bits==0)
return;
if (bits>32) //Get is only for <=32 bits
{
do {
Get(32);
if (!buffer)
return;
bits-=32;
} while (bits>32);
if (bits)
Get(bits);
return;
}
Get(bits);
}

Expand All @@ -114,7 +132,7 @@ class BitStream_LE : public BitStream
void Byte_Align()
{
if (endbit)
Get(endbit);
Get(8-endbit);
};

size_t Offset_Get()
Expand Down
Loading