Exemplo n.º 1
0
        public TextureEditor(FileEntry file) : base(file)
        {
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Program.Filesystem.GetFileData(file)))
                using (System.IO.BinaryReader reader = new System.IO.BinaryReader(ms))
                {
                    Texture = new Drome.Texture(reader);
                }

            Control = new Controls.TextureEditorControl();
            //Control.Init
            Control.Texture = Texture;
            BaseControl     = Control;
        }
Exemplo n.º 2
0
        private System.Drawing.Bitmap GenerateTexturePreview(Drome.Texture texture)
        {
            System.Drawing.Bitmap             result = new System.Drawing.Bitmap((int)texture.Width, (int)texture.Height);
            System.Drawing.Imaging.BitmapData data   = result.LockBits(new System.Drawing.Rectangle(0, 0, (int)texture.Width, (int)texture.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            // Acquire pixel data and flip it
            byte[] rawPixelData     = texture.DumpPixelData();
            byte[] flippedPixelData = new byte[(int)texture.Width * (int)texture.Height * 4];
            for (int row = 0; row < texture.Height; row++)
            {
                for (int col = 0; col < texture.Width; col++)
                {
                    int actualRow = (int)texture.Height - row - 1;
                    flippedPixelData[actualRow * texture.Width * 4 + col * 4]     = rawPixelData[row * texture.Width * 4 + col * 4];
                    flippedPixelData[actualRow * texture.Width * 4 + col * 4 + 1] = rawPixelData[row * texture.Width * 4 + col * 4 + 1];
                    flippedPixelData[actualRow * texture.Width * 4 + col * 4 + 2] = rawPixelData[row * texture.Width * 4 + col * 4 + 2];
                    flippedPixelData[actualRow * texture.Width * 4 + col * 4 + 3] = rawPixelData[row * texture.Width * 4 + col * 4 + 3];
                }
            }

            System.Runtime.InteropServices.Marshal.Copy(flippedPixelData, 0, data.Scan0, (int)texture.Width * (int)texture.Height * 4);
            result.UnlockBits(data);
            return(result);
        }