protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
{
int startY = rect.Top;
int stopY = startY + rect.Height;
int width = rect.Width;
int offset = image.Stride - rect.Width;
byte* ptr = (byte*) image.ImageData.ToPointer( ) + startY * image.Stride + rect.Left;
for ( int y = startY; y < stopY; y++ )
{
byte* lineStart = ptr;
byte* lineEndPtr = ptr + width;
// fill gaps between white pixels
while ( ptr < lineEndPtr )
{
byte* gapStart = ptr;
// look for non black pixel
while ( ( ptr < lineEndPtr ) && ( *ptr == 0 ) )
{
ptr++;
}
// fill the gap between white areas
if ( ptr - gapStart <= maxGapSize )
{
if ( ( processGapsWithImageBorders ) ||
( ( gapStart != lineStart ) && ( ptr != lineEndPtr ) ) )
{
while ( gapStart < ptr )
{
*gapStart = 255;
gapStart++;
}
}
}
// skip all non black pixels
while ( ( ptr < lineEndPtr ) && ( *ptr != 0 ) )
{
ptr++;
}
}
ptr += offset;
}
}
}