Esempio n. 1
0
 internal OcTree(int colorDepth)
 {
     this._colorDepth = colorDepth;
     _maxColors       = 1 << _colorDepth;
     ReducibleNodes   = new OcTreeNode[colorDepth];
     _rootNode        = new OcTreeNode(colorDepth, 0, this);
 }
Esempio n. 2
0
        void Reduce()
        {
            int index;

            for (index = _colorDepth - 1; (index > 0 && ReducibleNodes[index] == null); index--)
            {
            }
            OcTreeNode node = ReducibleNodes[index];

            ReducibleNodes[index] = node.NextReducible;
            leaves     -= node.Reduce();
            _prefixNode = null;
        }
Esempio n. 3
0
 /// <summary>
 /// 八叉树的构造函数
 /// </summary>
 /// <param name="leaf">是否是叶子节点</param>
 /// <param name="level">层级</param>
 /// <param name="parent">父节点</param>
 internal OcTreeNode(int colorDepth, int level, OcTree tree)
 {
     this.ColorDepth = colorDepth;
     this.Leaf       = (colorDepth == level);
     this.Level      = level;
     if (!Leaf)
     {
         NextReducible = tree.ReducibleNodes[level];
         tree.ReducibleNodes[level] = this;
         Children = new OcTreeNode[8];
     }
     else
     {
         tree.IncrementLeaves();
     }
 }
Esempio n. 4
0
        internal int GetPaletteIndex(Color32 *pixel, int level)
        {
            int pindex = paletteIndex;

            if (!Leaf)
            {
                int shift = 7 - level;
                int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                            ((pixel->Green & mask[level]) >> (shift - 1)) |
                            ((pixel->Blue & mask[level]) >> (shift));
                OcTreeNode child = Children[index];
                if (child != null)
                {
                    child.GetPaletteIndex(pixel, level + 1);
                }
                else
                {
                    throw new Exception("不可预料的事情发生了!");
                }
            }
            return(pindex);
        }
Esempio n. 5
0
        internal void AddColor(Color32 *pixel, int level, OcTree tree)
        {
            //如果是树叶了,表示一个颜色像素添加完成
            if (this.Leaf)
            {
                Increment(pixel);
                tree.TracePrevious(this);
                return;
            }
            int shift = 7 - level;
            int index = ((pixel->Red & mask[level]) >> (shift - 2)) |
                        ((pixel->Green & mask[level]) >> (shift - 1)) |
                        ((pixel->Blue & mask[level]) >> (shift));
            OcTreeNode child = Children[index];

            if (child == null)
            {
                child           = new OcTreeNode(ColorDepth, level + 1, tree);
                Children[index] = child;
            }
            child.AddColor(pixel, ++level, tree);
        }
Esempio n. 6
0
 internal void TracePrevious(OcTreeNode node)
 {
     this._prefixNode = node;
 }