AForge.Imaging.Filters.ApplyMask.ProcessFilter C# (CSharp) Method

ProcessFilter() protected method

Process the filter on the specified image.
None of the possible mask properties were set. Need to provide mask before applying the filter. Invalid size of provided mask. Its size must be the same as the size of the image to mask.
protected ProcessFilter ( UnmanagedImage image, Rectangle rect ) : void
image UnmanagedImage Source image data.
rect System.Drawing.Rectangle Image rectangle for processing by the filter.
return void
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            if ( mask != null )
            {
                if ( ( image.Width  != mask.GetLength( 1 ) ) ||
                     ( image.Height != mask.GetLength( 0 ) ) )
                {
                    throw new ArgumentException( "Invalid size of mask array. Its size must be the same as the size of the image to mask." );
                }

                fixed ( byte* maskPtr = mask )
                {
                    ProcessImage( image, rect, maskPtr, mask.GetLength( 1 ) );
                }
            }
            else if ( unmanagedMaskImage != null )
            {
                if ( ( image.Width  != unmanagedMaskImage.Width ) ||
                     ( image.Height != unmanagedMaskImage.Height ) )
                {
                    throw new ArgumentException( "Invalid size of unmanaged mask image. Its size must be the same as the size of the image to mask." );
                }

                ProcessImage( image, rect, (byte*) unmanagedMaskImage.ImageData.ToPointer( ),
                              unmanagedMaskImage.Stride );
            }
            else if ( maskImage != null )
            {
                if ( ( image.Width  != maskImage.Width ) ||
                     ( image.Height != maskImage.Height ) )
                {
                    throw new ArgumentException( "Invalid size of mask image. Its size must be the same as the size of the image to mask." );
                }

                BitmapData maskData = maskImage.LockBits( new Rectangle( 0, 0, image.Width, image.Height ),
                    ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed );

                try
                {
                    ProcessImage( image, rect, (byte*) maskData.Scan0.ToPointer( ),
                                  maskData.Stride );
                }
                finally
                {
                    maskImage.UnlockBits( maskData );
                }
            }
            else
            {
                throw new NullReferenceException( "None of the possible mask properties were set. Need to provide mask before applying the filter." );
            }
        }