Skip to content

Commit

Permalink
Add initial support for other surface formats
Browse files Browse the repository at this point in the history
  • Loading branch information
iMrShadow committed Mar 20, 2024
1 parent 0a182dd commit 5cc0830
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 29 deletions.
317 changes: 300 additions & 17 deletions DDS_D3DTX_Converter_GUI/DDS_D3DTX_Converter/DirectX/DDS.cs

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions DDS_D3DTX_Converter_GUI/DDS_D3DTX_Converter/ImageProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static ImageProperties GetImagePropertiesFromD3DTX(string filePath)
MipMapCount = master.GetMipMapCount().ToString()
};
}

/// <summary>
/// Gets the properties of the selected .dds file
/// </summary>
Expand All @@ -57,19 +57,21 @@ public static ImageProperties GetDdsProperties(string ddsFilePath)

byte[] headerBytes = ByteFunctions.AllocateBytes(124, sourceFileData, 4);

//TODO: CHECK ALPHA IF IT'S CORRECT

var header = DDS.GetHeaderFromBytes(headerBytes);

byte[] bytes = BitConverter.GetBytes(header.ddspf.dwFourCC);
string result = System.Text.Encoding.UTF8.GetString(bytes);

result.Reverse();

string hasAlpha = "False";
if (header.ddspf.dwABitMask > 0)
if (header.ddspf.dwABitMask > 0)
{
hasAlpha = "True";
}

return new ImageProperties
{
Name = Path.GetFileNameWithoutExtension(ddsFilePath),
Expand All @@ -82,7 +84,7 @@ public static ImageProperties GetDdsProperties(string ddsFilePath)
MipMapCount = header.dwMipMapCount.ToString()
};
}

/// <summary>
/// Get the needed image properties from the selected file, excluding .dds and .d3dtx.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void ModifyD3DTX(DDS_Master dds)
{
mWidth = dds.header.dwWidth;
mHeight = dds.header.dwHeight;
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC, dds);
mNumMipLevels = dds.header.dwMipMapCount;

List<byte[]> ddsData = new List<byte[]>(dds.textureData); //this is correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void ModifyD3DTX(DDS_Master dds)
{
mWidth = dds.header.dwWidth;
mHeight = dds.header.dwHeight;
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC, dds);
//mDepth = dds.header.dwDepth;
}

Expand Down Expand Up @@ -389,7 +389,7 @@ public void WriteBinaryData(BinaryWriter writer)
}
}

public uint GetHeaderByteSize()
public uint GetHeaderByteSize()
{
uint totalSize = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void ModifyD3DTX(DDS_Master dds)
{
mWidth = dds.header.dwWidth;
mHeight = dds.header.dwHeight;
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC, dds);
//mDepth = dds.header.dwDepth;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public void ModifyD3DTX(DDS_Master dds)
{
mWidth = dds.header.dwWidth;
mHeight = dds.header.dwHeight;
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC, dds);
//mDepth = dds.header.dwDepth;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public void ModifyD3DTX(DDS_Master dds)
{
mWidth = dds.header.dwWidth;
mHeight = dds.header.dwHeight;
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC, dds);
mDepth = dds.header.dwDepth;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public void ModifyD3DTX(DDS_Master dds, DDS_DirectXTexNet_ImageSection[] section
{
mWidth = dds.header.dwWidth; //THIS IS CORRECT
mHeight = dds.header.dwHeight; //THIS IS CORRECT
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC); //THIS IS CORRECT
mSurfaceFormat = DDS.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC, dds); //THIS IS CORRECT
mDepth = dds.header.dwDepth; //THIS IS CORRECT
mNumMipLevels = dds.header.dwMipMapCount; //THIS IS CORRECT

Expand Down

0 comments on commit 5cc0830

Please sign in to comment.