AForge.Imaging.Filters.ImageWarp.ProcessFilter C# (CSharp) Метод

ProcessFilter() защищенный Метод

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage source, UnmanagedImage destination ) : void
source UnmanagedImage Source image data.
destination UnmanagedImage Destination image data.
Результат void
        protected override unsafe void ProcessFilter( UnmanagedImage source, UnmanagedImage destination )
        {
            int pixelSize = Image.GetPixelFormatSize( source.PixelFormat ) / 8;

            // image width and height
            int width  = source.Width;
            int height = source.Height;

            int widthToProcess  = Math.Min( width,  warpMap.GetLength( 1 ) );
            int heightToProcess = Math.Min( height, warpMap.GetLength( 0 ) );

            int srcStride = source.Stride;
            int dstStride = destination.Stride;
            int dstOffset = dstStride - widthToProcess * pixelSize;

            // new pixel's position
            int ox, oy;

            byte* src = (byte*) source.ImageData.ToPointer( );
            byte* dst = (byte*) destination.ImageData.ToPointer( );
            byte* p;

            // for each line
            for ( int y = 0; y < heightToProcess; y++ )
            {
                // for each pixel
                for ( int x = 0; x < widthToProcess; x++ )
                {
                    // get original pixel's coordinates
                    ox = x + warpMap[y, x].X;
                    oy = y + warpMap[y, x].Y;

                    // check if the random pixel is inside of image
                    if ( ( ox >= 0 ) && ( oy >= 0 ) && ( ox < width ) && ( oy < height ) )
                    {
                        p = src + oy * srcStride + ox * pixelSize;

                        for ( int i = 0; i < pixelSize; i++, dst++, p++ )
                        {
                            *dst = *p;
                        }
                    }
                    else
                    {
                        for ( int i = 0; i < pixelSize; i++, dst++ )
                        {
                            *dst = 0;
                        }
                    }
                }

                // copy remaining pixel in the row
                if ( width != widthToProcess )
                {
                    AForge.SystemTools.CopyUnmanagedMemory( dst, src + y * srcStride + widthToProcess * pixelSize, ( width - widthToProcess ) * pixelSize );
                }

                dst += dstOffset;
            }

            // copy remaining rows of pixels
            for ( int y = heightToProcess; y < height; y++, dst += dstStride )
            {
                AForge.SystemTools.CopyUnmanagedMemory( dst, src + y * srcStride, width * pixelSize );
            }
        }
    }