protected override unsafe void ProcessFilter( UnmanagedImage image, UnmanagedImage overlay )
{
// get image dimension
int width = image.Width;
int height = image.Height;
// initialize other variables
int pixelSize = ( image.PixelFormat == PixelFormat.Format8bppIndexed ) ? 1 : 3;
int lineSize = width * pixelSize;
int offset = image.Stride - lineSize;
int ovrOffset = overlay.Stride - lineSize;
// percentage of overlay image
double q = 1.0 - sourcePercent;
// do the job
byte * ptr = (byte*) image.ImageData.ToPointer( );
byte * ovr = (byte*) overlay.ImageData.ToPointer( );
// for each line
for ( int y = 0; y < height; y++ )
{
// for each pixel
for ( int x = 0; x < lineSize; x++, ptr++, ovr++ )
{
*ptr = (byte) ( ( sourcePercent * ( *ptr ) ) + ( q * ( *ovr ) ) );
}
ptr += offset;
ovr += ovrOffset;
}
}
}