public DDSPixelFormat(DDSPixelFormatFlags Flags, DDSPixelFormatFourCC FourCC, uint RGBBitCount, uint BitMaskRed, uint BitMaskGreen, uint BitMaskBlue, uint BitMaskRGBAlpha) { this.Size = 0x20; this.Flags = Flags; this.FourCC = FourCC; this.RGBBitCount = RGBBitCount; this.BitMaskRed = BitMaskRed; this.BitMaskGreen = BitMaskGreen; this.BitMaskBlue = BitMaskBlue; this.BitMaskRGBAlpha = BitMaskRGBAlpha; }
public DDSPixelFormat(DDSPixelFormatFlags Flags, DDSPixelFormatFourCC FourCC, uint RGBBitCount, uint BitMaskRed, uint BitMaskGreen, uint BitMaskBlue, uint BitMaskRGBAlpha) { this.Size = 0x20; this.Flags = Flags; this.FourCC = FourCC; this.RGBBitCount = RGBBitCount; this.BitMaskRed = BitMaskRed; this.BitMaskGreen = BitMaskGreen; this.BitMaskBlue = BitMaskBlue; this.BitMaskRGBAlpha = BitMaskRGBAlpha; }
/// <summary> /// Read the DDS Pixel Format Header /// </summary> /// <param name="reader"></param> /// <returns>Valid header</returns> public override bool Read(EndianReader reader) { reader.Format = EndianFormat.LittleEndian; var size = reader.ReadInt32(); if (size != Size) { return(false); } else { Flags = (DDSPixelFormatFlags)reader.ReadInt32(); FourCC = reader.ReadUInt32(); RGBBitCount = reader.ReadInt32(); RBitMask = reader.ReadUInt32(); GBitMask = reader.ReadUInt32(); BBitMask = reader.ReadUInt32(); ABitMask = reader.ReadUInt32(); return(true); } }
public void SetTextureFormat(BitmapFormat format, BitmapFlags flags) { if (flags.HasFlag(BitmapFlags.Compressed)) { Flags |= DDSPixelFormatFlags.Compressed; switch (format) { case BitmapFormat.Dxt5: Flags |= DDSPixelFormatFlags.FourCC; FourCC = 0x35545844; break; case BitmapFormat.Dxt3: Flags |= DDSPixelFormatFlags.FourCC; FourCC = 0x33545844; break; case BitmapFormat.Dxt1: Flags |= DDSPixelFormatFlags.FourCC; FourCC = 0x31545844; break; case BitmapFormat.Dxn: Flags |= DDSPixelFormatFlags.FourCC; FourCC = 0x32495441; break; default: throw new Exception($"Unsupported bitmap format {format}"); } } else { Flags |= DDSPixelFormatFlags.RGB; RGBBitCount = BitmapFormatUtils.GetBitsPerPixel(format); switch (format) { case BitmapFormat.A8: case BitmapFormat.AY8: ABitMask = 0xFF; Flags |= DDSPixelFormatFlags.Alpha; break; case BitmapFormat.Y8: RBitMask = 0xFF; Flags |= DDSPixelFormatFlags.Luminance; break; case BitmapFormat.A8Y8: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0x00FF; ABitMask = 0xFF00; break; case BitmapFormat.R5G6B5: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0xF800; GBitMask = 0x07E0; BBitMask = 0x001F; break; case BitmapFormat.A1R5G5B5: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0x7C00; GBitMask = 0x03E0; BBitMask = 0x001F; ABitMask = 0x8000; break; case BitmapFormat.A4R4G4B4: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0xF000; GBitMask = 0x0F00; BBitMask = 0x00F0; ABitMask = 0x000F; break; case BitmapFormat.A4R4G4B4Font: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0xF000; GBitMask = 0x0F00; BBitMask = 0x00F0; ABitMask = 0x000F; break; case BitmapFormat.A8R8G8B8: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0x00FF0000; GBitMask = 0x0000FF00; BBitMask = 0x000000FF; ABitMask = 0xFF000000; break; case BitmapFormat.X8R8G8B8: Flags |= DDSPixelFormatFlags.RGB; RBitMask = 0x00FF0000; GBitMask = 0x0000FF00; BBitMask = 0x000000FF; break; case BitmapFormat.V8U8: RBitMask = 0xFF00; GBitMask = 0x00FF; Flags |= DDSPixelFormatFlags.BumpDUDV; break; case BitmapFormat.A32B32G32R32F: Flags |= DDSPixelFormatFlags.FourCC; FourCC = 0x74; break; case BitmapFormat.A16B16G16R16F: Flags |= DDSPixelFormatFlags.FourCC; FourCC = 0x71; break; default: throw new Exception($"Unsupported bitmap format {format}"); } } }