protected override unsafe void ProcessFilter(UnmanagedImage image, Rectangle rect)
{
// processing start and stop X,Y positions
startX = rect.Left;
startY = rect.Top;
stopX = startX + rect.Width;
stopY = startY + rect.Height;
stride = image.Stride;
int offset = stride - rect.Width;
// pixel value and error value
int v, error;
// do the job
byte* ptr = (byte*)image.ImageData.ToPointer();
// allign pointer to the first pixel to process
ptr += (startY * stride + startX);
// for each line
for (y = startY; y < stopY; y++)
{
// for each pixels
for (x = startX; x < stopX; x++, ptr++)
{
v = *ptr;
// fill the next destination pixel
if (v >= threshold)
{
*ptr = 255;
error = v - 255;
}
else
{
*ptr = 0;
error = v;
}
// do error diffusion
Diffuse(error, ptr);
}
ptr += offset;
}
}
}