Esempio n. 1
0
 public 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);
 }
Esempio n. 2
0
 /// <summary>
 /// 八叉树的构造函数
 /// </summary>
 /// <param name="leaf">是否是叶子节点</param>
 /// <param name="level">层级</param>
 /// <param name="parent">父节点</param>
 public 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. 3
0
        public 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);
        }