Ejemplo n.º 1
0
        public void ImageDecodingBlockErrorsTest()
        {
            Bitmap originalImage;
            var    fileStream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "/sandwich.bmp", FileMode.Open, FileAccess.Read);

            using (fileStream)
            {
                originalImage = new Bitmap(fileStream);
            }
            fileStream.Close();

            var reedSolomon = new ReedSolomon(32);
            var data        = ImageProcessing.GetRawBytesFromRGBImage(originalImage);

            var originalData = new int[data.Length];

            Array.Copy(data, originalData, data.Length);

            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            var errorsCount = ErrorProvider.FillInGroupErrorsForEveryBlock(modifiedData, 16, 255);

            reedSolomon.SimplyDecodeRawBytesArray(modifiedData, data);

            var processedImage = ImageProcessing.GetRGBImageFromRawBytes(originalImage, data);

            Bitmap diffImage;
            var    diffCount = ImageProcessing.Compare(processedImage, originalImage, out diffImage);

            var bytesDiffCount = GetDiffTable(originalData, data);

            Assert.AreEqual(0, bytesDiffCount.Count);
            Assert.AreEqual(0, diffCount);
        }
Ejemplo n.º 2
0
        private void ProcessImageTransmissionSimulation(Params parms, int iterator, int fileOrder)
        {
            var       errorMeasureValue    = parms.ErrorMeasureValue;
            var       correctionBytesCount = parms.CorrectionBytesCount;
            var       decoderType          = parms.RsDecoderType;
            var       errorProviderType    = parms.RsErrorProviderType;
            var       orderNo   = parms.OrderNo;
            const int blockSize = 255;
            var       tries     = 0;

            object clonedImage = null;

            while (clonedImage == null && tries < 5)
            {
                try
                {
                    clonedImage = iterator % 2 == 0 ? _originalImage0.Clone() : _originalImage1.Clone();
                }
                catch (InvalidOperationException ioe)
                {
                    tries++;
                }
            }
            if (tries >= 5)
            {
                return;
            }

            var image       = (Bitmap)clonedImage;
            var stopwatch   = new Stopwatch();
            var reedSolomon = new ReedSolomon(correctionBytesCount);
            var data        = ImageProcessing.GetRawBytesFromRGBImage(image);

            stopwatch.Reset();
            stopwatch.Start();
            var modifiedData = reedSolomon.EncodeRawBytesArray(data);

            stopwatch.Stop();

            var errorsCount = 0;

            switch (errorProviderType)
            {
            case ErrorProviderType.ErrorsTotalCount:
                errorsCount = ErrorProvider.FillInErrors(modifiedData, errorMeasureValue);
                break;

            case ErrorProviderType.PercentageOfErrors:
                errorsCount = ErrorProvider.FillInPercentageOfErrors(modifiedData, errorMeasureValue);
                break;

            case ErrorProviderType.SingleErrorsForEveryBlock:
                errorsCount = ErrorProvider.FillInErrorsForEveryBlock(modifiedData, errorMeasureValue, blockSize);
                break;

            case ErrorProviderType.ErrorsWithProbability:
                errorsCount = ErrorProvider.FillInErrorsWithProbability(modifiedData, (double)errorMeasureValue / 100);
                break;

            case ErrorProviderType.GroupErrorsForEveryBlock:
                errorsCount = ErrorProvider.FillInGroupErrorsForEveryBlock(modifiedData, errorMeasureValue, blockSize);
                break;
            }

            stopwatch.Start();
            if (decoderType.Equals(DecoderType.Extended))
            {
                reedSolomon.DecodeRawBytesArray(modifiedData, data);
            }
            else
            {
                reedSolomon.SimplyDecodeRawBytesArray(modifiedData, data);
            }
            stopwatch.Stop();

            var processedImage = ImageProcessing.GetRGBImageFromRawBytes(image, data);

            var diffCount = 0;

            try
            {
                Bitmap diffImage;
                diffCount = ImageProcessing.Compare(processedImage, image, out diffImage);
            }
            catch (InvalidOperationException ioe)
            {
                var singleResultException = new List <int>
                {
                    errorMeasureValue,
                    (int)errorProviderType,
                    correctionBytesCount,
                    (int)decoderType,
                    0,
                    0,
                    0,
                    orderNo,
                    fileOrder
                };

                _results.TryAdd(singleResultException);
                return;
            }

            var singleResult = new List <int>
            {
                errorMeasureValue,
                (int)errorProviderType,
                correctionBytesCount,
                (int)decoderType,
                errorsCount,
                (int)stopwatch.ElapsedMilliseconds,
                diffCount,
                orderNo,
                fileOrder
            };

            _results.TryAdd(singleResult);
        }