예제 #1
0
        public unsafe void ApplyColorKey(TexImage image, ColorKeyRequest request)
        {
            Log.Info("Apply color key [{0}]", request.ColorKey);

            var colorKey = request.ColorKey;
            var rowPtr = image.Data;
            if (image.Format == PixelFormat.R8G8B8A8_UNorm)
            {
                for (int i = 0; i < image.Height; i++)
                {
                    var colors = (Core.Mathematics.Color*)rowPtr;
                    for (int x = 0; x < image.Width; x++)
                    {
                        if (colors[x] == colorKey)
                        {
                            colors[x] = Core.Mathematics.Color.Transparent;
                        }
                    }
                    rowPtr = IntPtr.Add(rowPtr, image.RowPitch);
                }
            }
            else if (image.Format == PixelFormat.B8G8R8A8_UNorm)
            {
                var rgbaColorKey = colorKey.ToRgba();
                for (int i = 0; i < image.Height; i++)
                {
                    var colors = (Core.Mathematics.ColorBGRA*)rowPtr;
                    for (int x = 0; x < image.Width; x++)
                    {
                        if (colors[x].ToRgba() == rgbaColorKey)
                        {
                            colors[x] = Core.Mathematics.Color.Transparent;
                        }
                    }
                    rowPtr = IntPtr.Add(rowPtr, image.RowPitch);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Apply a color key on the image by replacing the color passed by to this method by a white transparent color (Alpha is 0).
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="colorKey">The color key.</param>
        public void ColorKey(TexImage image, Color colorKey)
        {
            if (image.Format.IsCompressed())
            {
                Log.Warning("You can't compress an already compressed texture. It will be decompressed first..");
                Decompress(image, image.Format.IsSRgb());
            }

            if (image.Format != PixelFormat.R8G8B8A8_UNorm && image.Format != PixelFormat.B8G8R8A8_UNorm 
                && image.Format != PixelFormat.B8G8R8A8_UNorm_SRgb && image.Format != PixelFormat.R8G8B8A8_UNorm_SRgb)
            {
                Log.Error("ColorKey TextureConverter is only supporting R8G8B8A8_UNorm or B8G8R8A8_UNorm while Texture Format is [{0}]", image.Format);
                return;
            }

            var request = new ColorKeyRequest(colorKey);
            ExecuteRequest(image, request);
        }