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;
// 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++ )
{
// for each pixel
for ( int x = startX; x < stopX; x++, ptr++ )
{
*ptr = (byte) ( ( *ptr <= matrix[( y % rows ), ( x % cols )] ) ? 0 : 255 );
}
ptr += offset;
}
}
}