AForge.Imaging.Filters.CanvasMove.ProcessFilter8bpc C# (CSharp) Method

ProcessFilter8bpc() private method

private ProcessFilter8bpc ( UnmanagedImage image ) : void
image UnmanagedImage
return void
        private unsafe void ProcessFilter8bpc( UnmanagedImage image )
        {
            int pixelSize = Image.GetPixelFormatSize( image.PixelFormat ) / 8;
            bool is32bpp = ( pixelSize == 4 );

            // get image width and height
            int width  = image.Width;
            int height = image.Height;
            int stride = image.Stride;

            int movePointX = movePoint.X;
            int movePointY = movePoint.Y;

            // intersection rectangle
            Rectangle intersect = Rectangle.Intersect(
                new Rectangle( 0, 0, width, height ),
                new Rectangle( movePointX, movePointY, width, height ) );

            // start, stop and step for X adn Y
            int yStart  = 0;
            int yStop   = height;
            int yStep   = 1;
            int xStart  = 0;
            int xStop   = width;
            int xStep   = 1;

            if ( movePointY > 0 )
            {
                yStart = height - 1;
                yStop  = -1;
                yStep  = -1;
            }
            if ( movePointX > 0 )
            {
                xStart = width - 1;
                xStop  = -1;
                xStep  = -1;
            }

            // do the job
            byte* src = (byte*) image.ImageData.ToPointer( );
            byte* pixel, moved;

            if ( image.PixelFormat == PixelFormat.Format8bppIndexed )
            {
                // grayscale image
                for ( int y = yStart; y != yStop; y += yStep )
                {
                    for ( int x = xStart; x != xStop; x += xStep )
                    {
                        // current pixel
                        pixel = src + y * stride + x;

                        if ( intersect.Contains( x, y ) )
                        {
                            moved = src + ( y - movePointY ) * stride + ( x - movePointX );

                            *pixel = *moved;
                        }
                        else
                        {
                            *pixel = fillGray;
                        }
                    }
                }
            }
            else
            {
                // color image
                for ( int y = yStart; y != yStop; y += yStep )
                {
                    for ( int x = xStart; x != xStop; x += xStep )
                    {
                        // current pixel
                        pixel = src + y * stride + x * pixelSize;

                        if ( intersect.Contains( x, y ) )
                        {
                            moved = src + ( y - movePointY ) * stride + ( x - movePointX ) * pixelSize;

                            pixel[RGB.R] = moved[RGB.R];
                            pixel[RGB.G] = moved[RGB.G];
                            pixel[RGB.B] = moved[RGB.B];

                            if ( is32bpp )
                            {
                                pixel[RGB.A] = moved[RGB.A];
                            }
                        }
                        else
                        {
                            pixel[RGB.R] = fillRed;
                            pixel[RGB.G] = fillGreen;
                            pixel[RGB.B] = fillBlue;

                            if ( is32bpp )
                            {
                                pixel[RGB.A] = fillAlpha;
                            }
                        }
                    }
                }
            }
        }