Esempio n. 1
0
        private void LoadPixels(Pixel[] pixels)
        {
            if (ChunkList == null)
            {
                ChunkList = new List <ColorChunk>();
            }

            List <Pixel> pixelList = new List <Pixel>(pixels);

            Stopwatch stopwatch = new Stopwatch();

            Console.WriteLine("Loading pixels...");

            int count = 0;

            stopwatch.Start();

            pixelList = new List <Pixel>(pixelList.OrderBy(pixel => pixel.Color.AsInt()));

            int i;

            while (pixelList.Any())
            {
                for (i = 0; i < pixelList.Count - 1; i++)
                {
                    if (!pixelList[i].Color.Equals(pixelList[i + 1].Color))
                    {
                        break;
                    }
                }

                ChunkList.Add(new ColorChunk(pixelList.First().Color, i + 1));

                pixelList.RemoveRange(0, i + 1);

                count++;
            }

            stopwatch.Restart();

            // Sort by Count
            ChunkList = new List <ColorChunk>(ChunkList.OrderBy(chunk => chunk.Count));

            ColorList = ChunkList.Select(chunk => chunk.Color).ToList();

            stopwatch.Stop();

            Console.WriteLine("Pixels was loaded successfully!");
            Console.WriteLine("Elapsed: " + stopwatch.Elapsed.ToString());
            Console.WriteLine("CaluculateTime: " + count.ToString());
        }