Esempio n. 1
0
        public byte[] ToBytes()
        {
            byte[] data = new byte[0x80];

            DDSHeader header = this;

            BitConverter.GetBytes(header.Magic).CopyTo(data, 0x00);
            BitConverter.GetBytes(header.Size).CopyTo(data, 0x04);
            BitConverter.GetBytes(header.Flags).CopyTo(data, 0x08);
            BitConverter.GetBytes(header.Height).CopyTo(data, 0x0C);
            BitConverter.GetBytes(header.Width).CopyTo(data, 0x10);
            BitConverter.GetBytes(header.PitchOrLinearSize).CopyTo(data, 0x14);
            BitConverter.GetBytes(header.Depth).CopyTo(data, 0x18);
            BitConverter.GetBytes(header.MipMapCount).CopyTo(data, 0x1C);

            BitConverter.GetBytes(header.PixelFormat.Size).CopyTo(data, 0x4C);
            BitConverter.GetBytes(header.PixelFormat.Flags).CopyTo(data, 0x50);
            BitConverter.GetBytes((uint)header.PixelFormat.FourCC).CopyTo(data, 0x54);
            BitConverter.GetBytes(header.PixelFormat.RGBBitCount).CopyTo(data, 0x58);
            BitConverter.GetBytes(header.PixelFormat.RBitMask).CopyTo(data, 0x5C);
            BitConverter.GetBytes(header.PixelFormat.GBitMask).CopyTo(data, 0x60);
            BitConverter.GetBytes(header.PixelFormat.BBitMask).CopyTo(data, 0x64);
            BitConverter.GetBytes(header.PixelFormat.ABitMask).CopyTo(data, 0x68);

            BitConverter.GetBytes(header.Caps).CopyTo(data, 0x6C);
            BitConverter.GetBytes(header.Caps2).CopyTo(data, 0x70);

            return(data);
        }
Esempio n. 2
0
 public DDS(Stream ddsFile)
 {
     if (ddsFile.Length < 0x80)
     {
         throw new Exception("Invalid size for DDS file.");
     }
     Header = DDSHeader.FromStream(ddsFile);
     Data   = new MemoryStream((int)ddsFile.Length - 0x80);
     Util.CopyStream(ddsFile, Data, ddsFile.Length - 0x80);
 }
Esempio n. 3
0
        public static byte[] Generate(uint width, uint height, uint mipmaps, TextureFormat format)
        {
            if (!IsDDSTextureFormat(format))
            {
                throw new Exception("Texture format must be compatible with the DDS file format!");
            }

            byte[] data = new byte[0x80];

            DDSHeader header = new DDSHeader();

            header.Flags  = DDSFlags.DDSD_CAPS | DDSFlags.DDSD_HEIGHT | DDSFlags.DDSD_WIDTH | DDSFlags.DDSD_PIXELFORMAT;
            header.Width  = width;
            header.Height = height;
            if (mipmaps > 1)
            {
                header.Flags      |= DDSFlags.DDSD_MIPMAPCOUNT;
                header.MipMapCount = mipmaps;
            }
            header.PixelFormat.Flags  = DDSFlags.DDPF_FOURCC;
            header.PixelFormat.FourCC = format;

            BitConverter.GetBytes(header.Magic).CopyTo(data, 0x00);
            BitConverter.GetBytes(header.Size).CopyTo(data, 0x04);
            BitConverter.GetBytes(header.Flags).CopyTo(data, 0x08);
            BitConverter.GetBytes(header.Height).CopyTo(data, 0x0C);
            BitConverter.GetBytes(header.Width).CopyTo(data, 0x10);
            BitConverter.GetBytes(header.PitchOrLinearSize).CopyTo(data, 0x14);
            BitConverter.GetBytes(header.Depth).CopyTo(data, 0x18);
            BitConverter.GetBytes(header.MipMapCount).CopyTo(data, 0x1C);

            BitConverter.GetBytes(header.PixelFormat.Size).CopyTo(data, 0x4C);
            BitConverter.GetBytes(header.PixelFormat.Flags).CopyTo(data, 0x50);
            BitConverter.GetBytes((uint)header.PixelFormat.FourCC).CopyTo(data, 0x54);
            BitConverter.GetBytes(header.PixelFormat.RGBBitCount).CopyTo(data, 0x58);
            BitConverter.GetBytes(header.PixelFormat.RBitMask).CopyTo(data, 0x5C);
            BitConverter.GetBytes(header.PixelFormat.GBitMask).CopyTo(data, 0x60);
            BitConverter.GetBytes(header.PixelFormat.BBitMask).CopyTo(data, 0x64);
            BitConverter.GetBytes(header.PixelFormat.ABitMask).CopyTo(data, 0x68);

            BitConverter.GetBytes(header.Caps).CopyTo(data, 0x6C);
            BitConverter.GetBytes(header.Caps2).CopyTo(data, 0x70);

            return(data);
        }
