private void GetImageFromFileReader(IFileReader fileReader)
 {
     fileReader.Close();
     using (var fileStream = new FileStream(fileReader.FilePath, FileMode.Open))
     {
         var bmp = new Bitmap(fileStream);
         OriginalImage = bmp;
     }
     fileReader.Open();
 }
Exemplo n.º 2
0
        public void DecodeFile(string sourceFilepath, string destinationFilepath)
        {
            fileReader.Open(sourceFilepath);
            fileWriter.Open(destinationFilepath);

            fileReader.Close();
            fileWriter.Close();

            throw new System.NotImplementedException();
        }
Exemplo n.º 3
0
 public void Close()
 {
     try
     {
         _reader.Close();
     }
     catch (Exception ex)
     {
         Log.Error("Error on close reader", ex);
     }
 }
        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));
        }
Exemplo n.º 5
0
        public IList <ImportResultItem <TEntity> > Read(string file)
        {
            _fileReader.Open(file);
            CheckTitles();

            try
            {
                var result = ImportResultItems();
                return(result);
            }
            finally
            {
                _fileReader.Close();
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 8
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();
        }
        private void ValidateImageFromFileReader(IFileReader fileReader)
        {
            if (!fileReader.FilePath.EndsWith(".bmp"))
            {
                throw new InvalidOperationException("Only bmp images can be encoded");
            }

            fileReader.Close();
            var image = new Bitmap(fileReader.FilePath);

            try
            {
                if (image.Size != new Size(256, 256))
                {
                    throw new InvalidOperationException("Image must be 256x256");
                }
            }
            finally
            {
                image.Dispose();
                fileReader.Open();
            }
        }
Exemplo n.º 11
0
 public void Close()
 {
     _fileReader?.Close();
     _fileWriter?.Close();
 }