Beispiel #1
0
 internal OcTreeQuantizer(int colorDepth)
 {
     if (colorDepth > 8)
     {
         throw new ArgumentOutOfRangeException("colorDepth", colorDepth, "颜色深度不能大于8");
     }
     if (colorDepth <= 0)
     {
         throw new ArgumentOutOfRangeException("colorDepth", colorDepth, "颜色深度不能小于1");
     }
     maxColors = 1 << colorDepth;
     tree      = new OcTree(colorDepth);
 }
 /// <summary>
 /// 八叉树的构造函数
 /// </summary>
 /// <param name="colorDepth"></param>
 /// <param name="level">层级</param>
 /// <param name="tree"></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();
     }
 }
        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);
        }