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); }