Clandestine.Texture.ChromaKey32bppBitmap C# (CSharp) Method

ChromaKey32bppBitmap() private static method

private static ChromaKey32bppBitmap ( Bitmap bmp, Color chroma ) : void
bmp System.Drawing.Bitmap
chroma Color
return void
        private static void ChromaKey32bppBitmap(Bitmap bmp, Color chroma)
        {
            BitmapData bd = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size),
                        ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                int len = bd.Stride * bd.Height;

                byte* ptr = (byte*)bd.Scan0.ToPointer();

                byte* ptrStop = ptr + len;

                while (ptr < ptrStop)
                {
                    if (*ptr == chroma.B && *(ptr + 1) == chroma.G
                        && *(ptr + 2) == chroma.R)
                        *(ptr + 3) = 0; // ...then set the alpha to 0

                    ptr += 4;
                }
            }

            bmp.UnlockBits(bd);
        }