protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
{
int startX = rect.Left;
int stopX = startX + rect.Width;
int height = rect.Height;
int stride = image.Stride;
byte* basePtr = (byte*) image.ImageData.ToPointer( ) + rect.Top * stride + startX;
for ( int x = startX; x < stopX; x++ )
{
byte* ptr = basePtr;
byte* columnStartPtr = ptr;
byte* columnEndPtr = ptr + stride * height;
// fill gaps between white pixels
while ( ptr < columnEndPtr )
{
byte* gapStart = ptr;
int gapSize = 0;
// look for non black pixel
while ( ( ptr < columnEndPtr ) && ( *ptr == 0 ) )
{
ptr += stride;
gapSize++;
}
// fill the gap between white areas
if ( gapSize <= maxGapSize )
{
if ( ( processGapsWithImageBorders ) ||
( ( gapStart != columnStartPtr ) && ( ptr != columnEndPtr ) ) )
{
while ( gapStart < ptr )
{
*gapStart = 255;
gapStart += stride;
}
}
}
// skip all non black pixels
while ( ( ptr < columnEndPtr ) && ( *ptr != 0 ) )
{
ptr += stride;
}
}
basePtr++;
}
}
}