private void SaveByArithmeticMethod() { const uint numSymbols = ((maxValuePixel * 2) + 1), eof = numSymbols - 1; ArithmeticCodingLogic arithmCoder = new ArithmeticCodingLogic(bitWriterContext: _bitwriter, total_symbols: numSymbols, eof: eof); for (int i = 0; i < _imgLength; i++) { for (int j = 0; j < _imgLength; j++) { uint symbol = (uint)(_imgPred._errorPredQ[i, j] + (maxValuePixel)); arithmCoder.EncodeImageErrorValue(symbol); } } arithmCoder.SendLastDetailsOfImageError(); _bitwriter.Dispose(); }
private List <int> readArithmeticCompressedFile() { const uint numSymbols = (_imgLength * 2), eof = numSymbols - 1; List <int> values = new List <int>(); ArithmeticCodingLogic arithmCoder = new ArithmeticCodingLogic(bitReaderContext: _bitReader, total_symbols: numSymbols, eof: eof); arithmCoder._decodingValue = _bitReader.ReadNBits(32); for (; ;) { uint symbol = arithmCoder.DecodeSymbol(); if (symbol == eof) // eof { arithmCoder._bitReader.Dispose(); break; } int symbolToErrorRange = (int)symbol - (_imgLength - 1); values.Add(symbolToErrorRange); arithmCoder.UpdateModel(symbol); } return(values); }