Exemplo n.º 1
0
            /// <summary>
            /// Get the palette index for the passed color
            /// </summary>
            public int GetPaletteIndex(int pixel)
            {
                var ret = _root.GetPaletteIndex(pixel, 0);

                if (ret < 0)
                {
                    if (_paletteTable == null)
                    {
                        _paletteTable = new PaletteTable(_palette);
                    }

                    ret = _paletteTable.FindClosestPaletteIndex(Color.FromArgb(pixel));
                }

                return(ret);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Convert the nodes in the octree to a palette with a maximum of colorCount colors
            /// </summary>
            /// <param name="colorCount">The maximum number of colors</param>
            /// <returns>A list with the palettized colors</returns>
            public List <Color> Palletize(int colorCount)
            {
                while (_leafCount > colorCount)
                {
                    Reduce();
                }

                // Now palletize the nodes
                var palette      = new List <Color>(_leafCount);
                int paletteIndex = 0;

                _root.ConstructPalette(palette, ref paletteIndex);

                // And return the palette
                _palette      = palette.ToArray();
                _paletteTable = null;

                return(palette);
            }