PurplePen.OctreeQuantizer.Octree.OctreeNode.AddColor C# (CSharp) Method

AddColor() public method

Add a color into the tree
public AddColor ( Color32 pixel, int colorBits, int level, Octree octree ) : void
pixel Color32 The color
colorBits int The number of significant color bits
level int The level in the tree
octree Octree The tree to which this node belongs
return void
                public void AddColor(Color32* pixel, int colorBits, int level, Octree octree)
                {
                    // Update the color information if this is a leaf
                    if (_leaf) {
                        Increment(pixel);
                        // Setup the previous node
                        octree.TrackPrevious(this);
                    }
                    else {
                        // Go to the next level down in the tree
                        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 (null == child) {
                            // Create a new child node & store in the array
                            child = new OctreeNode(level + 1, colorBits, octree);
                            _children[index] = child;
                        }

                        // Add the color to the child node
                        child.AddColor(pixel, colorBits, level + 1, octree);
                    }
                }