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

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

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage image, Rectangle rect ) : void
image UnmanagedImage Source image data.
rect System.Drawing.Rectangle Image rectangle for processing by the filter.
Результат void
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            int startX  = rect.Left;
            int startY  = rect.Top;
            int stopX   = startX + rect.Width;
            int stopY   = startY + rect.Height;
            int offset  = image.Stride - rect.Width;

            // value which is caried from pixel to pixel
            short carry = 0;

            // do the job
            byte* ptr = (byte*) image.ImageData.ToPointer( );

            // allign pointer to the first pixel to process
            ptr += ( startY * image.Stride + startX );

            // for each line	
            for ( int y = startY; y < stopY; y++ )
            {
                carry = 0;

                // for each pixel
                for ( int x = startX; x < stopX; x++, ptr++ )
                {
                    carry += *ptr;

                    if ( carry >= threshold )
                    {
                        *ptr = (byte) 255;
                        carry -= 255;
                    }
                    else
                    {
                        *ptr = (byte) 0;
                    }
                }
                ptr += offset;
            }
        }
    }