protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
{
int pixelSize = ( image.PixelFormat == PixelFormat.Format8bppIndexed ) ? 1 : 3;
int startY = rect.Top;
int stopY = startY + rect.Height;
int startX = rect.Left * pixelSize;
int stopX = startX + rect.Width * pixelSize;
int offset = image.Stride - ( stopX - startX );
// do the job
byte* ptr = (byte*) image.ImageData.ToPointer( );
// allign pointer to the first pixel to process
ptr += ( startY * image.Stride + rect.Left * pixelSize );
// for each line
for ( int y = startY; y < stopY; y++ )
{
// for each pixel
for ( int x = startX; x < stopX; x++, ptr++ )
{
*ptr = (byte) Math.Max( 0, Math.Min( 255, *ptr + generator.Next( ) ) );
}
ptr += offset;
}
}
}