protected override unsafe void ProcessFilter(UnmanagedImage image, Rectangle rect)
{
if (mask != null)
{
if ((image.Width != mask.GetLength(1)) ||
(image.Height != mask.GetLength(0)))
{
throw new ArgumentException("Invalid size of mask array. Its size must be the same as the size of the image to mask.");
}
fixed (byte* maskPtr = mask)
{
ProcessImage(image, rect, maskPtr, mask.GetLength(1));
}
}
else if (unmanagedMaskImage != null)
{
if ((image.Width != unmanagedMaskImage.Width) ||
(image.Height != unmanagedMaskImage.Height))
{
throw new ArgumentException("Invalid size of unmanaged mask image. Its size must be the same as the size of the image to mask.");
}
ProcessImage(image, rect, (byte*)unmanagedMaskImage.ImageData.ToPointer(),
unmanagedMaskImage.Stride);
}
else if (maskImage != null)
{
if ((image.Width != maskImage.Width) ||
(image.Height != maskImage.Height))
{
throw new ArgumentException("Invalid size of mask image. Its size must be the same as the size of the image to mask.");
}
BitmapData maskData = maskImage.LockBits(new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
try
{
ProcessImage(image, rect, (byte*)maskData.Scan0.ToPointer(),
maskData.Stride);
}
finally
{
maskImage.UnlockBits(maskData);
}
}
else
{
throw new InvalidOperationException("None of the possible mask properties were set. Need to provide mask before applying the filter.");
}
}