private List <byte> CreateSymbolsMapByteList(HuffmanEncodeModel huffmanEncodeModel, Dictionary <string, OutputValues> symbolsMap, bool specialSymbol) { List <byte> symbolsMapByteList = new List <byte>(); char specialSymbolCharacter = '0'; ushort specialSymbolCounts = 0; foreach (KeyValuePair <string, OutputValues> symbol in symbolsMap) { string symbolKey = symbol.Key; if (symbolKey.Length == 1 && huffmanEncodeModel != HuffmanEncodeModel.Standard) { specialSymbolCharacter = symbolKey[0]; specialSymbolCounts = symbol.Value.Counts; } else { symbolsMapByteList.AddRange(ToByteArray(symbolKey)); symbolsMapByteList.AddRange(new List <byte>(BitConverter.GetBytes(symbol.Value.Counts))); } } if (specialSymbol) { symbolsMapByteList.Add(Convert.ToByte(specialSymbolCharacter)); symbolsMapByteList.AddRange(new List <byte>(BitConverter.GetBytes(specialSymbolCounts))); } return(symbolsMapByteList); }
public Statistics Encode(string inputFilePath, string outputFilePath, HuffmanEncodeModel huffmanEncodeModel) { Statistics statiscs; IHuffmanCoderInterface huffmanCoderInterface; IStatisticsBuilder statisticsBuilder = new StatisticsBuilder(); using (IInputReader input = new InputReader(inputFilePath)) { ICoderOutputWriter output = new CoderOutputWriter(new ByteCreator(), new HeaderCreator()); if (huffmanEncodeModel == HuffmanEncodeModel.Standard) { huffmanCoderInterface = new StandardHuffmanCoderInterface(input, output); } else if (huffmanEncodeModel == HuffmanEncodeModel.Block) { huffmanCoderInterface = new PairHuffmanCoderInterface(input, output); } else { huffmanCoderInterface = new MarkowHuffmanCoderInterface(input, output); } huffmanCoderInterface.Encode(); System.IO.File.WriteAllBytes(outputFilePath, output.FileBytes); statiscs = statisticsBuilder.BuildStatistics(output.SymbolMap, output.Header, input.Size, output.Size); if (huffmanEncodeModel == HuffmanEncodeModel.Standard) { IHistogramBuilder histogramBuilder = new HistogramBuilder(); histogramBuilder.BuildHistogram(output.SymbolMap, outputFilePath); } } return(statiscs); }
public void Read(byte[] map, bool specialSymbol, HuffmanEncodeModel huffmanEncodeModel) { switch (huffmanEncodeModel) { case HuffmanEncodeModel.Standard: StandardRead(map); break; case HuffmanEncodeModel.Block: case HuffmanEncodeModel.Markov: BlockMarkovRead(map, specialSymbol); break; } }
public void CreateFileBytes(HuffmanEncodeModel huffmanEncodeModel, bool specialSymbol, Dictionary <string, OutputValues> map) { Header header = headerCreator.Create(huffmanEncodeModel, specialSymbol, map); this.header = header; this.symbolMap = map; if (byteCreator.IsEmpty == false) { ++currentSize; data.Add(byteCreator.Data); } fileBytes = header.Content.Concat(data).ToArray(); }
public Header Create(HuffmanEncodeModel huffmanEncodeModel, bool specialSymbol, Dictionary <string, OutputValues> symbolsMap) { byte huffmanEncodeModelByte = Convert.ToByte(huffmanEncodeModel); byte specialSymbolByte = Convert.ToByte(specialSymbol); List <byte> symbolsMapByteList = CreateSymbolsMapByteList(huffmanEncodeModel, symbolsMap, specialSymbol); byte[] headerContent = CreateHeaderFromBytes(huffmanEncodeModelByte, specialSymbolByte, symbolsMapByteList); Header header = new Header(); header.Content = headerContent; header.Size = (uint)headerContent.Length; return(header); }
public void CreateFileBytes(HuffmanEncodeModel huffmanEncodeMode, bool specialSymbol, Dictionary <string, OutputValues> map) { return; }