public void OpenForWrite(string fileName) { if (_fileWriter == null) { _fileWriter = new FileWriter(); } _fileWriter.Open(fileName); }
public void DecodeFile(string sourceFilepath, string destinationFilepath) { fileReader.Open(sourceFilepath); fileWriter.Open(destinationFilepath); fileReader.Close(); fileWriter.Close(); throw new System.NotImplementedException(); }
public void TestThatFileIsCopiedCorrectlyForNumberOfBitsBetween1And8(string fileTextContents) { TestMethods.CreateFileWithTextContents(filepathSource, fileTextContents); var random = new Random(); fileReader.Open(filepathSource); fileWriter.Open(filepathDestination); while (!fileReader.ReachedEndOfFile) { var numberOfBits = fileReader.BitsLeft < 8 ? (byte)fileReader.BitsLeft : (byte)random.Next(1, 8); var readStuff = fileReader.ReadBits(numberOfBits); fileWriter.WriteValueOnBits(readStuff, numberOfBits); } fileReader.Close(); fileWriter.Close(); Assert.IsTrue(TestMethods.FilesHaveTheSameContent(filepathSource, filepathDestination)); }
public void EncodeFile(string sourceFilepath, string destinationFilepath) { fileReader.Open(sourceFilepath); var sourceFileBytes = GetAllBytesFromSourceFile(); fileReader.Close(); InitializeSymbolDictionaryFromBytes(sourceFileBytes); fileWriter.Open(destinationFilepath); fileWriter.Close(); throw new System.NotImplementedException(); }
public ImageMatrices Decode(string sourceFilepath, string destinationFilepath) { fileReader.Open(sourceFilepath); fileWriter.Open(destinationFilepath); CopyBitmapHeader(); var usedOptions = GetOptions(); var errorMatrixReader = NearLosslessErrorMatrixReaderSelector.GetErrorMatrixReader(usedOptions.SaveMode); var quantizedErrorMatrix = errorMatrixReader.ReadErrorMatrix(fileReader); var imageMatrices = ErrorMatrixHelper.GetImageMatricesFromQuantizedErrorMatrix(quantizedErrorMatrix, usedOptions); WriteImageCodes(imageMatrices.Decoded); fileReader.Close(); fileWriter.Close(); return(imageMatrices); }
private void RunForThisNumberOfBits(byte numberOfBits) { fileReader.Open(filepathSource); fileWriter.Open(filepathDestination); while (!fileReader.ReachedEndOfFile) { var numberOfBitsForCurrentIteration = fileReader.BitsLeft < numberOfBits ? (byte)fileReader.BitsLeft : numberOfBits; var readStuff = fileReader.ReadBits(numberOfBitsForCurrentIteration); fileWriter.WriteValueOnBits(readStuff, numberOfBitsForCurrentIteration); } fileReader.Close(); fileWriter.Close(); }
public void Encode(string sourceFilepath, string destinationFilepath, NearLosslessOptions nearLosslessOptions) { var image = GetImageOrThrow(sourceFilepath); var imageMatrices = new ImageMatrices(image); image.Dispose(); PredictionMatrixHelper.SetImageMatrices(imageMatrices, nearLosslessOptions); fileReader.Open(sourceFilepath); fileWriter.Open(destinationFilepath); CopyBitmapHeader(); WriteOptions(nearLosslessOptions); var errorMatrixWriter = NearLosslessErrorMatrixWriterSelector.GetErrorMatrixWriter(nearLosslessOptions.SaveMode); errorMatrixWriter.WriteErrorMatrix(imageMatrices.QuantizedErrors, fileWriter); fileWriter.Flush(); fileReader.Close(); fileWriter.Close(); }