1
0
mirror of synced 2024-12-02 19:17:24 +01:00

Support DDS editing

This commit is contained in:
KillzXGaming 2019-08-05 21:30:47 -04:00
parent 714be7d126
commit 3ee6cd887a
8 changed files with 95 additions and 32 deletions

Binary file not shown.

View File

@ -89,11 +89,6 @@ namespace FirstPlugin
reader.ReadByte(); // mag filter type reader.ReadByte(); // mag filter type
reader.ReadInt16(); reader.ReadInt16();
Console.WriteLine("Format " + Format);
Console.WriteLine("texFormat " + (Decode_Gamecube.TextureFormats)texFormat);
Console.WriteLine($"paletteOffset {paletteOffset} paletteEntryCount {paletteEntryCount} paletteFormat {paletteFormat}");
MipCount = reader.ReadByte(); MipCount = reader.ReadByte();
reader.ReadByte(); reader.ReadByte();
short LODBias = reader.ReadInt16(); short LODBias = reader.ReadInt16();
@ -110,7 +105,6 @@ namespace FirstPlugin
reader.SeekBegin(paletteOffset); reader.SeekBegin(paletteOffset);
byte[] PaletteData = reader.ReadBytes((int)paletteEntryCount * 2); byte[] PaletteData = reader.ReadBytes((int)paletteEntryCount * 2);
SetPaletteData(PaletteData, Decode_Gamecube.ToGenericPaletteFormat(paletteFormat)); SetPaletteData(PaletteData, Decode_Gamecube.ToGenericPaletteFormat(paletteFormat));
} }
} }

View File

