/// <summary> /// Add a given color value to the Octree /// </summary> /// <param name="pixel"> /// The <see cref="TColor"/>containing color information to add. /// </param> public void AddColor(TColor pixel) { TPacked packed = pixel.PackedValue; // Check if this request is for the same color as the last if (this.previousColor.Equals(packed)) { // If so, check if I have a previous node setup. This will only occur if the first color in the image // happens to be black, with an alpha component of zero. if (this.previousNode == null) { this.previousColor = packed; this.root.AddColor(pixel, this.maxColorBits, 0, this); } else { // Just update the previous node this.previousNode.Increment(pixel); } } else { this.previousColor = packed; this.root.AddColor(pixel, this.maxColorBits, 0, this); } }
/// <summary> /// Initializes a new instance of the <see cref="Octree"/> class. /// </summary> /// <param name="maxColorBits"> /// The maximum number of significant bits in the image /// </param> public Octree(int maxColorBits) { this.maxColorBits = maxColorBits; this.Leaves = 0; this.reducibleNodes = new OctreeNode[9]; this.root = new OctreeNode(0, this.maxColorBits, this); this.previousColor = default(TPacked); this.previousNode = null; }