private static DDSHeader10 ReadHeader10(BinaryReader input) { DDSHeader10 header10 = new DDSHeader10(); header10.Exists = true; header10.Format = ReadDXGIFormat(input); header10.Dimension = ReadResourceDimension(input); header10.MiscFlag = input.ReadInt32(); header10.ArraySize = input.ReadInt32(); header10.Reserved = input.ReadInt32(); return(header10); }
private static SurfaceFormat DetermineFormat(DDSImageInfo image) { DDSHeader header = image.Header; DDSHeader10 header10 = image.Header10; int flags = header.ImageFormat.DwFlags; bool compressedFormat = IsSet(flags, (int)DDSPixelFlags.FourCC); bool rgb = IsSet(flags, (int)DDSPixelFlags.RGB); bool alphaPixels = IsSet(flags, (int)DDSPixelFlags.AlphaPixels); bool alpha = IsSet(flags, (int)DDSPixelFlags.Alpha); bool luminance = IsSet(flags, (int)DDSPixelFlags.Luminance); if (compressedFormat) { int fourCC = header.ImageFormat.DwFourCC; if (fourCC == GetInt("DXT1")) { return(SurfaceFormat.DXT1); } else if (fourCC == GetInt("DXT3")) { return(SurfaceFormat.DXT3); } else if (fourCC == GetInt("DXT5")) { return(SurfaceFormat.DXT5); } } else { if (rgb) { int bpp = header.ImageFormat.DwRGBBitCount; switch (bpp) { case 32: return(SurfaceFormat.Color); } } else if (alphaPixels && alpha && (header.ImageFormat.DwRGBBitCount == 8)) { return(SurfaceFormat.Alpha8); } } throw new InvalidDataException("Unsupported DDS format."); }
private static TextureDimensions DetermineTextureDimensions(DDSImageInfo image) { DDSHeader header = image.Header; DDSHeader10 header10 = image.Header10; if (IsSet(header.DwCaps2, (int)DDSCaps2.CubeMap)) { return(TextureDimensions.Cube); } else if (IsSet(header.DwCaps2, (int)DDSCaps2.Volume)) { return(TextureDimensions.Three); } else { return(TextureDimensions.Two); } }