/// <summary> /// Keep track of the previous node that was quantized /// </summary> /// <param name="node">The node last quantized</param> public void TrackPrevious( OctreeNode node ) { _previousNode = node; }
/// <summary> /// Construct the octree /// </summary> /// <param name="maxColourBits"> /// The maximum number of significant bits in the image /// </param> public Octree( int maxColourBits ) { _maxColorBits = maxColourBits; _reducibleNodes = new OctreeNode[9]; _root = new OctreeNode( 0, _maxColorBits, this ); }
/// <summary> /// Reduce the depth of the tree /// </summary> private void Reduce() { int index; // Find the deepest level containing at least one reducible node for( index = _maxColorBits - 1; ( index > 0 ) && ( null == _reducibleNodes[index] ); index-- ); // Reduce the node most recently added to the list at level 'index' OctreeNode node = _reducibleNodes[index]; _reducibleNodes[index] = node.NextReducible; // Decrement the leaf count after reducing the node _leafCount -= node.Reduce(); // And just in case I've reduced the last color to be added, // and the next color to be added is the same, invalidate the // previousNode... _previousNode = null; }
public void AddColour( Colour32* pixel, int colourBits, 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 // FXCOP: Correct the potential overflow in the operation '7-level' in 'OctreeNode.AddColour(Colour32*, Int32, Int32, Octree):Void'. (CA2233) 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 // FXCOP: Correct the potential overflow in the operation 'level+1' in 'OctreeNode.AddColour(Colour32*, Int32, Int32, Octree):Void'. (CA2233) child = new OctreeNode( level + 1, colourBits, octree ); _children[index] = child; } // Add the color to the child node // FXCOP: Correct the potential overflow in the operation 'level+1' in 'OctreeNode.AddColour(Colour32*, Int32, Int32, Octree):Void'. (CA2233) child.AddColour( pixel, colourBits, level + 1, octree ); } }
public OctreeNode( int level, int colourBits, Octree octree ) { if( octree == null ) { // TESTME: constructor null argument throw new ArgumentNullException( "octree" ); } // Construct the new node _leaf = ( level == colourBits ); _red = _green = _blue = 0; // If a leaf, increment the leaf count if( _leaf ) { octree.Leaves++; } else { // Otherwise add this to the reducible nodes _nextReducible = octree.ReducibleNodes[level]; octree.ReducibleNodes[level] = this; _children = new OctreeNode[8]; } }
/// <summary> /// Construct the octree /// </summary> /// <param name="maxColourBits"> /// The maximum number of significant bits in the image /// </param> public Octree(int maxColourBits) { _maxColorBits = maxColourBits; _reducibleNodes = new OctreeNode[9]; _root = new OctreeNode(0, _maxColorBits, this); }
/// <summary> /// Keep track of the previous node that was quantized /// </summary> /// <param name="node">The node last quantized</param> public void TrackPrevious(OctreeNode node) { _previousNode = node; }