/// <summary> /// See <see cref="BaseColorQuantizer.OnFinish"/> for more details. /// </summary> protected override void OnFinish() { base.OnFinish(); // initializes the octree level lists levels = new List<OctreeNode>[7]; // creates the octree level lists for (Int32 level = 0; level < 7; level++) { levels[level] = new List<OctreeNode>(); } // creates a root node root = new OctreeNode(0, this); }
/// <summary> /// Adds the color. /// </summary> /// <param name="color">The color.</param> /// <param name="level">The level.</param> /// <param name="parent">The parent.</param> public void AddColor(Color color, Int32 level, OctreeQuantizer parent) { // if this node is a leaf, then increase a color amount, and pixel presence if (level == 8) { red += color.R; green += color.G; blue += color.B; pixelCount++; } else if (level < 8) // otherwise goes one level deeper { // calculates an index for the next sub-branch Int32 index = GetColorIndexAtLevel(color, level); // if that branch doesn't exist, grows it if (nodes[index] == null) { nodes[index] = new OctreeNode(level, parent); } // adds a color to that branch nodes[index].AddColor(color, level + 1, parent); } }
/// <summary> /// Adds the node to a level node list. /// </summary> /// <param name="level">The depth level.</param> /// <param name="octreeNode">The octree node to be added.</param> internal void AddLevelNode(Int32 level, OctreeNode octreeNode) { levels[level].Add(octreeNode); }