1
0
mirror of synced 2024-12-01 02:27:22 +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.ReadInt16();
Console.WriteLine("Format " + Format);
Console.WriteLine("texFormat " + (Decode_Gamecube.TextureFormats)texFormat);
Console.WriteLine($"paletteOffset {paletteOffset} paletteEntryCount {paletteEntryCount} paletteFormat {paletteFormat}");
MipCount = reader.ReadByte();
reader.ReadByte();
short LODBias = reader.ReadInt16();
@ -110,7 +105,6 @@ namespace FirstPlugin
reader.SeekBegin(paletteOffset);
byte[] PaletteData = reader.ReadBytes((int)paletteEntryCount * 2);
SetPaletteData(PaletteData, Decode_Gamecube.ToGenericPaletteFormat(paletteFormat));
}
}

View File

@ -18,8 +18,10 @@ using OpenTK.Graphics.OpenGL;
namespace Toolbox.Library
{
//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 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
{
get
@ -66,6 +88,7 @@ namespace Toolbox.Library
{
IsActive = true;
CanSave = true;
CanReplace = true;
FileReader reader = new FileReader(stream);
reader.ByteOrder = ByteOrder.LittleEndian;
@ -421,24 +444,6 @@ namespace Toolbox.Library
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
{
@ -462,6 +467,8 @@ namespace Toolbox.Library
}
public void Load(BinaryDataReader reader)
{
Text = FileName;
reader.Seek(0);
string Magic = reader.ReadString(4);
Console.WriteLine(Magic);
@ -1026,6 +1033,7 @@ namespace Toolbox.Library
return Surfaces;
}
}
public TEX_FORMAT GetFormat()
{
if (DX10header != null)
@ -1187,6 +1195,7 @@ namespace Toolbox.Library
}
}
}
public void Save(DDS dds, string FileName, List<Surface> data = null)
{
FileWriter writer = new FileWriter(new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write));
@ -1237,6 +1246,7 @@ namespace Toolbox.Library
writer.Close();
writer.Dispose();
}
private void WriteDX10Header(BinaryDataWriter writer)
{
if (DX10header == null)
@ -1248,12 +1258,75 @@ namespace Toolbox.Library
writer.Write(DX10header.arrayFlag);
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)
{
byte[] image = new byte[0];
return image;
}
public static void ToRGBA(byte[] data, int Width, int Height, int bpp, int compSel)
{
int Size = Width * Height * 4;
@ -1268,8 +1341,6 @@ namespace Toolbox.Library
int pos_ = (Y * Width + X) * 4;
int pixel = 0;
}
}
}

View File

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

View File

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

View File

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