@ -18,8 +18,10 @@ using OpenTK.Graphics.OpenGL;
namespace Toolbox.Library namespace Toolbox.Library
{ {
//Data from https://github.com/jam1garner/Smash-Forge/blob/master/Smash%20Forge/Filetypes/Textures/DDS.cs //Data from https://github.com/jam1garner/Smash-Forge/blob/master/Smash%20Forge/Filetypes/Textures/DDS.cs
public class DDS : STGenericTexture, IEditor<ImageEditorBase>, IFileFormat public class DDS : STGenericTexture, IFileFormat, ISingleTextureIconLoader, IContextMenuNode
{ {
public STGenericTexture IconTexture { get { return this; } }
public FileType FileType { get; set; } = FileType.Image; public FileType FileType { get; set; } = FileType.Image;
public override TEX_FORMAT[] SupportedFormats public override TEX_FORMAT[] SupportedFormats
@ -53,6 +55,26 @@ namespace Toolbox.Library
} }
} }
public ToolStripItem[] GetContextMenuItems()
{
List<ToolStripItem> Items = new List<ToolStripItem>();
Items.Add(new ToolStripMenuItem("Save", null, SaveAction, Keys.Control | Keys.S));
Items.AddRange(base.GetContextMenuItems());
return Items.ToArray();
}
private void SaveAction(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(this);
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
STFileSaver.SaveFileFormat(this, sfd.FileName);
}
}
public Type[] Types public Type[] Types
{ {
get get
@ -66,6 +88,7 @@ namespace Toolbox.Library
{ {
IsActive = true; IsActive = true;
CanSave = true; CanSave = true;
CanReplace = true;
FileReader reader = new FileReader(stream); FileReader reader = new FileReader(stream);
reader.ByteOrder = ByteOrder.LittleEndian; reader.ByteOrder = ByteOrder.LittleEndian;
@ -421,24 +444,6 @@ namespace Toolbox.Library
DXGI_FORMAT_FORCE_UINT = 0xFFFFFFFF DXGI_FORMAT_FORCE_UINT = 0xFFFFFFFF
} }
public ImageEditorBase OpenForm()
{
bool IsDialog = IFileInfo != null && IFileInfo.InArchive;
ImageEditorBase form = new ImageEditorBase();
form.Text = Text;
form.Dock = DockStyle.Fill;
form.LoadImage(this);
form.LoadProperties(GenericProperties);
return form;
}
public void FillEditor(UserControl control)
{
((ImageEditorBase)control).LoadImage(this);
((ImageEditorBase)control).LoadProperties(GenericProperties);
}
public enum DXGI_ASTC_FORMAT public enum DXGI_ASTC_FORMAT
{ {
@ -462,6 +467,8 @@ namespace Toolbox.Library
} }
public void Load(BinaryDataReader reader) public void Load(BinaryDataReader reader)
{ {
Text = FileName;
reader.Seek(0); reader.Seek(0);
string Magic = reader.ReadString(4); string Magic = reader.ReadString(4);
Console.WriteLine(Magic); Console.WriteLine(Magic);
@ -1026,6 +1033,7 @@ namespace Toolbox.Library
return Surfaces; return Surfaces;
} }
} }
public TEX_FORMAT GetFormat() public TEX_FORMAT GetFormat()
{ {
if (DX10header != null) if (DX10header != null)
@ -1187,6 +1195,7 @@ namespace Toolbox.Library
} }
} }
} }
public void Save(DDS dds, string FileName, List<Surface> data = null) public void Save(DDS dds, string FileName, List<Surface> data = null)
{ {
FileWriter writer = new FileWriter(new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write)); FileWriter writer = new FileWriter(new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write));
@ -1237,6 +1246,7 @@ namespace Toolbox.Library
writer.Close(); writer.Close();
writer.Dispose(); writer.Dispose();
} }
private void WriteDX10Header(BinaryDataWriter writer) private void WriteDX10Header(BinaryDataWriter writer)
{ {
if (DX10header == null) if (DX10header == null)
@ -1248,12 +1258,75 @@ namespace Toolbox.Library
writer.Write(DX10header.arrayFlag); writer.Write(DX10header.arrayFlag);
writer.Write(DX10header.miscFlags2); writer.Write(DX10header.miscFlags2);
} }
public override void Replace(string FileName)
{
GenericTextureImporterList importer = new GenericTextureImporterList(SupportedFormats);
GenericTextureImporterSettings settings = new GenericTextureImporterSettings();
importer.LoadSettings(new List<GenericTextureImporterSettings>() { settings, });
if (Utils.GetExtension(FileName) == ".dds" ||
Utils.GetExtension(FileName) == ".dds2")
{
settings.LoadDDS(FileName);
ApplySettings(settings);
UpdateEditor();
}
else
{
settings.LoadBitMap(FileName);
if (importer.ShowDialog() == DialogResult.OK)
{
if (settings.GenerateMipmaps && !settings.IsFinishedCompressing)
{
settings.DataBlockOutput.Clear();
settings.DataBlockOutput.Add(settings.GenerateMips(importer.CompressionMode));
}
ApplySettings(settings);
UpdateEditor();
}
}
}
public override void OnClick(TreeView treeView) {
UpdateEditor();
}
private void UpdateEditor()
{
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
if (editor == null)
{
editor = new ImageEditorBase();
editor.Dock = DockStyle.Fill;
LibraryGUI.LoadEditor(editor);
}
editor.LoadProperties(GenericProperties);
editor.LoadImage(this);
}
private void ApplySettings(GenericTextureImporterSettings settings)
{
//Combine all arrays
this.bdata = Utils.CombineByteArray( settings.DataBlockOutput.ToArray());
this.Width = settings.TexWidth;
this.Height = settings.TexHeight;
this.Format = settings.Format;
this.MipCount = settings.MipCount;
this.Depth = settings.Depth;
this.ArrayCount = (uint)settings.DataBlockOutput.Count;
}
public static byte[] CompressBC1Block(byte[] data, int Width, int Height) public static byte[] CompressBC1Block(byte[] data, int Width, int Height)
{ {
byte[] image = new byte[0]; byte[] image = new byte[0];
return image; return image;
} }
public static void ToRGBA(byte[] data, int Width, int Height, int bpp, int compSel) public static void ToRGBA(byte[] data, int Width, int Height, int bpp, int compSel)
{ {
int Size = Width * Height * 4; int Size = Width * Height * 4;
@ -1268,8 +1341,6 @@ namespace Toolbox.Library
int pos_ = (Y * Width + X) * 4; int pos_ = (Y * Width + X) * 4;
int pixel = 0; int pixel = 0;
} }
} }
} }

View File

@ -1,4 +1,4 @@
namespace FirstPlugin namespace Toolbox.Library.Forms
{ {
partial class GenericTextureImporterList partial class GenericTextureImporterList
{ {

View File

@ -7,10 +7,8 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using Toolbox.Library;
using Toolbox.Library.Forms;
namespace FirstPlugin namespace Toolbox.Library.Forms
{ {
public partial class GenericTextureImporterList : STForm public partial class GenericTextureImporterList : STForm
{ {

View File

@ -7,7 +7,7 @@ using System.Linq;
using Toolbox.Library; using Toolbox.Library;
using Toolbox.Library.IO; using Toolbox.Library.IO;
namespace FirstPlugin namespace Toolbox.Library.Forms
{ {
public class GenericTextureImporterSettings public class GenericTextureImporterSettings
{ {