protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
{
int pixelSize = ( image.PixelFormat == PixelFormat.Format24bppRgb ) ? 3 : 4;
int startX = rect.Left;
int startY = rect.Top;
int stopX = startX + rect.Width;
int stopY = startY + rect.Height;
int offset = image.Stride - rect.Width * pixelSize;
// do the job
byte* ptr = (byte*) image.ImageData.ToPointer( );
byte t;
// allign pointer to the first pixel to process
ptr += ( startY * image.Stride + startX * pixelSize );
// for each line
for ( int y = startY; y < stopY; y++ )
{
// for each pixel
for ( int x = startX; x < stopX; x++, ptr += pixelSize )
{
// rotate colors of each pixel
t = ptr[RGB.R];
ptr[RGB.R] = ptr[RGB.G];
ptr[RGB.G] = ptr[RGB.B];
ptr[RGB.B] = t;
}
ptr += offset;
}
}
}