mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-30 00:10:36 +00:00
DDS fixes. Add BC7 normal mode for slower but better quality compression
This commit is contained in:
parent
b64e744d26
commit
cd721af0eb
14 changed files with 138 additions and 34 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -47,6 +47,8 @@
|
|||
this.HeightLabel = new Switch_Toolbox.Library.Forms.STLabel();
|
||||
this.pictureBox1 = new Switch_Toolbox.Library.Forms.PictureBoxCustom();
|
||||
this.formatComboBox = new Switch_Toolbox.Library.Forms.STComboBox();
|
||||
this.compressionModeCB = new Switch_Toolbox.Library.Forms.STComboBox();
|
||||
this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel();
|
||||
this.contentContainer.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.SwizzleNum)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.MipmapNum)).BeginInit();
|
||||
|
@ -55,6 +57,8 @@
|
|||
//
|
||||
// contentContainer
|
||||
//
|
||||
this.contentContainer.Controls.Add(this.compressionModeCB);
|
||||
this.contentContainer.Controls.Add(this.stLabel1);
|
||||
this.contentContainer.Controls.Add(this.SwizzleNum);
|
||||
this.contentContainer.Controls.Add(this.label5);
|
||||
this.contentContainer.Controls.Add(this.tileModeCB);
|
||||
|
@ -88,6 +92,8 @@
|
|||
this.contentContainer.Controls.SetChildIndex(this.tileModeCB, 0);
|
||||
this.contentContainer.Controls.SetChildIndex(this.label5, 0);
|
||||
this.contentContainer.Controls.SetChildIndex(this.SwizzleNum, 0);
|
||||
this.contentContainer.Controls.SetChildIndex(this.stLabel1, 0);
|
||||
this.contentContainer.Controls.SetChildIndex(this.compressionModeCB, 0);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
|
@ -140,7 +146,7 @@
|
|||
//
|
||||
// SwizzleNum
|
||||
//
|
||||
this.SwizzleNum.Location = new System.Drawing.Point(855, 175);
|
||||
this.SwizzleNum.Location = new System.Drawing.Point(854, 212);
|
||||
this.SwizzleNum.Name = "SwizzleNum";
|
||||
this.SwizzleNum.Size = new System.Drawing.Size(130, 20);
|
||||
this.SwizzleNum.TabIndex = 28;
|
||||
|
@ -148,7 +154,7 @@
|
|||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(759, 175);
|
||||
this.label5.Location = new System.Drawing.Point(757, 212);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(42, 13);
|
||||
this.label5.TabIndex = 27;
|
||||
|
@ -160,16 +166,16 @@
|
|||
this.tileModeCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
|
||||
this.tileModeCB.ButtonColor = System.Drawing.Color.Empty;
|
||||
this.tileModeCB.FormattingEnabled = true;
|
||||
this.tileModeCB.Location = new System.Drawing.Point(855, 102);
|
||||
this.tileModeCB.Location = new System.Drawing.Point(854, 139);
|
||||
this.tileModeCB.Name = "tileModeCB";
|
||||
this.tileModeCB.ReadOnly = true;
|
||||
this.tileModeCB.Size = new System.Drawing.Size(233, 21);
|
||||
this.tileModeCB.Size = new System.Drawing.Size(232, 21);
|
||||
this.tileModeCB.TabIndex = 26;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(759, 105);
|
||||
this.label4.Location = new System.Drawing.Point(757, 142);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(54, 13);
|
||||
this.label4.TabIndex = 25;
|
||||
|
@ -181,16 +187,16 @@
|
|||
this.ImgDimComb.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
|
||||
this.ImgDimComb.ButtonColor = System.Drawing.Color.Empty;
|
||||
this.ImgDimComb.FormattingEnabled = true;
|
||||
this.ImgDimComb.Location = new System.Drawing.Point(853, 69);
|
||||
this.ImgDimComb.Location = new System.Drawing.Point(854, 106);
|
||||
this.ImgDimComb.Name = "ImgDimComb";
|
||||
this.ImgDimComb.ReadOnly = true;
|
||||
this.ImgDimComb.Size = new System.Drawing.Size(233, 21);
|
||||
this.ImgDimComb.Size = new System.Drawing.Size(230, 21);
|
||||
this.ImgDimComb.TabIndex = 24;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(759, 72);
|
||||
this.label3.Location = new System.Drawing.Point(757, 109);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(88, 13);
|
||||
this.label3.TabIndex = 23;
|
||||
|
@ -208,7 +214,7 @@
|
|||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(759, 140);
|
||||
this.label1.Location = new System.Drawing.Point(757, 177);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(90, 13);
|
||||
this.label1.TabIndex = 21;
|
||||
|
@ -216,7 +222,7 @@
|
|||
//
|
||||
// MipmapNum
|
||||
//
|
||||
this.MipmapNum.Location = new System.Drawing.Point(855, 138);
|
||||
this.MipmapNum.Location = new System.Drawing.Point(854, 175);
|
||||
this.MipmapNum.Name = "MipmapNum";
|
||||
this.MipmapNum.Size = new System.Drawing.Size(130, 20);
|
||||
this.MipmapNum.TabIndex = 20;
|
||||
|
@ -225,7 +231,7 @@
|
|||
// WidthLabel
|
||||
//
|
||||
this.WidthLabel.AutoSize = true;
|
||||
this.WidthLabel.Location = new System.Drawing.Point(759, 243);
|
||||
this.WidthLabel.Location = new System.Drawing.Point(757, 271);
|
||||
this.WidthLabel.Name = "WidthLabel";
|
||||
this.WidthLabel.Size = new System.Drawing.Size(35, 13);
|
||||
this.WidthLabel.TabIndex = 19;
|
||||
|
@ -234,7 +240,7 @@
|
|||
// HeightLabel
|
||||
//
|
||||
this.HeightLabel.AutoSize = true;
|
||||
this.HeightLabel.Location = new System.Drawing.Point(759, 208);
|
||||
this.HeightLabel.Location = new System.Drawing.Point(757, 240);
|
||||
this.HeightLabel.Name = "HeightLabel";
|
||||
this.HeightLabel.Size = new System.Drawing.Size(38, 13);
|
||||
this.HeightLabel.TabIndex = 18;
|
||||
|
@ -265,6 +271,28 @@
|
|||
this.formatComboBox.TabIndex = 16;
|
||||
this.formatComboBox.SelectedIndexChanged += new System.EventHandler(this.formatComboBox_SelectedIndexChanged);
|
||||
//
|
||||
// compressionModeCB
|
||||
//
|
||||
this.compressionModeCB.BorderColor = System.Drawing.Color.Empty;
|
||||
this.compressionModeCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
|
||||
this.compressionModeCB.ButtonColor = System.Drawing.Color.Empty;
|
||||
this.compressionModeCB.FormattingEnabled = true;
|
||||
this.compressionModeCB.Location = new System.Drawing.Point(854, 72);
|
||||
this.compressionModeCB.Name = "compressionModeCB";
|
||||
this.compressionModeCB.ReadOnly = true;
|
||||
this.compressionModeCB.Size = new System.Drawing.Size(233, 21);
|
||||
this.compressionModeCB.TabIndex = 30;
|
||||
this.compressionModeCB.SelectedIndexChanged += new System.EventHandler(this.compressionModeCB_SelectedIndexChanged);
|
||||
//
|
||||
// stLabel1
|
||||
//
|
||||
this.stLabel1.AutoSize = true;
|
||||
this.stLabel1.Location = new System.Drawing.Point(757, 75);
|
||||
this.stLabel1.Name = "stLabel1";
|
||||
this.stLabel1.Size = new System.Drawing.Size(100, 13);
|
||||
this.stLabel1.TabIndex = 29;
|
||||
this.stLabel1.Text = "Compression Mode:";
|
||||
//
|
||||
// BinaryTextureImporterList
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -302,5 +330,7 @@
|
|||
private Switch_Toolbox.Library.Forms.STComboBox formatComboBox;
|
||||
private System.Windows.Forms.ColumnHeader Name;
|
||||
private System.Windows.Forms.ColumnHeader Format;
|
||||
private Switch_Toolbox.Library.Forms.STComboBox compressionModeCB;
|
||||
private Switch_Toolbox.Library.Forms.STLabel stLabel1;
|
||||
}
|
||||
}
|
|
@ -80,6 +80,15 @@ namespace FirstPlugin
|
|||
formatComboBox.Items.Add(SurfaceFormat.BC7_UNORM);
|
||||
formatComboBox.Items.Add(SurfaceFormat.BC7_SRGB);
|
||||
|
||||
compressionModeCB.Items.Add("Fast (Lower Qaulity)");
|
||||
compressionModeCB.Items.Add("Normal (Good Qaulity)");
|
||||
|
||||
|
||||
|
||||
compressionModeCB.SelectedIndex = 1;
|
||||
|
||||
compressionModeCB.Enabled = false;
|
||||
|
||||
foreach (SurfaceDim dim in (SurfaceDim[])Enum.GetValues(typeof(SurfaceDim)))
|
||||
{
|
||||
ImgDimComb.Items.Add(dim);
|
||||
|
@ -132,15 +141,29 @@ namespace FirstPlugin
|
|||
|
||||
listViewCustom1.Items[SelectedIndex].SubItems[1].Text = SelectedTexSettings.Format.ToString();
|
||||
}
|
||||
|
||||
if (SelectedTexSettings.Format == SurfaceFormat.BC7_UNORM ||
|
||||
SelectedTexSettings.Format == SurfaceFormat.BC7_SRGB)
|
||||
{
|
||||
compressionModeCB.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
compressionModeCB.Enabled = false;
|
||||
}
|
||||
|
||||
Bitmap bitmap = Switch_Toolbox.Library.Imaging.GetLoadingImage();
|
||||
|
||||
STCompressionMode CompressionMode = STCompressionMode.Normal;
|
||||
if (compressionModeCB.SelectedIndex == 0)
|
||||
CompressionMode = STCompressionMode.Fast;
|
||||
|
||||
Thread = new Thread((ThreadStart)(() =>
|
||||
{
|
||||
ToggleOkButton(false);
|
||||
|
||||
pictureBox1.Image = bitmap;
|
||||
SelectedTexSettings.Compress();
|
||||
SelectedTexSettings.Compress(CompressionMode);
|
||||
|
||||
ToggleOkButton(true);
|
||||
|
||||
|
@ -239,5 +262,13 @@ namespace FirstPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void compressionModeCB_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (formatComboBox.SelectedIndex > -1 && SelectedTexSettings != null)
|
||||
{
|
||||
SetupSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,13 +173,13 @@ namespace FirstPlugin
|
|||
|
||||
return Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
public void Compress()
|
||||
public void Compress(STCompressionMode CompressionMode)
|
||||
{
|
||||
DataBlockOutput.Clear();
|
||||
foreach (var surface in DecompressedData)
|
||||
{
|
||||
DataBlockOutput.Add(STGenericTexture.CompressBlock(surface,
|
||||
(int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef));
|
||||
(int)TexWidth, (int)TexHeight, TextureData.ConvertFormat(Format), alphaRef, CompressionMode));
|
||||
}
|
||||
}
|
||||
public static uint DIV_ROUND_UP(uint value1, uint value2)
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -624,6 +624,10 @@ namespace Switch_Toolbox.Library
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unknown type!");
|
||||
}
|
||||
return TEX_FORMAT.UNKNOWN;
|
||||
}
|
||||
private void ReadDX10Header(BinaryDataReader reader)
|
||||
|
@ -775,11 +779,14 @@ namespace Switch_Toolbox.Library
|
|||
uint MipWidth = tex.Width, MipHeight = tex.Height;
|
||||
for (int j = 0; j < tex.MipCount; ++j)
|
||||
{
|
||||
MipWidth = (uint)Math.Max(1, tex.Width >> j);
|
||||
MipHeight = (uint)Math.Max(1, tex.Height >> j);
|
||||
|
||||
uint size = (MipWidth * MipHeight); //Total pixels
|
||||
if (IsCompressed(tex.Format))
|
||||
{
|
||||
size = (uint)(size * ((float)formatSize / 0x10)); //Bytes per 16 pixels
|
||||
if (size < formatSize) //Make sure it's at least one block
|
||||
size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
|
||||
if (size < formatSize)
|
||||
size = formatSize;
|
||||
}
|
||||
else
|
||||
|
@ -787,8 +794,6 @@ namespace Switch_Toolbox.Library
|
|||
size = (uint)(size * GetBytesPerPixel(tex.Format)); //Bytes per pixel
|
||||
}
|
||||
|
||||
MipWidth /= 2;
|
||||
MipHeight /= 2;
|
||||
Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
|
||||
Offset += size;
|
||||
}
|
||||
|
@ -818,11 +823,14 @@ namespace Switch_Toolbox.Library
|
|||
uint MipWidth = dds.header.width, MipHeight = dds.header.height;
|
||||
for (int j = 0; j < dds.header.mipmapCount; ++j)
|
||||
{
|
||||
MipWidth = (uint)Math.Max(1, dds.header.width >> j);
|
||||
MipHeight = (uint)Math.Max(1, dds.header.height >> j);
|
||||
|
||||
uint size = (MipWidth * MipHeight); //Total pixels
|
||||
if (isBlock)
|
||||
{
|
||||
size = (uint)(size * ((float)formatSize / 0x10)); //Bytes per 16 pixels
|
||||
if (size < formatSize) //Make sure it's at least one block
|
||||
size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
|
||||
if (size < formatSize)
|
||||
size = formatSize;
|
||||
}
|
||||
else
|
||||
|
@ -830,8 +838,6 @@ namespace Switch_Toolbox.Library
|
|||
size = (uint)(size * (GetBytesPerPixel(dds.Format))); //Bytes per pixel
|
||||
}
|
||||
|
||||
MipWidth /= 2;
|
||||
MipHeight /= 2;
|
||||
Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
|
||||
Offset += size;
|
||||
}
|
||||
|
|
|
@ -436,7 +436,7 @@ namespace Switch_Toolbox.Library
|
|||
}
|
||||
return BitmapExtension.GetBitmap(Output, W * 4, H * 4);
|
||||
}
|
||||
public static unsafe byte[] CompressBlock(Byte[] data, int width, int height, DDS.DXGI_FORMAT format, float AlphaRef = 0.5f)
|
||||
public static unsafe byte[] CompressBlock(Byte[] data, int width, int height, DDS.DXGI_FORMAT format, float AlphaRef = 0.5f, STCompressionMode CompressionMode = STCompressionMode.Normal)
|
||||
{
|
||||
long inputRowPitch = width * 4;
|
||||
long inputSlicePitch = width * height * 4;
|
||||
|
@ -464,7 +464,8 @@ namespace Switch_Toolbox.Library
|
|||
format == DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB ||
|
||||
format == DDS.DXGI_FORMAT.DXGI_FORMAT_BC7_TYPELESS)
|
||||
{
|
||||
compFlags |= TEX_COMPRESS_FLAGS.BC7_QUICK;
|
||||
if (CompressionMode == STCompressionMode.Fast)
|
||||
compFlags |= TEX_COMPRESS_FLAGS.BC7_QUICK;
|
||||
}
|
||||
|
||||
if (format == DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB ||
|
||||
|
|
|
@ -18,7 +18,16 @@ namespace Switch_Toolbox.Library.Forms
|
|||
private Brush ArrowBrush = new SolidBrush(SystemColors.ControlText);
|
||||
private Brush DropButtonBrush = new SolidBrush(SystemColors.Control);
|
||||
|
||||
private Color _borderColor = Color.Black;
|
||||
private Color _borderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Enabled)
|
||||
return FormThemes.BaseTheme.ComboBoxBorderColor;
|
||||
else
|
||||
return FormThemes.BaseTheme.DisabledBorderColor;
|
||||
}
|
||||
}
|
||||
private ButtonBorderStyle _borderStyle = ButtonBorderStyle.Solid;
|
||||
private static int WM_PAINT = 0x000F;
|
||||
|
||||
|
@ -40,7 +49,6 @@ namespace Switch_Toolbox.Library.Forms
|
|||
ButtonColor = FormThemes.BaseTheme.ComboBoxBackColor;
|
||||
ForeColor = FormThemes.BaseTheme.FormForeColor;
|
||||
BackColor = FormThemes.BaseTheme.ComboBoxBackColor;
|
||||
BorderColor = FormThemes.BaseTheme.ComboBoxBorderColor;
|
||||
DropDownStyle = ComboBoxStyle.DropDown;
|
||||
|
||||
if (FormThemes.ActivePreset == FormThemes.Preset.White)
|
||||
|
@ -50,13 +58,13 @@ namespace Switch_Toolbox.Library.Forms
|
|||
|
||||
ReadOnly = true;
|
||||
|
||||
Resize += (s, e) =>
|
||||
/* Resize += (s, e) =>
|
||||
{
|
||||
if (!IsHandleCreated)
|
||||
return;
|
||||
|
||||
SelectionLength = 0;
|
||||
};
|
||||
};*/
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
@ -131,7 +139,6 @@ namespace Switch_Toolbox.Library.Forms
|
|||
get { return _borderColor; }
|
||||
set
|
||||
{
|
||||
_borderColor = value;
|
||||
Invalidate(); // causes control to be redrawn
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +154,19 @@ namespace Switch_Toolbox.Library.Forms
|
|||
}
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
var backBrush = new SolidBrush(BorderColor);
|
||||
var foreBrush = new SolidBrush(ForeColor);
|
||||
|
||||
e.Graphics.FillRectangle(backBrush, this.ClientRectangle);
|
||||
|
||||
e.Graphics.DrawString(this.Text, this.Font, foreBrush, this.Location);
|
||||
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(System.EventArgs e)
|
||||
{
|
||||
base.OnLostFocus(e);
|
||||
|
@ -174,10 +194,19 @@ namespace Switch_Toolbox.Library.Forms
|
|||
this.DropDownStyleChanged += new System.EventHandler(this.STComboBox_DropDownStyleChanged);
|
||||
this.DropDownClosed += new System.EventHandler(this.STComboBox_DropDownClosed);
|
||||
this.TextChanged += new System.EventHandler(this.STComboBox_TextChanged);
|
||||
this.EnabledChanged += new EventHandler(EnableDisplayCombo_EnabledChanged);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
void EnableDisplayCombo_EnabledChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (this.Enabled)
|
||||
this.DropDownStyle = ComboBoxStyle.DropDown;
|
||||
else
|
||||
this.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
}
|
||||
|
||||
private void STComboBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
|
|
@ -13,6 +13,13 @@ using Switch_Toolbox.Library.NodeWrappers;
|
|||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public enum STCompressionMode
|
||||
{
|
||||
Slow,
|
||||
Normal,
|
||||
Fast
|
||||
}
|
||||
|
||||
public enum STChannelType
|
||||
{
|
||||
Red = 0,
|
||||
|
@ -505,7 +512,7 @@ namespace Switch_Toolbox.Library
|
|||
return MipmapNum;
|
||||
}
|
||||
|
||||
public byte[] GenerateMipsAndCompress(Bitmap bitmap, TEX_FORMAT Format, float alphaRef = 0.5f)
|
||||
public byte[] GenerateMipsAndCompress(Bitmap bitmap, TEX_FORMAT Format, float alphaRef = 0.5f, STCompressionMode CompressionMode = STCompressionMode.Normal)
|
||||
{
|
||||
byte[] DecompressedData = BitmapExtension.ImageToByte(bitmap);
|
||||
DecompressedData = ConvertBgraToRgba(DecompressedData);
|
||||
|
@ -522,7 +529,7 @@ namespace Switch_Toolbox.Library
|
|||
{
|
||||
Image = BitmapExtension.Resize(Image, Image.Width / 2, Image.Height / 2);
|
||||
mipmaps.Add(STGenericTexture.CompressBlock(BitmapExtension.ImageToByte(Image),
|
||||
Image.Width, Image.Height, Format, alphaRef));
|
||||
Image.Width, Image.Height, Format, alphaRef, CompressionMode));
|
||||
}
|
||||
}
|
||||
Image.Dispose();
|
||||
|
@ -530,10 +537,10 @@ namespace Switch_Toolbox.Library
|
|||
return Utils.CombineByteArray(mipmaps.ToArray());
|
||||
}
|
||||
|
||||
public static byte[] CompressBlock(byte[] data, int width, int height, TEX_FORMAT format, float alphaRef)
|
||||
public static byte[] CompressBlock(byte[] data, int width, int height, TEX_FORMAT format, float alphaRef, STCompressionMode CompressionMode = STCompressionMode.Normal)
|
||||
{
|
||||
if (IsCompressed(format))
|
||||
return DDSCompressor.CompressBlock(data, width, height, (DDS.DXGI_FORMAT)format, alphaRef);
|
||||
return DDSCompressor.CompressBlock(data, width, height, (DDS.DXGI_FORMAT)format, alphaRef, CompressionMode);
|
||||
else if (IsAtscFormat(format))
|
||||
return null;
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue