Ejemplo n.º 1
0
        /// <summary>
        /// Gets the indices of the colours of each of the supplied pixels
        /// within the colour table.
        /// </summary>
        /// <param name="pixelColours">
        /// A collection of the colours for which to get the indices in the
        /// colour table.
        /// </param>
        /// <returns>
        /// A collection of the indices of the colours of each of the supplied
        /// pixels within the colour table.
        /// </returns>
        private IndexedPixels GetIndexedPixels(Color[] pixelColours)
        {
            IndexedPixels indexedPixels = new IndexedPixels();
            // Take a copy of the distinct colours to make the IndexOf method
            // available
            string copyDistinctColoursCounterText = "Copying distinct colours";

            AddCounter(copyDistinctColoursCounterText, _distinctColours.Count);
            Collection <Color> distinctColours = new Collection <Color>();

            foreach (Color c in _distinctColours.Keys)
            {
                MyProgressCounters[copyDistinctColoursCounterText].Value++;
                distinctColours.Add(c);
            }
            RemoveCounter(copyDistinctColoursCounterText);

            int    indexInColourTable;
            int    red;
            int    green;
            int    blue;
            int    numberOfPixels = pixelColours.Length;
            string indexingPixelsCounterText
                = "Mapping colours to indices in colour table";

            AddCounter(indexingPixelsCounterText, numberOfPixels);

            for (int i = 0; i < numberOfPixels; i++)
            {
                MyProgressCounters[indexingPixelsCounterText].Value = i;
                red   = pixelColours[i].R;
                green = pixelColours[i].G;
                blue  = pixelColours[i].B;

                // Get the index in the colour table of the colour of this pixel
                if (_distinctColours.Count > 256)
                {
                    indexInColourTable = _nq.Map(red, green, blue);
                }
                else
                {
                    indexInColourTable = distinctColours.IndexOf(pixelColours[i]);
                }
                indexedPixels.Add((byte)indexInColourTable);
            }
            RemoveCounter(indexingPixelsCounterText);
            return(indexedPixels);
        }