public void Read(BinaryReaderExt reader) { reader.ReadChars(4); dwSize = reader.ReadUInt32(); dwFlags = (DDSD)reader.ReadUInt32(); dwHeight = reader.ReadInt32(); dwWidth = reader.ReadInt32(); dwPitchOrLinearSize = reader.ReadInt32(); dwDepth = reader.ReadInt32(); dwMipMapCount = reader.ReadInt32(); dwReserved1 = new uint[11]; for (int i = 0; i < 11; i++) { dwReserved1[i] = reader.ReadUInt32(); } ddspf.Read(reader); dwCaps = (DDSCAPS)reader.ReadInt32(); dwCaps2 = (DDSCAPS2)reader.ReadInt32(); dwCaps3 = reader.ReadUInt32(); dwCaps4 = reader.ReadUInt32(); dwReserved2 = reader.ReadUInt32(); if (ddspf.dwFlags.HasFlag(DDPF.FOURCC) && ddspf.dwFourCC == 0x30315844) { DXT10Header.Read(reader); } }
/// <summary> /// Read a DDS header from an array of bytes. /// </summary> public DDS(byte[] bytes) { BinaryReaderEx br = new BinaryReaderEx(false, bytes); // dwMagic br.AssertASCII("DDS "); // dwSize br.AssertInt32(0x7C); dwFlags = (DDSD)br.ReadUInt32(); dwHeight = br.ReadInt32(); dwWidth = br.ReadInt32(); dwPitchOrLinearSize = br.ReadInt32(); dwDepth = br.ReadInt32(); dwMipMapCount = br.ReadInt32(); // dwReserved1 br.Skip(4 * 11); ddspf = new PIXELFORMAT(br); dwCaps = (DDSCAPS)br.ReadUInt32(); dwCaps2 = (DDSCAPS2)br.ReadUInt32(); // dwCaps3, dwCaps4, dwReserved2 br.Skip(4 * 3); if (ddspf.dwFourCC == PIXELFORMAT.FourCCDX10) { header10 = new HEADER_DXT10(br); } else { header10 = null; } }
/// <summary> /// Create a new DDS header with default values and no DX10 header. /// </summary> public DDS() { dwFlags = HEADER_FLAGS_TEXTURE; dwReserved1 = new int[11]; ddspf = new PIXELFORMAT(); dwCaps = DDSCAPS.TEXTURE; }
/// <summary> /// Create a new DDS header with default values and no DX10 header. /// </summary> public DDS() { dwFlags = HEADER_FLAGS_TEXTURE; dwHeight = 0; dwWidth = 0; dwPitchOrLinearSize = 0; dwDepth = 0; dwMipMapCount = 0; ddspf = new PIXELFORMAT(); dwCaps = DDSCAPS.TEXTURE; dwCaps2 = 0; header10 = null; }
private static void CheckHeaderFlags(DDSImage workImage, DDSD flags) { if (!flags.HasFlag(DDSD.CAPS)) { workImage.AddMessage(new DDSMessage(DDSMessageType.Warning, "Header did not contain the CAPS flag!")); } if (!flags.HasFlag(DDSD.HEIGHT)) { workImage.AddMessage(new DDSMessage(DDSMessageType.Warning, "Header did not contain the HEIGHT flag!")); } if (!flags.HasFlag(DDSD.WIDTH)) { workImage.AddMessage(new DDSMessage(DDSMessageType.Warning, "Header did not contain the WIDTH flag!")); } if (!flags.HasFlag(DDSD.PIXELFORMAT)) { workImage.AddMessage(new DDSMessage(DDSMessageType.Warning, "Header did not contain the PIXELFORMAT flag!")); } }
public void Read(BinaryReader br) { dwMagic = br.ReadInt32(); // DDSURFACEDESC2 dwSize = br.ReadInt32(); dwFlags = (DDSD)br.ReadInt32(); dwHeight = br.ReadInt32(); dwWidth = br.ReadInt32(); dwPitchOrLinearSize = br.ReadInt32(); dwDepth = br.ReadInt32(); dwMipMapCount = br.ReadInt32(); dwReserved1 = new int[11]; for (int x = 0; x < dwReserved1.Length; x++) { dwReserved1[x] = br.ReadInt32(); } // DDPIXELFORMAT dwSize2 = br.ReadInt32(); dwFlags2 = (DDPF)br.ReadInt32(); dwFourCC = (FourCC)br.ReadInt32(); dwRGBBitCount = br.ReadInt32(); dwRBitMask = br.ReadInt32(); dwGBitMask = br.ReadInt32(); dwBBitMask = br.ReadInt32(); dwRGBAlphaBitMask = br.ReadUInt32(); // DDSCAPS2; dwCaps1 = (DDSCAPS)br.ReadInt32(); dwCaps2 = (DDSCAPS2)br.ReadInt32(); Reserved2 = new int[2]; for (int x = 0; x < Reserved2.Length; x++) { Reserved2[x] = br.ReadInt32(); } dwReserved3 = br.ReadInt32(); }
public void Read(BinaryReader br) { int num; dwMagic = br.ReadInt32(); dwSize = br.ReadInt32(); dwFlags = (DDSD)br.ReadInt32(); dwHeight = br.ReadInt32(); dwWidth = br.ReadInt32(); dwPitchOrLinearSize = br.ReadInt32(); dwDepth = br.ReadInt32(); dwMipMapCount = br.ReadInt32(); dwReserved1 = new int[11]; for (num = 0; num < dwReserved1.Length; num++) { dwReserved1[num] = br.ReadInt32(); } dwSize2 = br.ReadInt32(); dwFlags2 = (DDPF)br.ReadInt32(); dwFourCC = (FourCC)br.ReadInt32(); dwRGBBitCount = br.ReadInt32(); dwRBitMask = br.ReadInt32(); dwGBitMask = br.ReadInt32(); dwBBitMask = br.ReadInt32(); dwRGBAlphaBitMask = br.ReadUInt32(); dwCaps1 = (DDSCAPS)br.ReadInt32(); dwCaps2 = (DDSCAPS2)br.ReadInt32(); Reserved2 = new int[2]; for (num = 0; num < Reserved2.Length; num++) { Reserved2[num] = br.ReadInt32(); } dwReserved3 = br.ReadInt32(); }
public DDS(bitmap.BitmapData BitmapInfo) { dwMagic = 0x20534444; dwSize = 0x7c; dwFlags = 0; dwFlags |= DDSD.CAPS; dwFlags |= DDSD.HEIGHT; dwFlags |= DDSD.WIDTH; dwFlags |= DDSD.PIXELFORMAT; dwHeight = BitmapInfo.VirtualHeight; dwWidth = BitmapInfo.VirtualWidth; if (BitmapInfo.Format == BitmapFormat.A8R8G8B8) { dwFlags |= DDSD.PITCH; dwPitchOrLinearSize = dwWidth * 4; } else { dwFlags |= DDSD.LINEARSIZE; dwPitchOrLinearSize = BitmapInfo.RawSize; } dwDepth = 0; dwMipMapCount = 0; dwReserved1 = new int[11]; dwSize2 = 0x20; dwFlags2 = 0; dwFourCC = FourCC.None; switch (BitmapInfo.Format) { case BitmapFormat.A8R8G8B8: dwFlags2 |= DDPF.RGB; dwFlags2 |= DDPF.ALPHAPIXELS; break; case BitmapFormat.Dxt1: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT1; break; case BitmapFormat.Dxt3: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT3; break; case BitmapFormat.Dxt5: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT5; break; } if (BitmapInfo.Format == BitmapFormat.A8R8G8B8) { dwRGBBitCount = 0x20; dwRBitMask = 0xff0000; dwGBitMask = 0xff00; dwBBitMask = 0xff; dwRGBAlphaBitMask = 0xff000000; } else { dwRGBBitCount = 0; dwRBitMask = 0; dwGBitMask = 0; dwBBitMask = 0; dwRGBAlphaBitMask = 0; } dwCaps1 = 0; dwCaps1 |= DDSCAPS.TEXTURE; dwCaps2 = 0; Reserved2 = new int[2]; dwReserved3 = 0; }
public static byte[] Headerize(TPF.Texture texture) { if (Encoding.ASCII.GetString(texture.Bytes, 0, 4) == "DDS ") { return(texture.Bytes); } DDS dds = new DDS(); PIXELFORMAT ddspf = dds.ddspf; byte format = texture.Format; if (format != 16 && format != 26) { DDSD dwFlags = DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT | DDSD.MIPMAPCOUNT; if (format == 0 || format == 1 || format == 3 || format == 5) { dwFlags |= DDSD.LINEARSIZE; } else if (format == 9 || format == 10) { dwFlags |= DDSD.PITCH; } dds.dwFlags = dwFlags; dds.dwHeight = texture.Header.Height; dds.dwWidth = texture.Header.Width; if (format == 9 || format == 10) { dds.dwPitchOrLinearSize = (texture.Header.Width * 32 + 7) / 8; } //else if (format == 0 || format == 1) // pitch = Math.Max(1, (texture.Header.Width + 3) / 4) * (8 * 8 * 8); //else if (format == 5) // pitch = Math.Max(1, (texture.Header.Width + 3) / 4) * (16 * 16 * 8); dds.dwDepth = 1; dds.dwMipMapCount = texture.Mipmaps; DDPF ddspfdwFlags = 0; if (format == 0 || format == 1 || format == 3 || format == 5) { ddspfdwFlags |= DDPF.FOURCC; } else if (format == 9) { ddspfdwFlags |= DDPF.ALPHAPIXELS | DDPF.RGB; } else if (format == 10) { ddspfdwFlags |= DDPF.RGB; } ddspf.dwFlags = ddspfdwFlags; if (format == 0 || format == 1) { ddspf.SetFourCCAsString("DXT1"); } else if (format == 3) { ddspf.SetFourCCAsString("DXT3"); } else if (format == 5) { ddspf.SetFourCCAsString("DXT5"); } else { ddspf.dwFourCC = 0; } if (format == 9 || format == 10) { ddspf.dwRGBBitCount = 32; } if (format == 9) { ddspf.dwRBitMask = 0x00FF0000; ddspf.dwGBitMask = 0x0000FF00; ddspf.dwBBitMask = 0x000000FF; ddspf.dwABitMask = 0xFF000000; } else if (format == 10) { ddspf.dwRBitMask = 0x000000FF; ddspf.dwGBitMask = 0x0000FF00; ddspf.dwBBitMask = 0x00FF0000; ddspf.dwABitMask = 0x00000000; } DDSCAPS dwCaps = DDSCAPS.TEXTURE; if (texture.Type == TPF.TexType.Cubemap) { dwCaps |= DDSCAPS.COMPLEX; } if (texture.Mipmaps > 1) { dwCaps |= DDSCAPS.COMPLEX | DDSCAPS.MIPMAP; } dds.dwCaps = dwCaps; if (texture.Type == TPF.TexType.Cubemap) { dds.dwCaps2 = CUBEMAP_ALLFACES; } else if (texture.Type == TPF.TexType.Volume) { dds.dwCaps2 = DDSCAPS2.VOLUME; } } else { //int a = 0; } return(dds.Write(texture.Bytes)); }
public DDS(HaloDeveloper.Raw.BitmapRaw.BitmapSubmap BitmapInfo) { dwMagic = 0x20534444; // "DDS " dwSize = 0x7C; // Size of DDSURFACEDESC2 struct // Setup the basic flags that we know we will always have dwFlags = 0; dwFlags |= DDSD.CAPS; dwFlags |= DDSD.HEIGHT; dwFlags |= DDSD.WIDTH; dwFlags |= DDSD.PIXELFORMAT; // Set our height and width dwHeight = BitmapInfo.vHeight; dwWidth = BitmapInfo.vWidth; // We will provide a pitch or linear size if (BitmapInfo.Format == TextureFormat.A8R8G8B8) { dwFlags |= DDSD.PITCH; dwPitchOrLinearSize = dwWidth * 4; } else { dwFlags |= DDSD.LINEARSIZE; dwPitchOrLinearSize = BitmapInfo.RawLength; // Size of first mip } dwDepth = 0; // I havent seen this used yet in xtd's // We will provide a mipmap count if theres more then 1 level //if (BitmapInfo.Levels > 1) //{ // dwFlags |= DDSD.MIPMAPCOUNT; // dwMipMapCount = BitmapInfo.Levels; //} //else dwMipMapCount = 0; dwReserved1 = new int[11]; // Reserved dwSize2 = 0x00000020; // Size of DDPIXELFORMAT struct // Fill out our flags and fourcc dwFlags2 = 0; dwFourCC = FourCC.None; switch (BitmapInfo.Format) { case TextureFormat.DXT1: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT1; break; case TextureFormat.DXT3: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT3; break; case TextureFormat.DXT5: dwFlags2 |= DDPF.FOURCC; dwFourCC = FourCC.DXT5; break; case TextureFormat.A8R8G8B8: dwFlags2 |= DDPF.RGB; dwFlags2 |= DDPF.ALPHAPIXELS; break; } // Fill in the rest of the struct if (BitmapInfo.Format == TextureFormat.A8R8G8B8) { dwRGBBitCount = 0x20; dwRBitMask = 0x00ff0000; dwGBitMask = 0x0000ff00; dwBBitMask = 0x000000ff; dwRGBAlphaBitMask = 0xff000000; } else { dwRGBBitCount = 0x00000000; dwRBitMask = 0x00000000; dwGBitMask = 0x00000000; dwBBitMask = 0x00000000; dwRGBAlphaBitMask = 0x00000000; } // Fill in our DDSCAPS2 info dwCaps1 = 0; dwCaps1 |= DDSCAPS.TEXTURE; //if (BitmapInfo.Levels > 1) //{ // dwCaps1 |= DDSCAPS.COMPLEX; // dwCaps1 |= DDSCAPS.MIPMAP; //} dwCaps2 = 0; Reserved2 = new int[2]; dwReserved3 = 0x00000000; }