public DDSImage(SubStream data) { if (data.GetByte(0) == 'D' && data.GetByte(1) == 'D' && data.GetByte(2) == 'S' && data.GetByte(3) == ' ') { Height = data.GetInt32(12); Width = data.GetInt32(16); Depth = data.GetInt32(24); Flags = data.GetUInt32(8); Pitch = data.GetInt32(20); FourCC = Encoding.ASCII.GetString(data.GetBytes(84, 4)); RGBBitCount = data.GetInt32(88); RedMask = data.GetUInt32(92); GreenMask = data.GetUInt32(96); BlueMask = data.GetUInt32(100); AlphaMask = data.GetUInt32(104); Data = data; ImageOffset = 128; if (Depth == 0) { Depth = 1; } if ((Flags & 8) == 0) { Pitch = Width * RGBBitCount / 8; } IsARGB32 = (FourCC == "DXT1" || FourCC == "DXT2" || FourCC == "DXT3" || FourCC == "DXT4" || FourCC == "DXT5" || FourCC == "\0\0\0\0"); IntensityFactor = 1.0; try { FailureReason = null; switch (FourCC) { case "DXT1": Bitmap = GetBitmapFromDDS_DXT1(Data, ImageOffset, Width, Height, out HasAlpha); break; case "DXT2": Bitmap = GetBitmapFromDDS_DXT3(Data, ImageOffset, Width, Height, true, out HasAlpha); break; case "DXT3": Bitmap = GetBitmapFromDDS_DXT3(Data, ImageOffset, Width, Height, false, out HasAlpha); break; case "DXT4": Bitmap = GetBitmapFromDDS_DXT5(Data, ImageOffset, Width, Height, true, out HasAlpha); break; case "DXT5": Bitmap = GetBitmapFromDDS_DXT5(Data, ImageOffset, Width, Height, false, out HasAlpha); break; case "\0\0\0\0": Bitmap = GetBitmapFromDDS_RAW(Data, ImageOffset, Width, Height, Pitch, RGBBitCount, RedMask, GreenMask, BlueMask, AlphaMask, out HasAlpha, out IsARGB32); break; case "q\0\0\0": Bitmap = GetBitmapFromDDS_ARGB16F(Data, ImageOffset, Width, Height, out HasAlpha, out IntensityFactor); break; default: Bitmap = null; FailureReason = String.Format("Unknown DDS FourCC {0:X2}:{1:X2}:{2:X2}:{3:X2}", Data.GetByte(84), Data.GetByte(85), Data.GetByte(86), Data.GetByte(87)); break; } } catch (Exception ex) { Bitmap = null; FailureReason = ex.Message; } } else { throw new NotImplementedException(String.Format("Unknown file format {0:X2}:{1:X2}:{2:X2}:{3:X2}", data.GetByte(0), data.GetByte(1), data.GetByte(2), data.GetByte(3))); } }