public void LoadMatrixFromTxtFileReadsPredictionErrorCorrectly3X4Block()
        {
            SetTestBmpGz2DlzDecoderFacade();
            gz2DlzDecoderFacade.InputFilePath = _one3X4BlockBmpMatFileName;
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);
            int[,] expectedValues = new int[, ]
            {
                { 64, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { -32, -96, 0, 0, 0, 192, -96, 96, -96, -96 },
                { 64, -192, 0, 0, 0, 96, 96, -192, 255, -159 },
                { -64, -64, 0, 0, 0, 255, -159, 159, -159, -96 },
                { 127, -255, 0, 0, 0, 96, 96, -96, 96, -96 },
                { 64, -96, 159, -63, 63, -255, 0, 0, 0, 64 },
                { -64, 128, -96, 159, -159, 0, 0, 0, 0, 64 },
                { 64, -128, 128, -96, 96, 0, 0, 0, 0, 64 },
                { -64, 191, -159, 159, -159, 0, 0, 0, 0, 64 },
                { -128, 96, 96, -128, 191, -191, 191, -191, 191, -63 }
            };

            _decoder.LoadMatrixFromTxtFile();
            var predictionError = gz2DlzDecoderFacade.AbstractPredictor.PredictionError;

            var height = predictionError.GetLength(0);
            var width  = predictionError.GetLength(1);

            Assert.AreEqual(10, height);
            Assert.AreEqual(10, width);
            AssertEachValue(expectedValues, predictionError);
        }
        public void LoadMatrixFromTxtFileReadsMatchFlagCorrectlyFor3X4Block()
        {
            bool[,] expected =
            {
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, true,  false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false },
                { false, false, false, false, false, false, false, false, false, false }
            };
            SetTestBmpGz2DlzDecoderFacade();
            gz2DlzDecoderFacade.InputFilePath = _one3X4BlockBmpMatFileName;
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);

            _decoder.LoadMatrixFromTxtFile();

            var matchFlag = _decoder.IsMatchFound;

            Assert.AreEqual(10, matchFlag.GetLength(0));
            Assert.AreEqual(10, matchFlag.GetLength(1));
            AssertEachValue(expected, matchFlag);
        }
