コード例 #1
0
ファイル: Octree.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Add a given color value to the octree
		/// </summary>
		/// <param name="pixel">The colour to add</param>
		public void AddColour( Colour32* pixel )
		{
			// Check if this request is for the same color as the last
			if( _previousColor == pixel->ARGB )
			{
				// If so, check if I have a previous node setup. This will 
				// only ocurr if the first color in the image happens to be 
				// black, with an alpha component of zero.
				if( null == _previousNode )
				{
					// TESTME: AddColour - previous node is null
					_previousColor = pixel->ARGB;
					_root.AddColour( pixel, _maxColorBits, 0, this );
				}
				else
				{
					// Just update the previous node
					_previousNode.Increment( pixel );
				}
			}
			else
			{
				_previousColor = pixel->ARGB ;
				_root.AddColour( pixel, _maxColorBits, 0, this ) ;
			}
		}
コード例 #2
0
ファイル: Octree.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Get the palette index for the passed color
		/// </summary>
		/// <param name="pixel"></param>
		/// <returns></returns>
		public int GetPaletteIndex( Colour32* pixel )
		{
			return _root.GetPaletteIndex( pixel, 0 );
		}
コード例 #3
0
ファイル: OctreeNode.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Return the palette index for the passed color
		/// </summary>
		public int GetPaletteIndex( Colour32* pixel, int level )
		{
			int	paletteIndex = _paletteIndex;

			if( !_leaf )
			{
				// FXCOP: Correct the potential overflow in the operation '7-level' in 'OctreeNode.GetPaletteIndex(Colour32*, Int32):Int32'. (CA2233)
				int	shift = 7 - level;
				int index = ( ( pixel->Red & mask[level] ) >> ( shift - 2 ) ) |
							( ( pixel->Green & mask[level] ) >> ( shift - 1 ) ) |
							( ( pixel->Blue & mask[level] ) >> ( shift ) );

				if( null != _children[index] )
				{
					// FXCOP: Correct the potential overflow in the operation 'level+1' in 'OctreeNode.GetPaletteIndex(Colour32*, Int32):Int32'. (CA2233)
					paletteIndex 
						= _children[index].GetPaletteIndex( pixel, 
						                                    level + 1 );
				}
				else
				{
					// TESTME: GetPaletteIndex - _children[index] == null
					throw new InvalidOperationException( "Didn't expect this!" );
				}
			}

			return paletteIndex;
		}
コード例 #4
0
ファイル: OctreeNode.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Increment the pixel count and add to the color information
		/// </summary>
		public void Increment( Colour32* pixel )
		{
			_pixelCount++;
			_red += pixel->Red;
			_green += pixel->Green;
			_blue += pixel->Blue;
		}
コード例 #5
0
ファイル: OctreeNode.cs プロジェクト: hanistory/hasuite
		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 );
			}

		}
コード例 #6
0
ファイル: OctreeQuantizer.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Override this to process the pixel in the second pass of the 
		/// algorithm
		/// </summary>
		/// <param name="pixel">The pixel to quantize</param>
		/// <returns>The quantized value</returns>
		internal override byte QuantizePixel( Colour32* pixel )
		{
			// The color at [_maxColors] is set to transparent
			byte paletteIndex = (byte) _maxColors;

			// Get the palette index if this non-transparent
			if( pixel->Alpha > 0 )
			{
				paletteIndex = (byte) _octree.GetPaletteIndex( pixel );
			}

			return paletteIndex;
		}
コード例 #7
0
ファイル: OctreeQuantizer.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Process the pixel in the first pass of the algorithm
		/// </summary>
		/// <param name="pixel">The pixel to quantize</param>
		/// <remarks>
		/// This function need only be overridden if your quantize algorithm 
		/// needs two passes, such as an Octree quantizer.
		/// </remarks>
		internal override void InitialQuantizePixel( Colour32* pixel )
		{
			// Add the color to the octree
			_octree.AddColour( pixel );
		}
コード例 #8
0
ファイル: Quantizer.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Override this to process the pixel in the second pass of the algorithm
		/// </summary>
		/// <param name="pixel">The pixel to quantize</param>
		/// <returns>The quantized value</returns>
		internal abstract byte QuantizePixel( Colour32* pixel );
コード例 #9
0
ファイル: Quantizer.cs プロジェクト: hanistory/hasuite
		/// <summary>
		/// Override this to process the pixel in the first pass of the algorithm
		/// </summary>
		/// <param name="pixel">The pixel to quantize</param>
		/// <remarks>
		/// This function need only be overridden if your quantize algorithm 
		/// needs two passes, such as an Octree quantizer.
		/// </remarks>
		internal virtual void InitialQuantizePixel( Colour32* pixel )
		{
		}