FSO.Common.Utils.TextureUtils.ManualTextureMask C# (CSharp) Method

ManualTextureMask() public static method

Manually replaces a specified color in a texture with transparent black, thereby masking it.
public static ManualTextureMask ( Microsoft.Xna.Framework.Graphics.Texture2D &Texture, uint ColorsFrom ) : void
Texture Microsoft.Xna.Framework.Graphics.Texture2D The texture on which to apply the mask.
ColorsFrom uint
return void
        public static void ManualTextureMask(ref Texture2D Texture, uint[] ColorsFrom)
        {
            var ColorTo = Color.Transparent.PackedValue;

            //lock (TEXTURE_MASK_BUFFER)
            //{

                var size = Texture.Width * Texture.Height;
                uint[] buffer = GetBuffer(size);
                //uint[] buffer = new uint[size];

                //var buffer = TEXTURE_MASK_BUFFER;
                Texture.GetData(buffer, 0, size);

                var didChange = false;

                for (int i = 0; i < size; i++)
                {
                    if (ColorsFrom.Contains(buffer[i]))
                    {
                        didChange = true;
                        buffer[i] = ColorTo;
                    }
                }

                if (didChange)
                {
                    Texture.SetData(buffer, 0, size);
                }
        }