Esempio n. 4
0
        public static byte[] Generate( uint width, uint height, uint mipmaps, TextureFormat format )
        {
            if ( !IsDDSTextureFormat( format ) ) { throw new Exception( "Texture format must be compatible with the DDS file format!" ); }

            byte[] data = new byte[0x80];

            DDSHeader header = new DDSHeader();
            header.Flags = DDSFlags.DDSD_CAPS | DDSFlags.DDSD_HEIGHT | DDSFlags.DDSD_WIDTH | DDSFlags.DDSD_PIXELFORMAT;
            header.Width = width;
            header.Height = height;
            if ( mipmaps > 1 ) {
                header.Flags |= DDSFlags.DDSD_MIPMAPCOUNT;
                header.MipMapCount = mipmaps;
            }
            header.PixelFormat.Flags = DDSFlags.DDPF_FOURCC;
            header.PixelFormat.FourCC = format;

            BitConverter.GetBytes( header.Magic ).CopyTo( data, 0x00 );
            BitConverter.GetBytes( header.Size ).CopyTo( data, 0x04 );
            BitConverter.GetBytes( header.Flags ).CopyTo( data, 0x08 );
            BitConverter.GetBytes( header.Height ).CopyTo( data, 0x0C );
            BitConverter.GetBytes( header.Width ).CopyTo( data, 0x10 );
            BitConverter.GetBytes( header.PitchOrLinearSize ).CopyTo( data, 0x14 );
            BitConverter.GetBytes( header.Depth ).CopyTo( data, 0x18 );
            BitConverter.GetBytes( header.MipMapCount ).CopyTo( data, 0x1C );

            BitConverter.GetBytes( header.PixelFormat.Size ).CopyTo( data, 0x4C );
            BitConverter.GetBytes( header.PixelFormat.Flags ).CopyTo( data, 0x50 );
            BitConverter.GetBytes( (uint)header.PixelFormat.FourCC ).CopyTo( data, 0x54 );
            BitConverter.GetBytes( header.PixelFormat.RGBBitCount ).CopyTo( data, 0x58 );
            BitConverter.GetBytes( header.PixelFormat.RBitMask ).CopyTo( data, 0x5C );
            BitConverter.GetBytes( header.PixelFormat.GBitMask ).CopyTo( data, 0x60 );
            BitConverter.GetBytes( header.PixelFormat.BBitMask ).CopyTo( data, 0x64 );
            BitConverter.GetBytes( header.PixelFormat.ABitMask ).CopyTo( data, 0x68 );

            BitConverter.GetBytes( header.Caps ).CopyTo( data, 0x6C );
            BitConverter.GetBytes( header.Caps2 ).CopyTo( data, 0x70 );

            return data;
        }
Esempio n. 5
0
        public static DDSHeader Generate(uint width, uint height, uint mipmaps, TextureFormat format)
        {
            if (!IsDDSTextureFormat(format))
            {
                throw new Exception("Texture format must be compatible with the DDS file format!");
            }

            DDSHeader header = new DDSHeader();

            header.Flags  = DDSFlags.DDSD_CAPS | DDSFlags.DDSD_HEIGHT | DDSFlags.DDSD_WIDTH | DDSFlags.DDSD_PIXELFORMAT;
            header.Width  = width;
            header.Height = height;
            if (mipmaps > 1)
            {
                header.Flags      |= DDSFlags.DDSD_MIPMAPCOUNT;
                header.MipMapCount = mipmaps;
            }
            header.PixelFormat.Flags  = DDSFlags.DDPF_FOURCC;
            header.PixelFormat.FourCC = format;

            return(header);
        }
Esempio n. 6
0
        public static DDSHeader FromStream(Stream stream)
        {
            DDSHeader header = new DDSHeader();

            header.Magic = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            if (header.Magic != 0x20534444)
            {
                throw new Exception("Invalid magic.");
            }
            header.Size = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            if (header.Size != 0x7C)
            {
                throw new Exception("Invalid size.");
            }
            header.Flags             = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Height            = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Width             = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.PitchOrLinearSize = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Depth             = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.MipMapCount       = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1a        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1b        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1c        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1d        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1e        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1f        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1g        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1h        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1i        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1j        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved1k        = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.PixelFormat       = DDSPixelFormat.FromStream(stream);
            header.Caps      = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Caps2     = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Caps3     = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Caps4     = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            header.Reserved2 = stream.ReadUInt32().FromEndian(EndianUtils.Endianness.LittleEndian);
            return(header);
        }
Esempio n. 7
0
 public DDS(DDSHeader header, Stream imageData)
 {
     Header = header;
     Data   = new MemoryStream((int)imageData.Length);
     Util.CopyStream(imageData, Data, imageData.Length);
 }