protected override unsafe void ProcessFilter( UnmanagedImage image, UnmanagedImage overlay )
{
PixelFormat pixelFormat = image.PixelFormat;
// get image dimension
int width = image.Width;
int height = image.Height;
if (
( pixelFormat == PixelFormat.Format8bppIndexed ) ||
( pixelFormat == PixelFormat.Format24bppRgb ) ||
( pixelFormat == PixelFormat.Format32bppRgb ) ||
( pixelFormat == PixelFormat.Format32bppArgb ) )
{
// initialize other variables
int pixelSize = ( pixelFormat == PixelFormat.Format8bppIndexed ) ? 1 :
( pixelFormat == PixelFormat.Format24bppRgb ) ? 3 : 4;
int lineSize = width * pixelSize;
int srcOffset = image.Stride - lineSize;
int ovrOffset = overlay.Stride - lineSize;
// 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++ )
{
if ( *ovr < *ptr )
*ptr = *ovr;
}
ptr += srcOffset;
ovr += ovrOffset;
}
}
else
{
// initialize other variables
int pixelSize = ( pixelFormat == PixelFormat.Format16bppGrayScale ) ? 1 :
( pixelFormat == PixelFormat.Format48bppRgb ) ? 3 : 4;
int lineSize = width * pixelSize;
int srcStride = image.Stride;
int ovrStride = overlay.Stride;
// do the job
byte* basePtr = (byte*) image.ImageData.ToPointer( );
byte* baseOvr = (byte*) overlay.ImageData.ToPointer( );
// for each line
for ( int y = 0; y < height; y++ )
{
ushort * ptr = (ushort*) ( basePtr + y * srcStride );
ushort * ovr = (ushort*) ( baseOvr + y * ovrStride );
// for each pixel
for ( int x = 0; x < lineSize; x++, ptr++, ovr++ )
{
if ( *ovr < *ptr )
*ptr = *ovr;
}
}
}
}
}