Ejemplo n.º 1
0
        public IEnumerable <int> Process(IEnumerable <Color> colors)
        {
            var colorList = colors.ToArray();

            _quantizer.CreatePalette(colorList);

            var processingAction = new Action <LineTask <Color[], int[]> >(taskModel =>
            {
                var matrixWidth  = Matrix.GetLength(0);
                var matrixHeight = Matrix.GetLength(1);

                for (int i = taskModel.Start; i < taskModel.Start + taskModel.Length; i++)
                {
                    int x = i % _width % matrixWidth;
                    int y = i / _width % matrixHeight;

                    int threshold = Convert.ToInt32(Matrix[x, y]);
                    var color     = taskModel.Input[i];

                    int red   = GetClampedValue(color.R + threshold, 0, 255);
                    int green = GetClampedValue(color.G + threshold, 0, 255);
                    int blue  = GetClampedValue(color.B + threshold, 0, 255);

                    taskModel.Output[i] = _quantizer.GetPaletteIndex(Color.FromArgb(color.A, red, green, blue));
                }
            });

            var indices = new int[colorList.Length];

            ParallelProcessing.ProcessList(colorList, indices, processingAction, _quantizer.TaskCount);

            return(indices);
        }
        public IEnumerable <int> Process(IEnumerable <Color> colors)
        {
            if (_quantizer == null)
            {
                throw new ArgumentNullException(nameof(_quantizer));
            }
            if (ErrorFactorMatrix == null)
            {
                throw new ArgumentNullException(nameof(ErrorFactorMatrix));
            }

            var colorList = colors.ToArray();

            _quantizer.CreatePalette(colorList);

            var indices         = new int[colorList.Length];
            var errorComponents = new ColorComponentError[colorList.Length];

            for (int i = 0; i < errorComponents.Length; i++)
            {
                errorComponents[i] = new ColorComponentError(0, 0, 0);
            }
            var errors =
                new ErrorDiffusionList <Color, ColorComponentError>(colorList, errorComponents)
                .ToArray();

            ParallelProcessing.ProcessList(
                errors, indices, _width,
                MatrixSideWidth + 1, _quantizer.TaskCount, ProcessingAction);

            return(indices);
        }
Ejemplo n.º 3
0
        public IProcessing GetProcessing()
        {
            IProcessing processing = new ParallelProcessing();

            processing.Init(new GZipDecompressionTask(), new FileBlockReader(), new FileRawWriter());
            return(processing);
        }
        public async Task SingularThreadTest()
        {
            var _proc = new ParallelProcessing <string, int>();
            var r = new Reader(_str); var o = new OutputWrite <string, int>();

            await _proc.SingularTask(r, o, CancellationToken.None);

            CollectionAssert.AllItemsAreUnique(o, "");
            Assert.IsTrue(o.Count > 0);
            Assert.AreEqual(o["a"], 6);
            Assert.AreEqual(o["as"], 4);
            Assert.AreEqual(o["to"], 7);
        }
Ejemplo n.º 5
0
        public IEnumerable <int> Process(IEnumerable <Color> colors, IColorCache colorCache)
        {
            _colorCache = colorCache;

            var count           = _imageSize.Width * _imageSize.Height;
            var errorComponents = new ConcurrentDictionary <int, ColorComponentError>();
            var indices         = new int[count];

            var delayedTasks = CreateDelayedTasks(colors, errorComponents, indices);

            ParallelProcessing.ProcessParallel(delayedTasks, _taskCount, delayedLineTask => delayedLineTask.Process(ProcessingAction));

            return(indices);
        }
        private void FillDistinctColors(Color[] colors)
        {
            _distinctColors = new ConcurrentDictionary <uint, DistinctColorInfo>();

            void ProcessingAction(LineTask <Color[], ConcurrentDictionary <uint, DistinctColorInfo> > taskModel)
            {
                for (int i = taskModel.Start; i < taskModel.Start + taskModel.Length; i++)
                {
                    var color = Color.FromArgb(0xFF, taskModel.Input[i].R, taskModel.Input[i].G, taskModel.Input[i].B);
                    taskModel.Output.AddOrUpdate((uint)color.ToArgb(), key => new DistinctColorInfo(color),
                                                 (key, info) => info.IncreaseCount());
                }
            }

            ParallelProcessing.ProcessList(colors, _distinctColors, ProcessingAction, TaskCount);
        }
Ejemplo n.º 7
0
        public async Task MultipleTaskTest()
        {
            var _proc = new ParallelProcessing <string, int>();
            var o     = new OutputWrite <string, int>();

            //run 100 Task parallel
            Reader[] range = Enumerable.Range(1, 100).Select(i => new Reader(_str)).ToArray();

            await _proc.MultipleTasks(range, o, CancellationToken.None);

            CollectionAssert.AllItemsAreUnique(o, "");
            Assert.IsTrue(o.Count > 0);
            Assert.AreEqual(o["a"], 600);
            Assert.AreEqual(o["as"], 400);
            Assert.AreEqual(o["to"], 700);
        }
Ejemplo n.º 8
0
        private IEnumerable <int> GetIndeces(IEnumerable <Color> colors)
        {
            var colorList = colors.ToArray();
            var indices   = new int[colorList.Length];

            void ProcessingAction(LineTask <Color[], int[]> taskModel)
            {
                for (int i = taskModel.Start; i < taskModel.Start + taskModel.Length; i++)
                {
                    taskModel.Output[i] = GetPaletteIndex(taskModel.Input[i]);
                }
            }

            ParallelProcessing.ProcessList(colorList, indices, ProcessingAction, TaskCount);

            return(indices);
        }
Ejemplo n.º 9
0
        private void MergeDocument(string Filename, object Data)
        {
            // create a new PassingObject that is used to send
            // data to the ProcessingApplication using pipes
            PassingObject dataObject = new PassingObject()
            {
                Data     = JsonConvert.SerializeObject(Data),
                Document = File.ReadAllBytes(Filename)
            };

            // call the processing app and pass the data object
            ReturningObject returnObject = ParallelProcessing.CallProcessingApp(dataObject);

            // create destination folder if it doesn't exists
            Directory.CreateDirectory(sResultsFolder);

            // write the returned byte array as a file
            File.WriteAllBytes(sResultsFolder + "\\" + Path.GetFileNameWithoutExtension(Filename) + ".pdf", returnObject.Document);
        }
        public void ParallelProcessingTest()
        {
            ParallelProcessing p = new ParallelProcessing("TD2");

            TestTools.RunLocalTest("A9", p.Process, p.TestDataName);
        }
Ejemplo n.º 11
0
 public void Start()
 {
     parallelProcessing = new ParallelProcessing();
 }