protected override unsafe void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
{
PixelFormat pixelFormat = sourceData.PixelFormat;
// get image dimension
int width = sourceData.Width;
int height = sourceData.Height;
// check overlay type
if (overlayImage != null)
{
// source image and overlay must have same pixel format
if (pixelFormat != overlayImage.PixelFormat)
throw new InvalidImagePropertiesException("Source and overlay images must have same pixel format.");
// check overlay image size
if ((width != overlayImage.Width) || (height != overlayImage.Height))
throw new InvalidImagePropertiesException("Overlay image size must be equal to source image size.");
// lock overlay image
BitmapData ovrData = overlayImage.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadOnly, pixelFormat);
try
{
ProcessFilter(sourceData, new UnmanagedImage(ovrData), destinationData);
}
finally
{
// unlock overlay image
overlayImage.UnlockBits(ovrData);
}
}
else if (unmanagedOverlayImage != null)
{
// source image and overlay must have same pixel format
if (pixelFormat != unmanagedOverlayImage.PixelFormat)
throw new InvalidImagePropertiesException("Source and overlay images must have same pixel format.");
// check overlay image size
if ((width != unmanagedOverlayImage.Width) || (height != unmanagedOverlayImage.Height))
throw new InvalidImagePropertiesException("Overlay image size must be equal to source image size.");
ProcessFilter(sourceData, unmanagedOverlayImage, destinationData);
}
else
{
throw new InvalidOperationException("Overlay image is not set.");
}
}