public static DdsHeader Read(Stream stream) { var reader = new BinaryReader(stream); if (stream.Length - stream.Position < 128) throw new InvalidOperationException("Invalid DDS file: header is too small"); var result = new DdsHeader(); // Read and verify magic if (reader.ReadUInt32() != DdsFourCc.FromString("DDS ")) throw new InvalidOperationException("Invalid DDS file: invalid header magic"); // Read the DDS header result.ReadDdsHeader(reader); // If the format FourCC is 'DX10', read the extended header if (result.FourCc == DdsFourCc.FromString("DX10")) result.ReadDdsD3D10Header(reader); return result; }