Skip to content

Commit

Permalink
Added experimental support for DXT3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Atvaark committed Jan 15, 2015
1 parent e2c621a commit 0f72801
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 557 deletions.
159 changes: 84 additions & 75 deletions FtexTool/Dds/DdsFileHeader.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,84 @@
using System;
using System.IO;
using System.Text;
using FtexTool.Dds.Enum;

namespace FtexTool.Dds
{
public class DdsFileHeader
{
public const int DefaultHeaderSize = 124;
public int Size { get; set; }
public DdsFileHeaderFlags Flags { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public int PitchOrLinearSize { get; set; }
public int Depth { get; set; }
public int MipMapCount { get; set; }
public DdsPixelFormat PixelFormat { get; set; }
public DdsSurfaceFlags Caps { get; set; }
public DdsCubemap Caps2 { get; set; }
public int Caps3 { get; set; }
public int Caps4 { get; set; }

public static DdsFileHeader Read(Stream inputStream)
{
DdsFileHeader result = new DdsFileHeader();
BinaryReader reader = new BinaryReader(inputStream, Encoding.Default, true);
result.Size = reader.ReadInt32();
result.Flags = (DdsFileHeaderFlags) reader.ReadInt32();
result.Height = reader.ReadInt32();
result.Width = reader.ReadInt32();
result.PitchOrLinearSize = reader.ReadInt32();
result.Depth = reader.ReadInt32();
result.MipMapCount = reader.ReadInt32();
// int Reserved1[11];
reader.Skip(44);
result.PixelFormat = DdsPixelFormat.ReadDdsPixelFormat(inputStream);
result.Caps = (DdsSurfaceFlags) reader.ReadInt32();
result.Caps2 = (DdsCubemap) reader.ReadInt32();
result.Caps3 = reader.ReadInt32();
result.Caps4 = reader.ReadInt32();
// int Reserved2;
reader.Skip(4);
return result;
}

public void Write(Stream outputStream)
{
BinaryWriter writer = new BinaryWriter(outputStream, Encoding.Default, true);
writer.Write(Size);
writer.Write(Convert.ToInt32(Flags));
writer.Write(Height);
writer.Write(Width);
writer.Write(PitchOrLinearSize);
writer.Write(Depth);
writer.Write(MipMapCount);
// int Reserved1[11];
writer.WriteZeros(44);
PixelFormat.Write(outputStream);
writer.Write(Convert.ToInt32(Caps));
writer.Write(Convert.ToInt32(Caps2));
writer.Write(Caps3);
writer.Write(Caps4);
// int Reserved2
writer.WriteZeros(4);
}

public bool IsDx10()
{
return PixelFormat != null &&
PixelFormat.Flags.HasFlag(DdsPixelFormatFlag.FourCc) &&
PixelFormat.FourCc == DdsPixelFormat.Dx10FourCc;
}
}
}
using System;
using System.IO;
using System.Text;
using FtexTool.Dds.Enum;

namespace FtexTool.Dds
{
public class DdsFileHeader
{
public const int DefaultHeaderSize = 124;
public int Size { get; set; }
public DdsFileHeaderFlags Flags { get; set; }
public int Height { get; set; }
public int Width { get; set; }
public int PitchOrLinearSize { get; set; }
public int Depth { get; set; }
public int MipMapCount { get; set; }
public DdsPixelFormat PixelFormat { get; set; }
public DdsSurfaceFlags Caps { get; set; }
public DdsCubemap Caps2 { get; set; }
public int Caps3 { get; set; }
public int Caps4 { get; set; }

public static DdsFileHeader Read(Stream inputStream)
{
DdsFileHeader result = new DdsFileHeader();
BinaryReader reader = new BinaryReader(inputStream, Encoding.Default, true);
result.Size = reader.ReadInt32();
result.Flags = (DdsFileHeaderFlags) reader.ReadInt32();
result.Height = reader.ReadInt32();
result.Width = reader.ReadInt32();
result.PitchOrLinearSize = reader.ReadInt32();
result.Depth = reader.ReadInt32();
result.MipMapCount = reader.ReadInt32();
// int Reserved1[11];
reader.Skip(44);
result.PixelFormat = DdsPixelFormat.ReadDdsPixelFormat(inputStream);
result.Caps = (DdsSurfaceFlags) reader.ReadInt32();
result.Caps2 = (DdsCubemap) reader.ReadInt32();
result.Caps3 = reader.ReadInt32();
result.Caps4 = reader.ReadInt32();
// int Reserved2;
reader.Skip(4);
return result;
}

public void Write(Stream outputStream)
{
BinaryWriter writer = new BinaryWriter(outputStream, Encoding.Default, true);
writer.Write(Size);
writer.Write(Convert.ToInt32(Flags));
writer.Write(Height);
writer.Write(Width);
writer.Write(PitchOrLinearSize);
writer.Write(Depth);
writer.Write(MipMapCount);
// int Reserved1[11];
writer.WriteZeros(44);
PixelFormat.Write(outputStream);
writer.Write(Convert.ToInt32(Caps));
writer.Write(Convert.ToInt32(Caps2));
writer.Write(Caps3);
writer.Write(Caps4);
// int Reserved2
writer.WriteZeros(4);
}

public bool IsDx10()
{
return PixelFormat != null &&
PixelFormat.Flags.HasFlag(DdsPixelFormatFlag.FourCc) &&
PixelFormat.FourCc == DdsPixelFormat.Dx10FourCc;
}

public override string ToString()
{
return string.Format("Size: {0}, Flags: {1}, Height: {2}, Width: {3}," +
" PitchOrLinearSize: {4}, Depth: {5}, MipMapCount: {6}," +
" PixelFormat: {7}, Caps: {8}, Caps2: {9}, Caps3: {10}, " +
"Caps4: {11}", Size, Flags, Height, Width, PitchOrLinearSize,
Depth, MipMapCount, PixelFormat, Caps, Caps2, Caps3, Caps4);
}
}
}
Loading

0 comments on commit 0f72801

Please sign in to comment.