public GetBytesFreqs ( bool reducedLines, int lengthBitsCount, List |
||
reducedLines | bool | |
lengthBitsCount | int | |
compressedFrames | List |
|
return | FreakySources.Code.ByteCount[] |
public ByteCount[] GetBytesFreqs(bool reducedLines, int lengthBitsCount, List<CompressedFrame> compressedFrames)
{
int maxRepeatCount = (1 << (lengthBitsCount - 1)) + 1;
var result = new List<ByteCount>();
for (int i = 0; i < 256; i++)
result.Add(new ByteCount { Byte = (byte)i, Count = 0 });
int length = 0;
for (int k = 0; k < compressedFrames.Count; k++)
{
if (compressedFrames[k].FrameType == FrameType.Basic)
{
string line;
if (!reducedLines)
line = Frames[k].Line;
else
line = Frames[k].ReducedLine;
int i = 0;
while (i < line.Length)
{
result[(int)line[i]].Count++;
length++;
var beginChar = line[i];
int j;
for (j = i + 1; j < line.Length; j++)
if (line[j] != beginChar || j - i >= maxRepeatCount)
break;
i = j;
}
}
else
{
foreach (var change in compressedFrames[k].FrameChanges)
foreach (var c in change.Chars)
result[(int)c].Count++;
}
}
result = result.Where(bc => bc.Count != 0).OrderByDescending(bc => bc.Count).ToList();
return result.ToArray();
}
AsciimationDataGenerator::GetBytesFreqs ( bool reducedLines = false, int lengthBitsCount = 8 ) : FreakySources.Code.ByteCount[] |
public void HuffmanRleFull() { var generator = new AsciimationDataGenerator(AsciimationData); var bytesFreqs = generator.GetBytesFreqs(false); var bytes = AsciimationDataGenerator.SerializeByteCount(bytesFreqs); var huffmanTable = Convert.ToBase64String(bytes); var tree = new HuffmanTree(bytesFreqs); var encodedTable = Convert.ToBase64String(bytes); var encodedFrames = new List<string>(); for (int i = 0; i < generator.Frames.Length; i++) { var frame = generator.Frames[i]; encodedFrames.Add(Convert.ToBase64String(HuffmanRle.Encode(tree, frame.Bytes))); } var decodedTree = new HuffmanTree(AsciimationDataGenerator.DeserializeByteCount(Base64.DecodeBase64(encodedTable))); var decodedFrames = new List<string>(); for (int i = 0; i < encodedFrames.Count; i++) { var frame = HuffmanRle.Decode(decodedTree, Base64.DecodeBase64(encodedFrames[i])); CollectionAssert.AreEqual(generator.Frames[i].Bytes, frame); } }