示例#1
0
        public Color GetColor()
        {
            ColorRgb color = new ColorRgb(Color.Red / PixelCount,
                                          Color.Green / PixelCount, Color.Blue / PixelCount);

            return(color.GetColor());
        }
示例#2
0
        public void AddColor(ColorRgb color, int level, OctreeQuantizer parent)
        {
            if (level >= MaxDepth)
            {
                Color.Red   += color.Red;
                Color.Green += color.Green;
                Color.Blue  += color.Blue;
                PixelCount  += 1;
                return;
            }

            int index = GetColorIndexForLevel(color, level);

            if (_children[index] == null)
            {
                _children[index] = new OctreeNode(level, parent);
            }
            _children[index].AddColor(color, level + 1, parent);
        }
示例#3
0
        public int GetColorIndexForLevel(ColorRgb color, int level) // do rozkminy
        {
            var index = 0;
            var mask  = 0x80 >> level;

            if ((color.Red & mask) > 0)
            {
                index |= 4;
            }

            if ((color.Green & mask) > 0)
            {
                index |= 2;
            }

            if ((color.Blue & mask) > 0)
            {
                index |= 1;
            }

            return(index);
        }
示例#4
0
        public int GetPaletteIndex(ColorRgb color, int level)
        {
            if (this.IsLeaf())
            {
                return(this.PaletteIndex);
            }

            int index = GetColorIndexForLevel(color, level);

            if (_children[index] != null)
            {
                return(_children[index].GetPaletteIndex(color, level + 1));
            }
            else
            {
                foreach (var node in _children)
                {
                    node?.GetColorIndexForLevel(color, level + 1);
                }
            }


            return(0);
        }
示例#5
0
 public int GetPalletteIndex(ColorRgb color)
 {
     return(Root.GetPaletteIndex(color, 0));
 }
示例#6
0
 public void AddColor(ColorRgb color)
 {
     Root.AddColor(color, 0, this);
 }