示例#1
0
 public void OpenForWrite(string fileName)
 {
     if (_fileWriter == null)
     {
         _fileWriter = new FileWriter();
     }
     _fileWriter.Open(fileName);
 }
示例#2
0
        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));
        }
示例#4
0
        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);
        }
示例#6
0
        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();
        }