Example #1
0
        public static RenderSurface FromBitmap(Bitmap surface)
        {
            RenderSurface obj = new RenderSurface();

            obj.Unknown = 6;
            obj.Width   = surface.Width;
            obj.Height  = surface.Height;
            obj.Format  = ImagePixelFormat.PFID_A8R8G8B8;
            obj.Colors  = GetBitmapColors(surface);

            return(obj);
        }
Example #2
0
        private static List <int> GetColorData(BinaryReader reader, RenderSurface obj)
        {
            List <int> colors     = new List <int>();
            uint       byteLength = reader.ReadUInt32();

            if (byteLength > 0)
            {
                switch (obj.Format)
                {
                case ImagePixelFormat.PFID_R8G8B8:     // RGB format. 3 bytes per pixel
                    for (uint i = 0; i < obj.Height; i++)
                    {
                        for (uint j = 0; j < obj.Width; j++)
                        {
                            byte b     = reader.ReadByte();
                            byte g     = reader.ReadByte();
                            byte r     = reader.ReadByte();
                            int  color = (r << 16) + (g << 8) + b;
                            colors.Add(color);
                        }
                    }

                    break;

                case ImagePixelFormat.PFID_A8R8G8B8:     // ARGB format... Most UI textures fall into this category
                    for (uint i = 0; i < obj.Height; i++)
                    {
                        for (uint j = 0; j < obj.Width; j++)
                        {
                            colors.Add(reader.ReadInt32());
                        }
                    }
                    break;

                case ImagePixelFormat.PFID_INDEX16:     // 16 indexed. Textures are colored via a palette.
                    for (uint y = 0; y < obj.Height; y++)
                    {
                        for (uint x = 0; x < obj.Width; x++)
                        {
                            colors.Add(reader.ReadInt16());
                        }
                    }
                    break;

                default:
                    log.Warn("Unhandled ImagePixelFormat " + obj.Format.ToString() + " in RenderSurface " + obj.Id.ToString("X8"));
                    break;
                }
            }
            return(colors);
        }
Example #3
0
        public static RenderSurface Unpack(BinaryReader reader)
        {
            RenderSurface obj = new RenderSurface();

            obj.Id      = reader.ReadUInt32();
            obj.Unknown = reader.ReadUInt32();
            obj.Width   = reader.ReadInt32();
            obj.Height  = reader.ReadInt32();
            obj.Format  = (ImagePixelFormat)reader.ReadUInt32();

            obj.Colors = GetColorData(reader, obj);

            switch (obj.Format)
            {
            case ImagePixelFormat.PFID_INDEX16:
                obj.DefaultPalette = reader.ReadUInt32();
                break;
            }

            return(obj);
        }