// Note that many common DDS reader/writers (including D3DX) swap the // the RED/BLUE masks for 10:10:10:2 formats. We assumme // below that the 'backwards' header mask is being used since it is most // likely written by D3DX. The more robust solution is to use the 'DX10' // header extension and specify the Format.R10G10B10A2_UNorm format directly // We do not support the following legacy Direct3D 9 formats: // BumpDuDv D3DFMT_V8U8, D3DFMT_Q8W8V8U8, D3DFMT_V16U16, D3DFMT_A2W10V10U10 // BumpLuminance D3DFMT_L6V5U5, D3DFMT_X8L8V8U8 // FourCC "UYVY" D3DFMT_UYVY // FourCC "YUY2" D3DFMT_YUY2 // FourCC 117 D3DFMT_CxV8U8 // ZBuffer D3DFMT_D16_LOCKABLE // FourCC 82 D3DFMT_D32F_LOCKABLE private static Format GetDXGIFormat(ref DDS.PixelFormat pixelFormat, DDSFlags flags, out ConversionFlags conversionFlags) { conversionFlags = ConversionFlags.None; int index = 0; for (index = 0; index < LegacyMaps.Length; ++index) { var entry = LegacyMaps[index]; if ((pixelFormat.Flags & entry.PixelFormat.Flags) != 0) { if ((entry.PixelFormat.Flags & DDS.PixelFormatFlags.FourCC) != 0) { if (pixelFormat.FourCC == entry.PixelFormat.FourCC) { break; } } else if ((entry.PixelFormat.Flags & DDS.PixelFormatFlags.Pal8) != 0) { if (pixelFormat.RGBBitCount == entry.PixelFormat.RGBBitCount) { break; } } else if (pixelFormat.RGBBitCount == entry.PixelFormat.RGBBitCount) { // RGB, RGBA, ALPHA, LUMINANCE if (pixelFormat.RBitMask == entry.PixelFormat.RBitMask && pixelFormat.GBitMask == entry.PixelFormat.GBitMask && pixelFormat.BBitMask == entry.PixelFormat.BBitMask && pixelFormat.ABitMask == entry.PixelFormat.ABitMask) { break; } } } } if (index >= LegacyMaps.Length) { return(Format.Unknown); } conversionFlags = LegacyMaps[index].ConversionFlags; var format = LegacyMaps[index].Format; if ((conversionFlags & ConversionFlags.Expand) != 0 && (flags & DDSFlags.NoLegacyExpansion) != 0) { return(Format.Unknown); } if ((format == Format.R10G10B10A2_UNorm) && (flags & DDSFlags.NoR10B10G10A2Fixup) != 0) { conversionFlags ^= ConversionFlags.Swizzle; } return(format); }
/// <summary> /// Initializes a new instance of the <see cref="LegacyMap" /> struct. /// </summary> /// <param name="format">The format.</param> /// <param name="conversionFlags">The conversion flags.</param> /// <param name="pixelFormat">The pixel format.</param> public LegacyMap(Format format, ConversionFlags conversionFlags, DDS.PixelFormat pixelFormat) { Format = format; ConversionFlags = conversionFlags; PixelFormat = pixelFormat; }