Moved LZRW1CompressionModule into Modules

This commit is contained in:
Michael Becker 2014-04-20 13:12:36 -04:00
parent 61fe76671b
commit d4da2d6708
2 changed files with 90 additions and 1 deletions

View File

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.Compression.Modules.LZRW1
{
public class LZRW1CompressionModule : CompressionModule
{
/// <summary>
/// Number of bytes used by copy flag
/// </summary>
private const byte FLAG_BYTES = 0x04;
private const byte FLAG_COMPRESS = 0x00;
private const byte FLAG_COPY = 0x01;
public static byte[] Decompress(byte[] input)
{
byte[] output = null;
if (input[0] == FLAG_COPY)
{
output = new byte[input.Length - FLAG_BYTES];
Array.Copy(input, FLAG_BYTES, output, 0, input.Length - FLAG_BYTES);
}
else
{
ushort controlbits = 0, control = 0;
int p_src = FLAG_BYTES;
Accessors.MemoryAccessor ma = new Accessors.MemoryAccessor();
IO.Writer bw = new IO.Writer(ma);
while (p_src != input.Length)
{
if (controlbits == 0)
{
control = input[p_src++];
control |= (ushort)(input[p_src] << 8);
controlbits = 16;
}
if ((control & 1) != 0)
{
ushort offset, len;
int p;
offset = (ushort)((input[p_src] & 0xF0) << 4);
len = (ushort)(1 + (input[p_src++] & 0xF));
offset += (ushort)(input[p_src++] & 0xFF);
bw.Flush();
byte[] out1 = ma.ToArray();
p = out1.Length - offset;
while (len-- != 0)
{
bw.WriteByte(out1[p++]);
}
}
else
{
bw.WriteByte(input[p_src++]);
}
control >>= 1;
controlbits--;
}
bw.Flush();
bw.Close();
output = ma.ToArray();
}
return output;
}
public override string Name
{
get { return "LZRW1"; }
}
protected override void CompressInternal(System.IO.Stream inputStream, System.IO.Stream outputStream)
{
throw new NotImplementedException();
}
protected override void DecompressInternal(System.IO.Stream inputStream, System.IO.Stream outputStream, int inputLength, int outputLength)
{
throw new NotImplementedException();
}
}
}

View File

@ -63,7 +63,7 @@
<Compile Include="LZH\LZHStream.cs" />
<Compile Include="LZMA\LZMAStream.cs" />
<Compile Include="LZPL2\LZPL2CompressionModule.cs" />
<Compile Include="LZRW1\LZRW1CompressionModule.cs" />
<Compile Include="Modules\LZRW1\LZRW1CompressionModule.cs" />
<Compile Include="LZSS\LZSS2.cs" />
<Compile Include="LZSS\LZSSCompressionModule.cs" />
<Compile Include="LZW\Internal\Element.cs" />