AForge.Imaging.Filters.PointedColorFloodFill.LinearFloodFill4Gray C# (CSharp) Метод

LinearFloodFill4Gray() приватный Метод

private LinearFloodFill4Gray ( IntPoint startingPoint ) : void
startingPoint IntPoint
Результат void
        private unsafe void LinearFloodFill4Gray( IntPoint startingPoint )
        {
            Queue<IntPoint> points = new Queue<IntPoint>( );
            points.Enqueue( startingPoint );

            while ( points.Count > 0 )
            {
                IntPoint point = points.Dequeue( );

                int x = point.X;
                int y = point.Y;

                // get image pointer for current (X, Y)
                byte* p = (byte*) CoordsToPointerGray( x, y );

                // find left end of line to fill
                int leftLineEdge = x;
                byte* ptr = p;

                while ( true )
                {
                    // fill current pixel
                    *ptr = fillG;
                    // mark the pixel as checked
                    checkedPixels[y, leftLineEdge] = true;

                    leftLineEdge--;
                    ptr -= 1;

                    // check if we need to stop on the edge of image or color area
                    if ( ( leftLineEdge < startX ) || ( checkedPixels[y, leftLineEdge] ) || ( !CheckGrayPixel( *ptr ) ) )
                        break;

                }
                leftLineEdge++;

                // find right end of line to fill
                int rightLineEdge = x;
                ptr = p;

                while ( true )
                {
                    // fill current pixel
                    *ptr = fillG;
                    // mark the pixel as checked
                    checkedPixels[y, rightLineEdge] = true;

                    rightLineEdge++;
                    ptr += 1;

                    // check if we need to stop on the edge of image or color area
                    if ( rightLineEdge > stopX || ( checkedPixels[y, rightLineEdge] ) || ( !CheckGrayPixel( *ptr ) ) )
                        break;
                }
                rightLineEdge--;

                // loop to go up and down
                ptr = (byte*) CoordsToPointerGray( leftLineEdge, y );

                bool upperPointIsQueued = false;
                bool lowerPointIsQueued = false;
                int upperY = y - 1;
                int lowerY = y + 1;

                for ( int i = leftLineEdge; i <= rightLineEdge; i++, ptr++ )
                {
                    // go up
                    if ( ( y > startY ) && ( !checkedPixels[y - 1, i] ) && ( CheckGrayPixel( *( ptr - stride ) ) ) )
                    {
                        if ( !upperPointIsQueued )
                        {
                            points.Enqueue( new IntPoint( i, upperY ) );
                            upperPointIsQueued = true;
                        }
                    }
                    else
                    {
                        upperPointIsQueued = false;
                    }

                    // go down
                    if ( ( y < stopY ) && ( !checkedPixels[y + 1, i] ) && ( CheckGrayPixel( *( ptr + stride ) ) ) )
                    {
                        if ( !lowerPointIsQueued )
                        {
                            points.Enqueue( new IntPoint( i, lowerY ) );
                            lowerPointIsQueued = true;
                        }
                    }
                    else
                    {
                        lowerPointIsQueued = false;
                    }
                }
            }
        }