protected override unsafe void ProcessFilter( UnmanagedImage image )
{
int pixelSize = Image.GetPixelFormatSize( image.PixelFormat ) / 8;
// get image width and height
int width = image.Width;
int height = image.Height;
int offset = image.Stride - width * pixelSize;
// do the job
byte * ptr = (byte*) image.ImageData.ToPointer( );
if ( image.PixelFormat == PixelFormat.Format8bppIndexed )
{
// grayscale image
for ( int y = 0; y < height; y++ )
{
for ( int x = 0; x < width; x++, ptr++ )
{
if ( !region.Contains( x, y ) )
{
*ptr = fillGray;
}
}
ptr += offset;
}
}
else
{
// color image
for ( int y = 0; y < height; y++ )
{
for ( int x = 0; x < width; x++, ptr += pixelSize )
{
if ( !region.Contains( x, y ) )
{
// red
ptr[RGB.R] = fillRed;
// green
ptr[RGB.G] = fillGreen;
// blue
ptr[RGB.B] = fillBlue;
}
}
ptr += offset;
}
}
}
}