Skip to content
Open
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
155 changes: 106 additions & 49 deletions Source/src/BitStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,58 +486,74 @@ void BitStream::SetData( unsigned char *inByteArray )
void BitStream::WriteCompressed( const unsigned char* inByteArray,
const unsigned int size, const bool unsignedData )
{
BitSize_t currentByte = ( size >> 3 ) - 1; // PCs
BitSize_t currentByte;

unsigned char byteMatch;

if ( unsignedData )
{
byteMatch = 0;
}

else
{
byteMatch = 0xFF;
}
unsigned char byteMatch = unsignedData ? 0 : 0xFF;

// Write upper bytes with a single 1
// From high byte to low byte, if high byte is a byteMatch then write a 1 bit. Otherwise write a 0 bit and then write the remaining bytes
while ( currentByte > 0 )
// From high byte to low byte, if high byte is a byteMatch then write a 1 bit.
// Otherwise write a 0 bit and then write the remaining bytes
if (!IsNetworkOrder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing ()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also incorrect usage --- Endian swapping is conditionally controlled by the __BITSTREAM_NATIVE_END macro - should call DoEndianSwap() instead

{
if ( inByteArray[ currentByte ] == byteMatch ) // If high byte is byteMatch (0 of 0xff) then it would have the same value shifted
// get the highest byte with highest index PCs
currentByte = (size >> 3) - 1;
while (currentByte > 0)
{
bool b = true;
Write( b );
if (inByteArray[currentByte] == byteMatch) // If high byte is byteMatch (0 of 0xff) then it would have the same value shifted
{
Write(true);
currByte--;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be currentByte I take it
also invalid character used (0x203a) instead of ;

}
else
{
// Write the remainder of the data after writing 0
Write(false);
// Write the remainings
WriteBits(inByteArray, (currentByte + 1) << 3, true);
return;
}
}
else
{
// Write the remainder of the data after writing 0
bool b = false;
Write( b );

WriteBits( inByteArray, ( currentByte + 1 ) << 3, true );
// currentByte--;


return ;
// make sure we are now on the lowest byte (index 0)
if (currentByte > 0)
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a void function - should be simply return?

}
else
{
// get the highest byte with highest index PCs
currentByte = 0;
while (currentByte > ((size >> 3) - 1))
{
if (inByteArray[currentByte] == byteMatch) // If high byte is byteMatch (0 of 0xff) then it would have the same value shifted
{
Write(true);
currByte++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cyrrByte -> currentByte?
invalid character instead of simple ;

}
else
{
// Write the remainder of the data after writing 0
Write(false);
// Write the remainings
WriteBits(src + currentByte, size - (currentByte << 3));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src is undefined --- I guess you meant inByteArray instead?

return;
}
}

currentByte--;
// make sure we are now on the lowest byte (index highest)
if (currByte < ((size >> 3) - 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (i.e. currentByte)?

return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void function - should be return?

}

// If the upper half of the last byte is a 0 (positive) or 16 (negative) then write a 1 and the remaining 4 bits. Otherwise write a 0 and the 8 bites.
if ( ( unsignedData && ( ( *( inByteArray + currentByte ) ) & 0xF0 ) == 0x00 ) ||
( unsignedData == false && ( ( *( inByteArray + currentByte ) ) & 0xF0 ) == 0xF0 ) )
if ((inByteArray[currentByte] & 0xF0) == 0x00 || (inByteArray[currentByte] & 0xF0) == 0xF0)
{
bool b = true;
Write( b );
Write( true );
WriteBits( inByteArray + currentByte, 4, true );
}

else
{
bool b = false;
Write( b );
Write( false );
WriteBits( inByteArray + currentByte, 8, true );
}
}
Expand Down Expand Up @@ -614,7 +630,7 @@ bool BitStream::ReadBits( unsigned char *inOutByteArray, BitSize_t numberOfBitsT
bool BitStream::ReadCompressed( unsigned char* inOutByteArray,
const unsigned int size, const bool unsignedData )
{
unsigned int currentByte = ( size >> 3 ) - 1;
unsigned int currentByte;


unsigned char byteMatch, halfByteMatch;
Expand All @@ -632,30 +648,71 @@ bool BitStream::ReadCompressed( unsigned char* inOutByteArray,
}

// Upper bytes are specified with a single 1 if they match byteMatch
// From high byte to low byte, if high byte is a byteMatch then write a 1 bit. Otherwise write a 0 bit and then write the remaining bytes
while ( currentByte > 0 )
// From high byte to low byte, if high byte is a byteMatch then write a 1 bit.
// Otherwise write a 0 bit and then write the remaining bytes
if (!IsNetworkOrder())
{
// If we read a 1 then the data is byteMatch.
currentByte = (size >> 3) - 1;
while (currentByte > 0)
{
// If we read a 1 then the data is byteMatch.

bool b;
bool b;

if ( Read( b ) == false )
return false;
if (Read(b) == false)
return false;

if ( b ) // Check that bit
{
inOutByteArray[ currentByte ] = byteMatch;
currentByte--;
if (b) // Check that bit
{
inOutByteArray[currentByte] = byteMatch;
currentByte--;
}
else
{
// Read the rest of the bytes

if (ReadBits(inOutByteArray, (currentByte + 1) << 3) == false)
return false;

return true;
}
}
else

// make sure we are now on the lowest byte (index of 0)
if (currentByte > 0)
return false;
}
else
{
currentByte = 0;
while (currentByte <((size >>3 )-1))
{
// Read the rest of the bytes
// If we read a 1 then the data is byteMatch.

if ( ReadBits( inOutByteArray, ( currentByte + 1 ) << 3 ) == false )
bool b;

if (Read(b) == false)
return false;

return true;
if (b) // Check that bit
{
inOutByteArray[currentByte] = byteMatch;
currentByte++;
}
else
{
// Read the rest of the bytes

if (ReadBits(inOutByteArray, size - (currentByte << 3) == false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing closing )

return false;

return true;
}
}

// make sure we are now on the highest byte (index of (size >>3 )-1))
if (currentByte < (size >> 3) - 1))
return false;
}

// All but the first bytes are byteMatch. If the upper half of the last byte is a 0 (positive) or 16 (negative) then what we read will be a 1 and the remaining 4 bits.
Expand Down