public void Read(GenericReader r) { var size = r.ReadUInt32(); if (size != 124) { throw new FileFormatException($"Invalid DDS file header size: {size}."); } dwFlags = (DDSFlags)r.ReadUInt32(); if (!Utils.ContainsBitFlags((int)dwFlags, (int)DDSFlags.Height, (int)DDSFlags.Width)) { throw new FileFormatException($"Invalid DDS file flags: {dwFlags}."); } dwHeight = r.ReadUInt32(); dwWidth = r.ReadUInt32(); dwPitchOrLinearSize = r.ReadUInt32(); dwDepth = r.ReadUInt32(); dwMipMapCount = r.ReadUInt32(); dwReserved1 = new uint[11]; for (var i = 0; i < 11; i++) { dwReserved1[i] = r.ReadUInt32(); } ddspf = new DDSPixelFormat(r); dwCaps = (DDSCaps)r.ReadUInt32(); if (!Utils.ContainsBitFlags((int)dwCaps, (int)DDSCaps.Texture)) { throw new FileFormatException($"Invalid DDS file caps: {dwCaps}."); } dwCaps2 = (DDSCaps2)r.ReadUInt32(); dwCaps3 = r.ReadUInt32(); dwCaps4 = r.ReadUInt32(); dwReserved2 = r.ReadUInt32(); }
internal static DDSHeader Read(BinaryReader br) { var h = new DDSHeader(); h.size = br.ReadInt32(); h.flags = br.ReadInt32(); h.height = br.ReadInt32(); h.width = br.ReadInt32(); h.sizeOrPitch = br.ReadInt32(); h.depth = br.ReadInt32(); h.mipMapCount = br.ReadInt32(); h.reserved1 = new int[11]; for (var i = 0; i < 11; ++i) { h.reserved1[i] = br.ReadInt32(); } h.pixelFormat = DDSPixelFormat.Read(br); h.caps = DDSCaps.Read(br); h.reserved2 = br.ReadInt32(); return(h); }
public int[] reserved; //length = 2 internal static DDSCaps Read(BinaryReader br) { var caps = new DDSCaps(); caps.caps1 = br.ReadInt32(); caps.caps2 = br.ReadInt32(); caps.reserved = new int[2]; caps.reserved[0] = br.ReadInt32(); caps.reserved[1] = br.ReadInt32(); return(caps); }
private static DDSHeader ReadHeader(BinaryReader input) { DDSHeader header = new DDSHeader(); header.DwSize = input.ReadInt32(); if (header.DwSize != 124) { throw new InvalidOperationException("Invalid dds header size."); } header.DwFlags = input.ReadInt32(); header.DwHeight = input.ReadInt32(); header.DwWidth = input.ReadInt32(); header.DwLinearSize = input.ReadInt32(); header.DwDepth = input.ReadInt32(); header.DwMipMapCount = input.ReadInt32(); header.DwAlphaBitDepth = input.ReadInt32(); header.DwReserved1 = new int[10]; for (int i = 0; i < 10; i++) { header.DwReserved1[i] = input.ReadInt32(); } header.ImageFormat = ReadImageFormat(input); header.DwCaps = input.ReadInt32(); header.DwCaps2 = input.ReadInt32(); header.DwCaps3 = input.ReadInt32(); header.DwCaps4 = input.ReadInt32(); header.DwTextureStage = input.ReadInt32(); int mipMaps = 1 + (int)System.Math.Ceiling(System.Math.Log(System.Math.Max(header.DwHeight, header.DwWidth)) / System.Math.Log(2)); DDSCaps cap = (DDSCaps)header.DwCaps; if ((cap & DDSCaps.MipMap) == DDSCaps.MipMap) { DDSFlags flag = (DDSFlags)header.DwFlags; if ((flag & DDSFlags.MipCount) != DDSFlags.MipCount) { header.DwMipMapCount = mipMaps; } } else { header.DwMipMapCount = 1; } return(header); }
public int[] reserved; //length = 2 internal static DDSCaps Read( BinaryReader br ) { var caps = new DDSCaps(); caps.caps1 = br.ReadInt32(); caps.caps2 = br.ReadInt32(); caps.reserved = new int[2]; caps.reserved[ 0 ] = br.ReadInt32(); caps.reserved[ 1 ] = br.ReadInt32(); return caps; }