private byte[] GetCompressedFrameBytes(HuffmanTree tree, Frame frame, CompressedFrame compressedFrame) { int transBitPos = 0; var transZipBytes = new byte[frame.Bytes.Length * 10]; Utils.AddInt(transZipBytes, ref transBitPos, frame.RepeatCount, 7); Utils.AddInt(transZipBytes, ref transBitPos, (int)compressedFrame.FrameType, 3); Utils.AddInt(transZipBytes, ref transBitPos, compressedFrame.FrameChanges.Count, 7); for (int i = 0; i < compressedFrame.FrameChanges.Count; i++) { var change = compressedFrame.FrameChanges[i]; Utils.AddInt(transZipBytes, ref transBitPos, (int)change.Type, 2); Utils.AddInt(transZipBytes, ref transBitPos, GetPos(change.X, change.Y), 10); if (change.Type == FrameChangeType.One) { Utils.AddIntReversed(transZipBytes, ref transBitPos, tree.CompressedBytes[change.Chars[0]]); } else { Utils.AddInt(transZipBytes, ref transBitPos, change.Length, change.Type == FrameChangeType.Horizontal ? 7 : 4); //HuffmanRle.Encode(tree, change.Chars.Select(c => (byte)c).ToArray(), ref transBitPos, transZipBytes, 5, 4); for (int j = 0; j < change.Chars.Count; j++) { Utils.AddIntReversed(transZipBytes, ref transBitPos, tree.CompressedBytes[change.Chars[j]]); } /*if (i == 0 && compressedFrame.FrameType != FrameType.Basic && compressedFrame.FrameType != FrameType.Transitional) * HuffmanRle.Encode(tree, change.Chars.Select(c => (byte)c).ToArray(), ref transBitPos, transZipBytes, 5, 4); * else * for (int j = 0; j < change.Chars.Count; j++) * Utils.AddIntReversed(transZipBytes, ref transBitPos, tree.CompressedBytes[change.Chars[j]]);*/ } } return(transZipBytes.Take((transBitPos + 7) / 8).ToArray()); }
private byte[] GetCompressedFrameBytes(HuffmanTree tree, Frame frame, CompressedFrame compressedFrame) { int transBitPos = 0; var transZipBytes = new byte[frame.Bytes.Length * 10]; Utils.AddInt(transZipBytes, ref transBitPos, frame.RepeatCount, 7); Utils.AddInt(transZipBytes, ref transBitPos, (int)compressedFrame.FrameType, 3); Utils.AddInt(transZipBytes, ref transBitPos, compressedFrame.FrameChanges.Count, 7); for (int i = 0; i < compressedFrame.FrameChanges.Count; i++) { var change = compressedFrame.FrameChanges[i]; Utils.AddInt(transZipBytes, ref transBitPos, (int)change.Type, 2); Utils.AddInt(transZipBytes, ref transBitPos, GetPos(change.X, change.Y), 10); if (change.Type == FrameChangeType.One) Utils.AddIntReversed(transZipBytes, ref transBitPos, tree.CompressedBytes[change.Chars[0]]); else { Utils.AddInt(transZipBytes, ref transBitPos, change.Length, change.Type == FrameChangeType.Horizontal ? 7 : 4); //HuffmanRle.Encode(tree, change.Chars.Select(c => (byte)c).ToArray(), ref transBitPos, transZipBytes, 5, 4); for (int j = 0; j < change.Chars.Count; j++) Utils.AddIntReversed(transZipBytes, ref transBitPos, tree.CompressedBytes[change.Chars[j]]); /*if (i == 0 && compressedFrame.FrameType != FrameType.Basic && compressedFrame.FrameType != FrameType.Transitional) HuffmanRle.Encode(tree, change.Chars.Select(c => (byte)c).ToArray(), ref transBitPos, transZipBytes, 5, 4); else for (int j = 0; j < change.Chars.Count; j++) Utils.AddIntReversed(transZipBytes, ref transBitPos, tree.CompressedBytes[change.Chars[j]]);*/ } } return transZipBytes.Take((transBitPos + 7) / 8).ToArray(); }