protected unsafe override void ProcessFilter(UnmanagedImage image)
{
int width = image.Width;
int height = image.Height;
int pixelSize = System.Drawing.Image.GetPixelFormatSize(image.PixelFormat) / 8;
int stride = image.Stride;
int offset = stride - image.Width * pixelSize;
byte* src = (byte*)image.ImageData.ToPointer();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, src += pixelSize)
{
double sum = src[RGB.R] + src[RGB.G] + src[RGB.B];
sum = sum == 0 ? 1 : sum;
double red = src[RGB.R] / sum;
double green = src[RGB.G] / sum;
double blue = 1 - red - green;
src[RGB.R] = (byte)(red * 255);
src[RGB.G] = (byte)(green * 255);
src[RGB.B] = (byte)(blue * 255);
}
src += offset;
}
}
}