Skip to content

Commit

Permalink
Mips select option, cubemap saving, ATI support
Browse files Browse the repository at this point in the history
 - Added ATI1 and ATI2 codecs support
 - Added option to change mips count
 - Added option to saving cubemap textures
 - Fix width and height input
 - Rebuild GUI
  • Loading branch information
gmh4589 authored Oct 7, 2024
1 parent 27dfa40 commit 7bb38c3
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 30 deletions.
73 changes: 58 additions & 15 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public partial class Form1 : Form
{
private string fileName = string.Empty;
private CodecList codecList;
bool isCubemap = false;

public Form1()
{
Expand Down Expand Up @@ -70,16 +71,32 @@ private void dds_file_save(string codec_name, string file_name="temp")
byte[] codec_data = codecList.GetCodecData(codec_name);
byte[] name_codec = codecList.GetCodecName(codec_name);
int codec_data_len = codec_data.Length;
int linear_size = 0;
int mips_count = (int)mipsCount.Value;

if (x > y) {
linear_size = x;
} else {
linear_size = y;
}

using (FileStream ddsFile = new FileStream("out\\" + file_name + ".dds", FileMode.Create, FileAccess.Write))
if (isCubemap)
{
codec_data[25] = 0xFE;
} else {
codec_data[25] = 0x00;
}

using (FileStream ddsFile = new FileStream("out\\" + file_name + ".dds", FileMode.Create, FileAccess.Write))
{
ddsFile.Write(new byte[] { 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00 }, 0, 8); // DDS Header
ddsFile.Write(new byte[] { keys[0], pixel_format[0], depth[0], 0x00 }, 0, 4);
ddsFile.Write(BitConverter.GetBytes(x), 0, 4); // Height
ddsFile.Write(BitConverter.GetBytes(y), 0, 4); // Width
ddsFile.Write(BitConverter.GetBytes(y), 0, 4); // Linear size
ddsFile.Write(new byte[] { 0x01 }, 0, 1);
ddsFile.Write(new byte[51], 0, 51);
ddsFile.Write(BitConverter.GetBytes(linear_size), 0, 4); // Linear size
ddsFile.Write(new byte[] { 0x01, 0x00, 0x00, 0x00 }, 0, 4);
ddsFile.Write(BitConverter.GetBytes(mips_count), 0, 1);
ddsFile.Write(new byte[47], 0, 47);
ddsFile.Write(new byte[] { 0x20, 0x00, 0x00, 0x00 }, 0, 4);
ddsFile.Write(rgb, 0, 4);
ddsFile.Write(name_codec, 0, 4);
Expand Down Expand Up @@ -127,6 +144,14 @@ private void cancelBTN_Click(object sender, EventArgs e)
Console.WriteLine(codec);
this.dds_file_save(codec, codec);
}

MessageBox.Show("All formats are saved!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
isCubemap = !isCubemap;
}

}
}
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# dds_header_generator
Tools for generating headers to DDS textures files from any games

USAGE:
Run EXE file (download from release)
Press open file and select a file
Select a parametrs to cut texture from your file (offset, height, width and codec)
Press SAVE button
Near to EXE file create file temp.dds
Open temp.dds with any texture veiwer (for example XnView)
If result not good, save file another time with other parametrs
# dds_header_generator
Tools for generating headers to DDS textures files from any games

USAGE:
Run EXE file (download from release)
Press open file and select a file
Select a parametrs to cut texture from your file (offset, height, width and codec)
Press SAVE button
Near to EXE file create file temp.dds
Open temp.dds with any texture veiwer (for example XnView)
If result not good, save file another time with other parametrs
20 changes: 20 additions & 0 deletions codecList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ public CodecList()
{"pixel_format", new byte[] {0x10}},
{"rgb", new byte[] {0x04, 0x00, 0x00, 0x00}}
}
},
{"ATI1", new Dictionary<string, byte[]>
{
{"codec", new byte[] {0x41, 0x54, 0x49, 0x31}},
{"codec_data", new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{"depth", new byte[] {0x0a}},
{"keys", new byte[] {0x07}},
{"pixel_format", new byte[] {0x10}},
{"rgb", new byte[] {0x04, 0x00, 0x00, 0x00}}
}
},
{"ATI2", new Dictionary<string, byte[]>
{
{"codec", new byte[] {0x41, 0x54, 0x49, 0x32}},
{"codec_data", new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
{"depth", new byte[] {0x0a}},
{"keys", new byte[] {0x07}},
{"pixel_format", new byte[] {0x10}},
{"rgb", new byte[] {0x04, 0x00, 0x00, 0x00}}
}
},
{"B4G4R4A4_UNORM", new Dictionary<string, byte[]>
{
Expand Down

0 comments on commit 7bb38c3

Please sign in to comment.