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 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 quantizer /// </summary> /// <remarks> /// The Octree quantizer is a two pass algorithm. The initial pass sets /// up the octree, the second pass quantizes a colour based on the nodes /// in the tree. /// </remarks> /// <param name="maxColours">The maximum number of colours to return</param> /// <param name="maxColourBits">The number of significant bits</param> public OctreeQuantizer( int maxColours, int maxColourBits ) : base( false ) { #region guard against arguments out of range if( maxColours > 255 || maxColours < 1 ) { string message = "The number of colours should be between 1 and 255"; throw new ArgumentOutOfRangeException( "maxColours", maxColours, message ); } if( ( maxColourBits < 1 ) | ( maxColourBits > 8 ) ) { string message = "This should be between 1 and 8"; throw new ArgumentOutOfRangeException( "maxColourBits", maxColourBits, message ); } #endregion // Construct the octree _octree = new Octree( maxColourBits ); _maxColors = maxColours; }