Beispiel #3
0
        public void EncodeAndDecodeWithCalicPredictorCustomTxtLena256AnCreatesAFileIndenticalWithTheOriginal()
        {
            IImageReader txtImageReader = new TxtAsImageReader();

            _gz2DlzEncoderFacade.InputFilePath     = _lenna256anTxtFileName;
            _gz2DlzEncoderFacade.AbstractPredictor = new ABasedPredictor();
            _gz2DlzEncoderFacade.ImageReader       = txtImageReader;
            _gz2DlzEncoderFacade.Archiver          = new Paq6V2Archiver();
            _encoder = new Gz2DlzEncoder(_gz2DlzEncoderFacade);

            var inputFilePath = $"{_lenna256anTxtFileName}.mat";

            gz2DlzDecoderFacade = new Gz2DlzDecoderFacade();
            gz2DlzDecoderFacade.InputFilePath     = inputFilePath;
            gz2DlzDecoderFacade.AbstractPredictor = new ABasedPredictor();
            gz2DlzDecoderFacade.Archiver          = new Paq6V2Archiver();
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);

            _encoder.Encode();
            _encoder.WriteMatrixToFileAsText();
            _decoder.LoadMatrixFromTxtFile();
            _decoder.Decode();
            _decoder.SaveOriginalImageAsTxtFile();

            var filename     = $"{_lenna256anTxtFileName}.mat.decoded.txt";
            var originalFile = GetContentWithoutNewLines(_lenna256anTxtFileName).Replace("256 256 ", "");
            var decodedFile  = GetContentWithoutNewLines(filename);

            Assert.AreEqual(originalFile.Length, decodedFile.Length);
            Assert.IsTrue(string.Equals(originalFile, decodedFile));
        }
        public void LoadMatrixFromTxtFileReadsMatchDimensionsCorrectly3X4Block()
        {
            /*x y x y ..
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 4 3 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
             */
            SetTestBmpGz2DlzDecoderFacade();
            gz2DlzDecoderFacade.InputFilePath = _one3X4BlockBmpMatFileName;
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);

            _decoder.LoadMatrixFromTxtFile();
            var matchDimensions = _decoder.MatchDimension;

            var height = matchDimensions.GetLength(0);
            var width  = matchDimensions.GetLength(1);

            Assert.AreEqual(10, height);
            Assert.AreEqual(10, width);

            Assert.AreEqual(4, matchDimensions[6, 5].Width);
            Assert.AreEqual(3, matchDimensions[6, 5].Height);

            for (int y = 0; y < 6; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    Assert.AreEqual(0, matchDimensions[y, x].Width);
                    Assert.AreEqual(0, matchDimensions[y, x].Height);
                }
            }

            for (int y = 6; y < height; y++)
            {
                for (int x = 6; x < width; x++)
                {
                    Assert.AreEqual(0, matchDimensions[y, x].Width);
                    Assert.AreEqual(0, matchDimensions[y, x].Height);
                }
            }
        }
        public void LoadMatrixFromTxtFileReadsMatchFlagCorrectly()
        {
            SetTestBmpGz2DlzDecoderFacade();
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);

            _decoder.LoadMatrixFromTxtFile();

            var matchFlag = _decoder.IsMatchFound;

            Assert.AreEqual(5, matchFlag.GetLength(0));
            Assert.AreEqual(6, matchFlag.GetLength(1));

            for (int y = 0; y < matchFlag.GetLength(0); y++)
            {
                for (int x = 0; x < matchFlag.GetLength(1); x++)
                {
                    Assert.AreEqual(false, matchFlag[y, x]);
                }
            }
        }
        public void LoadMatrixFromTxtFileReadsResidualCorrectly()
        {
            SetTestBmpGz2DlzDecoderFacade();
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);

            _decoder.LoadMatrixFromTxtFile();
            var residual = _decoder.Residual;

            var height = residual.GetLength(0);
            var width  = residual.GetLength(1);

            Assert.AreEqual(5, height);
            Assert.AreEqual(6, width);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Assert.AreEqual(0, residual[y, x]);
                }
            }
        }
        public void LoadMatrixFromTxtFileReadsMatchDimensionsCorrectly()
        {
            SetTestBmpGz2DlzDecoderFacade();
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);

            _decoder.LoadMatrixFromTxtFile();
            var matchDimensions = _decoder.MatchDimension;

            var height = matchDimensions.GetLength(0);
            var width  = matchDimensions.GetLength(1);

            Assert.AreEqual(5, height);
            Assert.AreEqual(6, width);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Assert.AreEqual(0, matchDimensions[y, x].Width);
                    Assert.AreEqual(0, matchDimensions[y, x].Height);
                }
            }
        }
        public void LoadMatrixFromTxtFileReadsPredictionErrorCorrectly()
        {
            SetTestBmpGz2DlzDecoderFacade();
            _decoder = new Gz2DlzDecoder(gz2DlzDecoderFacade);
            int[,] expectedValues = new int[, ]
            {
                { -128, 255, -255, 255, -255, 255 },
                { -128, 255, -255, 255, -255, 0 },
                { 127, -255, 0, 0, 255, 0 },
                { -128, 255, -255, 255, -255, 255 },
                { 127, -255, 255, 0, -255, 0 }
            };

            _decoder.LoadMatrixFromTxtFile();
            var predictionError = gz2DlzDecoderFacade.AbstractPredictor.PredictionError;

            var height = predictionError.GetLength(0);
            var width  = predictionError.GetLength(1);

            Assert.AreEqual(5, height);
            Assert.AreEqual(6, width);

            AssertEachValue(expectedValues, predictionError);
        }