Esempio n. 1
0
        private byte[] getAllBytes()
        {
            byte[] b;

            if (Mode == 0)
            {
                int ddsSize = 128;

                for (int i = 0; i < DDS.MipMaps.Count; i++)
                {
                    ddsSize += DDS.MipMaps[i].Data.Length;
                }

                b = new byte[4 + 4 + Path.Length + 4 + ddsSize];

                using (MemoryStream ms = new MemoryStream(b))
                    using (BinaryWriter bw = new BinaryWriter(ms))
                    {
                        bw.Write(Mode);               // 4
                        bw.Write(Path.Length);        // 4
                        bw.Write(Path.ToCharArray()); // path.length
                        bw.Write(ddsSize);            // 4
                        DDS.Save(bw, DDS);            // ddsSize
                    }
            }
            else
            {
                int rawSize = 46 + (Raw.Width * Raw.Height * 4);
                int offset  = 0;
                b = new byte[4 + 4 + Path.Length + 4 + rawSize];

                using (MemoryStream ms = new MemoryStream(b))
                    using (BinaryWriter bw = new BinaryWriter(ms))
                    {
                        bw.Write(Mode);               // 4
                        bw.Write(Path.Length);        // 4
                        bw.Write(Path.ToCharArray()); // path.length
                        bw.Write(rawSize);            // 4
                        bw.Write((short)0x1c);
                        bw.Write((short)0x02);
                        bw.Write(0);
                        bw.Write(0);
                        bw.Write((short)Raw.Width);
                        bw.Write((short)Raw.Height);
                        bw.Write(" (Bugbear Entertainment Ltd. ".ToCharArray());
                        bw.Write((byte)0);

                        offset = (int)bw.BaseStream.Position;
                    }

                BitmapData bmpdata = Raw.LockBits(new Rectangle(0, 0, Raw.Width, Raw.Height), ImageLockMode.ReadOnly, Raw.PixelFormat);
                Marshal.Copy(bmpdata.Scan0, b, offset, bmpdata.Stride * bmpdata.Height);
                Raw.UnlockBits(bmpdata);
            }

            return(b);
        }
Esempio n. 2
0
        public void SaveAs(string path, OutputFormat outputFormat)
        {
            if (Mode == 0)
            {
                switch (outputFormat)
                {
                case OutputFormat.PNG:
                    DDS.Decompress().Save(path, ImageFormat.Png);
                    break;

                case OutputFormat.DDS:
                    DDS.Save(path);
                    break;

                case OutputFormat.TGA:
                    TGA.FromBitmap(DDS.Decompress()).Save(path);
                    break;
                }
            }
            else
            {
                Raw.Save(path, ImageFormat.Png);
            }
        }