mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-24 07:54:39 +00:00
more naming
This commit is contained in:
@@ -5,36 +5,36 @@ namespace SharpCompress.Compressors.Filters
|
||||
{
|
||||
internal class BCJ2Filter : Stream
|
||||
{
|
||||
private readonly Stream baseStream;
|
||||
private readonly byte[] input = new byte[4096];
|
||||
private int inputOffset;
|
||||
private int inputCount;
|
||||
private bool endReached;
|
||||
private readonly Stream _baseStream;
|
||||
private readonly byte[] _input = new byte[4096];
|
||||
private int _inputOffset;
|
||||
private int _inputCount;
|
||||
private bool _endReached;
|
||||
|
||||
private long position;
|
||||
private readonly byte[] output = new byte[4];
|
||||
private int outputOffset;
|
||||
private int outputCount;
|
||||
private long _position;
|
||||
private readonly byte[] _output = new byte[4];
|
||||
private int _outputOffset;
|
||||
private int _outputCount;
|
||||
|
||||
private readonly byte[] control;
|
||||
private readonly byte[] data1;
|
||||
private readonly byte[] data2;
|
||||
private readonly byte[] _control;
|
||||
private readonly byte[] _data1;
|
||||
private readonly byte[] _data2;
|
||||
|
||||
private int controlPos;
|
||||
private int data1Pos;
|
||||
private int data2Pos;
|
||||
private int _controlPos;
|
||||
private int _data1Pos;
|
||||
private int _data2Pos;
|
||||
|
||||
private readonly ushort[] p = new ushort[256 + 2];
|
||||
private uint range, code;
|
||||
private byte prevByte;
|
||||
private bool isDisposed;
|
||||
private readonly ushort[] _p = new ushort[256 + 2];
|
||||
private uint _range, _code;
|
||||
private byte _prevByte;
|
||||
private bool _isDisposed;
|
||||
|
||||
private const int kNumTopBits = 24;
|
||||
private const int kTopValue = 1 << kNumTopBits;
|
||||
private const int K_NUM_TOP_BITS = 24;
|
||||
private const int K_TOP_VALUE = 1 << K_NUM_TOP_BITS;
|
||||
|
||||
private const int kNumBitModelTotalBits = 11;
|
||||
private const int kBitModelTotal = 1 << kNumBitModelTotalBits;
|
||||
private const int kNumMoveBits = 5;
|
||||
private const int K_NUM_BIT_MODEL_TOTAL_BITS = 11;
|
||||
private const int K_BIT_MODEL_TOTAL = 1 << K_NUM_BIT_MODEL_TOTAL_BITS;
|
||||
private const int K_NUM_MOVE_BITS = 5;
|
||||
|
||||
private static bool IsJ(byte b0, byte b1)
|
||||
{
|
||||
@@ -48,34 +48,34 @@ namespace SharpCompress.Compressors.Filters
|
||||
|
||||
public BCJ2Filter(byte[] control, byte[] data1, byte[] data2, Stream baseStream)
|
||||
{
|
||||
this.control = control;
|
||||
this.data1 = data1;
|
||||
this.data2 = data2;
|
||||
this.baseStream = baseStream;
|
||||
_control = control;
|
||||
_data1 = data1;
|
||||
_data2 = data2;
|
||||
_baseStream = baseStream;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < p.Length; i++)
|
||||
for (i = 0; i < _p.Length; i++)
|
||||
{
|
||||
p[i] = kBitModelTotal >> 1;
|
||||
_p[i] = K_BIT_MODEL_TOTAL >> 1;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
range = 0xFFFFFFFF;
|
||||
_code = 0;
|
||||
_range = 0xFFFFFFFF;
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
code = (code << 8) | control[controlPos++];
|
||||
_code = (_code << 8) | control[_controlPos++];
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (isDisposed)
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isDisposed = true;
|
||||
_isDisposed = true;
|
||||
base.Dispose(disposing);
|
||||
baseStream.Dispose();
|
||||
_baseStream.Dispose();
|
||||
}
|
||||
|
||||
public override bool CanRead => true;
|
||||
@@ -89,57 +89,57 @@ namespace SharpCompress.Compressors.Filters
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override long Length => baseStream.Length + data1.Length + data2.Length;
|
||||
public override long Length => _baseStream.Length + _data1.Length + _data2.Length;
|
||||
|
||||
public override long Position { get => position; set => throw new NotSupportedException(); }
|
||||
public override long Position { get => _position; set => throw new NotSupportedException(); }
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int size = 0;
|
||||
byte b = 0;
|
||||
|
||||
while (!endReached && size < count)
|
||||
while (!_endReached && size < count)
|
||||
{
|
||||
while (outputOffset < outputCount)
|
||||
while (_outputOffset < _outputCount)
|
||||
{
|
||||
b = output[outputOffset++];
|
||||
b = _output[_outputOffset++];
|
||||
buffer[offset++] = b;
|
||||
size++;
|
||||
position++;
|
||||
_position++;
|
||||
|
||||
prevByte = b;
|
||||
_prevByte = b;
|
||||
if (size == count)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
if (inputOffset == inputCount)
|
||||
if (_inputOffset == _inputCount)
|
||||
{
|
||||
inputOffset = 0;
|
||||
inputCount = baseStream.Read(input, 0, input.Length);
|
||||
if (inputCount == 0)
|
||||
_inputOffset = 0;
|
||||
_inputCount = _baseStream.Read(_input, 0, _input.Length);
|
||||
if (_inputCount == 0)
|
||||
{
|
||||
endReached = true;
|
||||
_endReached = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
b = input[inputOffset++];
|
||||
b = _input[_inputOffset++];
|
||||
buffer[offset++] = b;
|
||||
size++;
|
||||
position++;
|
||||
_position++;
|
||||
|
||||
if (!IsJ(prevByte, b))
|
||||
if (!IsJ(_prevByte, b))
|
||||
{
|
||||
prevByte = b;
|
||||
_prevByte = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
int prob;
|
||||
if (b == 0xE8)
|
||||
{
|
||||
prob = prevByte;
|
||||
prob = _prevByte;
|
||||
}
|
||||
else if (b == 0xE9)
|
||||
{
|
||||
@@ -150,27 +150,27 @@ namespace SharpCompress.Compressors.Filters
|
||||
prob = 257;
|
||||
}
|
||||
|
||||
uint bound = (range >> kNumBitModelTotalBits) * p[prob];
|
||||
if (code < bound)
|
||||
uint bound = (_range >> K_NUM_BIT_MODEL_TOTAL_BITS) * _p[prob];
|
||||
if (_code < bound)
|
||||
{
|
||||
range = bound;
|
||||
p[prob] += (ushort)((kBitModelTotal - p[prob]) >> kNumMoveBits);
|
||||
if (range < kTopValue)
|
||||
_range = bound;
|
||||
_p[prob] += (ushort)((K_BIT_MODEL_TOTAL - _p[prob]) >> K_NUM_MOVE_BITS);
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
range <<= 8;
|
||||
code = (code << 8) | control[controlPos++];
|
||||
_range <<= 8;
|
||||
_code = (_code << 8) | _control[_controlPos++];
|
||||
}
|
||||
prevByte = b;
|
||||
_prevByte = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
range -= bound;
|
||||
code -= bound;
|
||||
p[prob] -= (ushort)(p[prob] >> kNumMoveBits);
|
||||
if (range < kTopValue)
|
||||
_range -= bound;
|
||||
_code -= bound;
|
||||
_p[prob] -= (ushort)(_p[prob] >> K_NUM_MOVE_BITS);
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
range <<= 8;
|
||||
code = (code << 8) | control[controlPos++];
|
||||
_range <<= 8;
|
||||
_code = (_code << 8) | _control[_controlPos++];
|
||||
}
|
||||
|
||||
uint dest;
|
||||
@@ -178,24 +178,24 @@ namespace SharpCompress.Compressors.Filters
|
||||
{
|
||||
dest =
|
||||
(uint)
|
||||
((data1[data1Pos++] << 24) | (data1[data1Pos++] << 16) | (data1[data1Pos++] << 8) |
|
||||
data1[data1Pos++]);
|
||||
((_data1[_data1Pos++] << 24) | (_data1[_data1Pos++] << 16) | (_data1[_data1Pos++] << 8) |
|
||||
_data1[_data1Pos++]);
|
||||
}
|
||||
else
|
||||
{
|
||||
dest =
|
||||
(uint)
|
||||
((data2[data2Pos++] << 24) | (data2[data2Pos++] << 16) | (data2[data2Pos++] << 8) |
|
||||
data2[data2Pos++]);
|
||||
((_data2[_data2Pos++] << 24) | (_data2[_data2Pos++] << 16) | (_data2[_data2Pos++] << 8) |
|
||||
_data2[_data2Pos++]);
|
||||
}
|
||||
dest -= (uint)(position + 4);
|
||||
dest -= (uint)(_position + 4);
|
||||
|
||||
output[0] = (byte)dest;
|
||||
output[1] = (byte)(dest >> 8);
|
||||
output[2] = (byte)(dest >> 16);
|
||||
output[3] = (byte)(dest >> 24);
|
||||
outputOffset = 0;
|
||||
outputCount = 4;
|
||||
_output[0] = (byte)dest;
|
||||
_output[1] = (byte)(dest >> 8);
|
||||
_output[2] = (byte)(dest >> 16);
|
||||
_output[3] = (byte)(dest >> 24);
|
||||
_outputOffset = 0;
|
||||
_outputCount = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ namespace SharpCompress.Compressors.Filters
|
||||
|
||||
private static readonly int[] MASK_TO_BIT_NUMBER = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
|
||||
private int pos;
|
||||
private int prevMask;
|
||||
private int _pos;
|
||||
private int _prevMask;
|
||||
|
||||
public BCJFilter(bool isEncoder, Stream baseStream)
|
||||
: base(isEncoder, baseStream, 5)
|
||||
{
|
||||
pos = 5;
|
||||
_pos = 5;
|
||||
}
|
||||
|
||||
private static bool test86MSByte(byte b)
|
||||
private static bool Test86MsByte(byte b)
|
||||
{
|
||||
return b == 0x00 || b == 0xFF;
|
||||
}
|
||||
@@ -39,18 +39,18 @@ namespace SharpCompress.Compressors.Filters
|
||||
if ((prevPos & ~3) != 0)
|
||||
{
|
||||
// (unsigned)prevPos > 3
|
||||
prevMask = 0;
|
||||
_prevMask = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevMask = (prevMask << (prevPos - 1)) & 7;
|
||||
if (prevMask != 0)
|
||||
_prevMask = (_prevMask << (prevPos - 1)) & 7;
|
||||
if (_prevMask != 0)
|
||||
{
|
||||
if (!MASK_TO_ALLOWED_STATUS[prevMask] || test86MSByte(
|
||||
buffer[i + 4 - MASK_TO_BIT_NUMBER[prevMask]]))
|
||||
if (!MASK_TO_ALLOWED_STATUS[_prevMask] || Test86MsByte(
|
||||
buffer[i + 4 - MASK_TO_BIT_NUMBER[_prevMask]]))
|
||||
{
|
||||
prevPos = i;
|
||||
prevMask = (prevMask << 1) | 1;
|
||||
_prevMask = (_prevMask << 1) | 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace SharpCompress.Compressors.Filters
|
||||
|
||||
prevPos = i;
|
||||
|
||||
if (test86MSByte(buffer[i + 4]))
|
||||
if (Test86MsByte(buffer[i + 4]))
|
||||
{
|
||||
int src = buffer[i + 1]
|
||||
| (buffer[i + 2] << 8)
|
||||
@@ -67,22 +67,22 @@ namespace SharpCompress.Compressors.Filters
|
||||
int dest;
|
||||
while (true)
|
||||
{
|
||||
if (isEncoder)
|
||||
if (_isEncoder)
|
||||
{
|
||||
dest = src + (pos + i - offset);
|
||||
dest = src + (_pos + i - offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
dest = src - (pos + i - offset);
|
||||
dest = src - (_pos + i - offset);
|
||||
}
|
||||
|
||||
if (prevMask == 0)
|
||||
if (_prevMask == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int index = MASK_TO_BIT_NUMBER[prevMask] * 8;
|
||||
if (!test86MSByte((byte)(dest >> (24 - index))))
|
||||
int index = MASK_TO_BIT_NUMBER[_prevMask] * 8;
|
||||
if (!Test86MsByte((byte)(dest >> (24 - index))))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -98,15 +98,15 @@ namespace SharpCompress.Compressors.Filters
|
||||
}
|
||||
else
|
||||
{
|
||||
prevMask = (prevMask << 1) | 1;
|
||||
_prevMask = (_prevMask << 1) | 1;
|
||||
}
|
||||
}
|
||||
|
||||
prevPos = i - prevPos;
|
||||
prevMask = ((prevPos & ~3) != 0) ? 0 : prevMask << (prevPos - 1);
|
||||
_prevMask = ((prevPos & ~3) != 0) ? 0 : _prevMask << (prevPos - 1);
|
||||
|
||||
i -= offset;
|
||||
pos += i;
|
||||
_pos += i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,109 +5,109 @@ namespace SharpCompress.Compressors.Filters
|
||||
{
|
||||
internal abstract class Filter : Stream
|
||||
{
|
||||
protected bool isEncoder;
|
||||
protected Stream baseStream;
|
||||
protected bool _isEncoder;
|
||||
protected Stream _baseStream;
|
||||
|
||||
private readonly byte[] tail;
|
||||
private readonly byte[] window;
|
||||
private int transformed;
|
||||
private int read;
|
||||
private bool endReached;
|
||||
private bool isDisposed;
|
||||
private readonly byte[] _tail;
|
||||
private readonly byte[] _window;
|
||||
private int _transformed;
|
||||
private int _read;
|
||||
private bool _endReached;
|
||||
private bool _isDisposed;
|
||||
|
||||
protected Filter(bool isEncoder, Stream baseStream, int lookahead)
|
||||
{
|
||||
this.isEncoder = isEncoder;
|
||||
this.baseStream = baseStream;
|
||||
tail = new byte[lookahead - 1];
|
||||
window = new byte[tail.Length * 2];
|
||||
_isEncoder = isEncoder;
|
||||
_baseStream = baseStream;
|
||||
_tail = new byte[lookahead - 1];
|
||||
_window = new byte[_tail.Length * 2];
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (isDisposed)
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isDisposed = true;
|
||||
_isDisposed = true;
|
||||
base.Dispose(disposing);
|
||||
baseStream.Dispose();
|
||||
_baseStream.Dispose();
|
||||
}
|
||||
|
||||
public override bool CanRead => !isEncoder;
|
||||
public override bool CanRead => !_isEncoder;
|
||||
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => isEncoder;
|
||||
public override bool CanWrite => _isEncoder;
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override long Length => baseStream.Length;
|
||||
public override long Length => _baseStream.Length;
|
||||
|
||||
public override long Position { get => baseStream.Position; set => throw new NotSupportedException(); }
|
||||
public override long Position { get => _baseStream.Position; set => throw new NotSupportedException(); }
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
if (transformed > 0)
|
||||
if (_transformed > 0)
|
||||
{
|
||||
int copySize = transformed;
|
||||
int copySize = _transformed;
|
||||
if (copySize > count)
|
||||
{
|
||||
copySize = count;
|
||||
}
|
||||
Buffer.BlockCopy(tail, 0, buffer, offset, copySize);
|
||||
transformed -= copySize;
|
||||
read -= copySize;
|
||||
Buffer.BlockCopy(_tail, 0, buffer, offset, copySize);
|
||||
_transformed -= copySize;
|
||||
_read -= copySize;
|
||||
offset += copySize;
|
||||
count -= copySize;
|
||||
size += copySize;
|
||||
Buffer.BlockCopy(tail, copySize, tail, 0, read);
|
||||
Buffer.BlockCopy(_tail, copySize, _tail, 0, _read);
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
int inSize = read;
|
||||
int inSize = _read;
|
||||
if (inSize > count)
|
||||
{
|
||||
inSize = count;
|
||||
}
|
||||
Buffer.BlockCopy(tail, 0, buffer, offset, inSize);
|
||||
read -= inSize;
|
||||
Buffer.BlockCopy(tail, inSize, tail, 0, read);
|
||||
while (!endReached && inSize < count)
|
||||
Buffer.BlockCopy(_tail, 0, buffer, offset, inSize);
|
||||
_read -= inSize;
|
||||
Buffer.BlockCopy(_tail, inSize, _tail, 0, _read);
|
||||
while (!_endReached && inSize < count)
|
||||
{
|
||||
int baseRead = baseStream.Read(buffer, offset + inSize, count - inSize);
|
||||
int baseRead = _baseStream.Read(buffer, offset + inSize, count - inSize);
|
||||
inSize += baseRead;
|
||||
if (baseRead == 0)
|
||||
{
|
||||
endReached = true;
|
||||
_endReached = true;
|
||||
}
|
||||
}
|
||||
while (!endReached && read < tail.Length)
|
||||
while (!_endReached && _read < _tail.Length)
|
||||
{
|
||||
int baseRead = baseStream.Read(tail, read, tail.Length - read);
|
||||
read += baseRead;
|
||||
int baseRead = _baseStream.Read(_tail, _read, _tail.Length - _read);
|
||||
_read += baseRead;
|
||||
if (baseRead == 0)
|
||||
{
|
||||
endReached = true;
|
||||
_endReached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (inSize > tail.Length)
|
||||
if (inSize > _tail.Length)
|
||||
{
|
||||
transformed = Transform(buffer, offset, inSize);
|
||||
offset += transformed;
|
||||
count -= transformed;
|
||||
size += transformed;
|
||||
inSize -= transformed;
|
||||
transformed = 0;
|
||||
_transformed = Transform(buffer, offset, inSize);
|
||||
offset += _transformed;
|
||||
count -= _transformed;
|
||||
size += _transformed;
|
||||
inSize -= _transformed;
|
||||
_transformed = 0;
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
@@ -115,20 +115,20 @@ namespace SharpCompress.Compressors.Filters
|
||||
return size;
|
||||
}
|
||||
|
||||
Buffer.BlockCopy(buffer, offset, window, 0, inSize);
|
||||
Buffer.BlockCopy(tail, 0, window, inSize, read);
|
||||
if (inSize + read > tail.Length)
|
||||
Buffer.BlockCopy(buffer, offset, _window, 0, inSize);
|
||||
Buffer.BlockCopy(_tail, 0, _window, inSize, _read);
|
||||
if (inSize + _read > _tail.Length)
|
||||
{
|
||||
transformed = Transform(window, 0, inSize + read);
|
||||
_transformed = Transform(_window, 0, inSize + _read);
|
||||
}
|
||||
else
|
||||
{
|
||||
transformed = inSize + read;
|
||||
_transformed = inSize + _read;
|
||||
}
|
||||
Buffer.BlockCopy(window, 0, buffer, offset, inSize);
|
||||
Buffer.BlockCopy(window, inSize, tail, 0, read);
|
||||
Buffer.BlockCopy(_window, 0, buffer, offset, inSize);
|
||||
Buffer.BlockCopy(_window, inSize, _tail, 0, _read);
|
||||
size += inSize;
|
||||
transformed -= inSize;
|
||||
_transformed -= inSize;
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace SharpCompress.Compressors.Filters
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
Transform(buffer, offset, count);
|
||||
baseStream.Write(buffer, offset, count);
|
||||
_baseStream.Write(buffer, offset, count);
|
||||
}
|
||||
|
||||
protected abstract int Transform(byte[] buffer, int offset, int count);
|
||||
|
||||
Reference in New Issue
Block a user