FSO.IDE.Common.SpriteEncoderUtils.QuantizeFrame C# (CSharp) Method

QuantizeFrame() public static method

public static QuantizeFrame ( SPR2Frame frame, byte &bytes ) : Microsoft.Xna.Framework.Color[]
frame SPR2Frame
bytes byte
return Microsoft.Xna.Framework.Color[]
        public static Microsoft.Xna.Framework.Color[] QuantizeFrame(SPR2Frame frame, out byte[] bytes)
        {
            var bmps = GetPixelAlpha(frame, frame.Width, frame.Height, new Vector2());

            var quantpx = (Bitmap)ImageBuffer.QuantizeImage(bmps[0], new DistinctSelectionQuantizer(), null, 255, 4);
            var palt = quantpx.Palette.Entries;

            var data = quantpx.LockBits(new System.Drawing.Rectangle(0, 0, quantpx.Width, quantpx.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            bytes = new byte[data.Height * data.Width];

            // copy the bytes from bitmap to array
            for (int i = 0; i < data.Height; i++)
            {
                Marshal.Copy(data.Scan0 + i * data.Stride, bytes, i * data.Width, data.Width);
            }

            var result = new Microsoft.Xna.Framework.Color[palt.Length];
            for (int i=0; i<palt.Length; i++)
            {
                var c = palt[i];
                result[i] = new Microsoft.Xna.Framework.Color(c.R, c.G, c.B, c.A);
            }
            return result;
        }