private void MarkAsVisited(Pixel pixel)
        {
            int index = pixel.Index;
            int row = index / _pixelWidth;
            int col = index % _pixelWidth;

            if (_isVisited[row] == null)
                _isVisited[row] = new bool[_pixelWidth];

            _isVisited[row][col] = true;

        }
        public void Process(byte[] pixelsData)
        {
            var queue = new Queue<Pixel>();
            var firstPixel = new Pixel(pixelsData, 0, _pixelWidth, _pixelHeight);
            queue.Enqueue(firstPixel);
            MarkAsVisited(firstPixel);


            while (queue.Count > 0)
            {
                Pixel pixel = queue.Dequeue();
                pixel.ChangeColor(150);

                Pixel[] adjacents = pixel.GetAdjacents();
                foreach (Pixel adj in adjacents)
                {
                    if (adj.IsWhite && !IsVisited(adj))
                    {
                        MarkAsVisited(adj);
                        queue.Enqueue(adj);
                    }
                }
            }
        }
Esempio n. 3
0
 private void AddPixel(int index, List<Pixel> adjacents)
 {
     var pixel = new Pixel(_pixels, index, _pixelsWidth, _pixelsHeight);
     adjacents.Add(pixel);
 }
 private bool IsVisited(Pixel pixel) => IsVisited(pixel.Row, pixel.Col);