1
0
mirror of synced 2024-11-12 02:00:50 +01:00

More image editor improvements

Array textures can be exported to DDS.
Specific channels can be edited.
Uncompressed formats for dds greatly improved.
Array textures can be exported from non dds formats as multiple images.
This commit is contained in:
KillzXGaming 2019-05-14 15:12:26 -04:00
parent 55702ff401
commit f2439f2fdc
25 changed files with 410 additions and 51 deletions

Binary file not shown.

View File

@ -270,8 +270,10 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1096, 560);
this.KeyPreview = true;
this.Text = "Texture Importer";
this.Load += new System.EventHandler(this.BinaryTextureImporterList_Load);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.BinaryTextureImporterList_KeyDown);
this.contentContainer.ResumeLayout(false);
this.contentContainer.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.SwizzleNum)).EndInit();

View File

@ -88,6 +88,8 @@ namespace FirstPlugin
ImgDimComb.SelectedIndex = 1;
tileModeCB.SelectedIndex = 0;
formatComboBox.SelectedItem = SurfaceFormat.BC1_SRGB;
button1.Select();
}
TextureImporterSettings SelectedTexSettings;
@ -226,5 +228,18 @@ namespace FirstPlugin
else
SelectedTexSettings.MipCount = 1;
}
private void BinaryTextureImporterList_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (button1.Enabled)
{
DialogResult = DialogResult.OK;
}
}
}
}
}

View File

@ -23,7 +23,6 @@ namespace FirstPlugin
}
public string TexName;
public uint arrayLength = 1;
public uint AccessFlags = 0x20;
public uint MipCount;
public uint Depth = 1;
@ -68,16 +67,11 @@ namespace FirstPlugin
MipCount = dds.header.mipmapCount;
TexWidth = dds.header.width;
TexHeight = dds.header.height;
arrayLength = 1;
if (dds.header.caps2 == (uint)DDS.DDSCAPS2.CUBEMAP_ALLFACES)
{
arrayLength = 6;
}
foreach (var array in DDS.GetArrayFacesBytes(dds.bdata, (int)arrayLength))
{
DataBlockOutput.Add(array);
}
var surfaces = DDS.GetArrayFaces(dds, dds.bdata, dds.ArrayCount);
foreach (var surface in surfaces)
DataBlockOutput.Add(Utils.CombineByteArray(surface.mipmaps.ToArray()));
Format = TextureData.GenericToBntxSurfaceFormat(dds.Format);
}
@ -234,7 +228,6 @@ namespace FirstPlugin
tex.sparseBinding = settings.sparseBinding;
tex.sparseResidency = settings.sparseResidency;
tex.AccessFlags = settings.AccessFlags;
tex.ArrayLength = settings.arrayLength;
tex.MipCount = settings.MipCount;
tex.Depth = settings.Depth;
tex.Dim = settings.Dim;

View File

@ -136,7 +136,7 @@ namespace FirstPlugin
// Formats.Add(typeof(NCA));
// Formats.Add(typeof(XCI));
// Formats.Add(typeof(NSP));
Formats.Add(typeof(NSP));
Formats.Add(typeof(BFSAR));
Formats.Add(typeof(BNSH));
Formats.Add(typeof(BFSHA));

View File

@ -490,6 +490,13 @@ namespace Switch_Toolbox.Library
header.caps4 = reader.ReadUInt32();
header.reserved2 = reader.ReadUInt32();
ArrayCount = 1;
if (header.caps2 == (uint)DDS.DDSCAPS2.CUBEMAP_ALLFACES)
{
ArrayCount = 6;
}
int DX10HeaderSize = 0;
if (header.ddspf.fourCC == FOURCC_DX10)
{
@ -537,7 +544,6 @@ namespace Switch_Toolbox.Library
reader.Close();
ArrayCount = 1;
MipCount = header.mipmapCount;
Width = header.width;
Height = header.height;
@ -587,7 +593,7 @@ namespace Switch_Toolbox.Library
{
if (RedMask == R8G8B8_MASKS[0] && GreenMask == R8G8B8_MASKS[1] && BlueMask == R8G8B8_MASKS[2] && AlphaMask == R8G8B8_MASKS[3])
{
return TEX_FORMAT.R8G8_B8G8_UNORM;
return TEX_FORMAT.R8G8B8A8_UNORM;
}
else
{
@ -602,7 +608,7 @@ namespace Switch_Toolbox.Library
}
else if (RedMask == X8B8G8R8_MASKS[0] && GreenMask == X8B8G8R8_MASKS[1] && BlueMask == X8B8G8R8_MASKS[2] && AlphaMask == X8B8G8R8_MASKS[3])
{
return TEX_FORMAT.R8G8_B8G8_UNORM;
return TEX_FORMAT.B8G8R8X8_UNORM;
}
else if (RedMask == A8R8G8B8_MASKS[0] && GreenMask == A8R8G8B8_MASKS[1] && BlueMask == A8R8G8B8_MASKS[2] && AlphaMask == A8R8G8B8_MASKS[3])
{
@ -610,7 +616,7 @@ namespace Switch_Toolbox.Library
}
else if (RedMask == X8R8G8B8_MASKS[0] && GreenMask == X8R8G8B8_MASKS[1] && BlueMask == X8R8G8B8_MASKS[2] && AlphaMask == X8R8G8B8_MASKS[3])
{
return TEX_FORMAT.R8G8_B8G8_UNORM;
return TEX_FORMAT.B8G8R8X8_UNORM;
}
else
{
@ -628,6 +634,8 @@ namespace Switch_Toolbox.Library
DX10header.miscFlag = reader.ReadUInt32();
DX10header.arrayFlag = reader.ReadUInt32();
DX10header.miscFlags2 = reader.ReadUInt32();
ArrayCount = DX10header.arrayFlag;
}
public bool Swizzle = false;
@ -636,7 +644,7 @@ namespace Switch_Toolbox.Library
if (Swizzle)
return TegraX1Swizzle.GetImageData(this, bdata, ArrayLevel, MipLevel);
return GetArrayFaces(this, 1)[ArrayLevel].mipmaps[MipLevel];
return GetArrayFaces(this, ArrayCount)[ArrayLevel].mipmaps[MipLevel];
}
public override void SetImageData(Bitmap bitmap, int ArrayLevel)
@ -818,13 +826,25 @@ namespace Switch_Toolbox.Library
return TEX_FORMAT.R8G8B8A8_UNORM;
}
}
public void SetFlags(DXGI_FORMAT Format)
public void SetFlags(DXGI_FORMAT Format, bool UseDX10 = false)
{
header.flags = (uint)(DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT | DDSD.MIPMAPCOUNT | DDSD.LINEARSIZE);
header.caps = (uint)DDSCAPS.TEXTURE;
if (header.mipmapCount > 1)
header.caps |= (uint)(DDSCAPS.COMPLEX | DDSCAPS.MIPMAP);
if (UseDX10)
{
header.ddspf.flags = (uint)DDPF.FOURCC;
header.ddspf.fourCC = FOURCC_DX10;
if (DX10header == null)
DX10header = new DX10Header();
IsDX10 = true;
DX10header.DXGI_Format = Format;
return;
}
switch (Format)
{
case DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM:

View File

@ -42,24 +42,25 @@
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(114, 9);
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(79, 13);
this.label1.Size = new System.Drawing.Size(287, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Loaidng File.....";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ProgressBar
// STProgressBar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(311, 82);
this.Controls.Add(this.label1);
this.Controls.Add(this.progressBar1);
this.Name = "ProgressBar";
this.Name = "STProgressBar";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ProgressBar_FormClosed);
this.ResumeLayout(false);
this.PerformLayout();
}

View File

@ -58,6 +58,11 @@
this.fillColorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.undoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.redoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.channelsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.replacRedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.replaceGreenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.replaceBlueToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.replaceAlphaToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editInExternalProgramToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -360,6 +365,7 @@
this.fillColorToolStripMenuItem,
this.undoToolStripMenuItem,
this.redoToolStripMenuItem,
this.channelsToolStripMenuItem,
this.editInExternalProgramToolStripMenuItem,
this.copyToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
@ -387,6 +393,45 @@
this.redoToolStripMenuItem.Text = "Redo";
this.redoToolStripMenuItem.Click += new System.EventHandler(this.redoToolStripMenuItem_Click);
//
// channelsToolStripMenuItem
//
this.channelsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.replacRedToolStripMenuItem,
this.replaceGreenToolStripMenuItem,
this.replaceBlueToolStripMenuItem,
this.replaceAlphaToolStripMenuItem});
this.channelsToolStripMenuItem.Name = "channelsToolStripMenuItem";
this.channelsToolStripMenuItem.Size = new System.Drawing.Size(192, 22);
this.channelsToolStripMenuItem.Text = "Channels";
//
// replacRedToolStripMenuItem
//
this.replacRedToolStripMenuItem.Name = "replacRedToolStripMenuItem";
this.replacRedToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.replacRedToolStripMenuItem.Text = "Replace Red";
this.replacRedToolStripMenuItem.Click += new System.EventHandler(this.replacRedToolStripMenuItem_Click);
//
// replaceGreenToolStripMenuItem
//
this.replaceGreenToolStripMenuItem.Name = "replaceGreenToolStripMenuItem";
this.replaceGreenToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.replaceGreenToolStripMenuItem.Text = "Replace Green";
this.replaceGreenToolStripMenuItem.Click += new System.EventHandler(this.replaceGreenToolStripMenuItem_Click);
//
// replaceBlueToolStripMenuItem
//
this.replaceBlueToolStripMenuItem.Name = "replaceBlueToolStripMenuItem";
this.replaceBlueToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.replaceBlueToolStripMenuItem.Text = "Replace Blue";
this.replaceBlueToolStripMenuItem.Click += new System.EventHandler(this.replaceBlueToolStripMenuItem_Click);
//
// replaceAlphaToolStripMenuItem
//
this.replaceAlphaToolStripMenuItem.Name = "replaceAlphaToolStripMenuItem";
this.replaceAlphaToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.replaceAlphaToolStripMenuItem.Text = "Replace Alpha";
this.replaceAlphaToolStripMenuItem.Click += new System.EventHandler(this.replaceAlphaToolStripMenuItem_Click);
//
// editInExternalProgramToolStripMenuItem
//
this.editInExternalProgramToolStripMenuItem.Name = "editInExternalProgramToolStripMenuItem";
@ -621,5 +666,10 @@
private STPanel stPanel5;
private STLabel bottomLabel;
private System.Windows.Forms.ToolStripMenuItem fillColorToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem channelsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem replacRedToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem replaceGreenToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem replaceBlueToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem replaceAlphaToolStripMenuItem;
}
}

View File

@ -333,6 +333,8 @@ namespace Switch_Toolbox.Library.Forms
}
public Image BaseImage;
private void UpdatePictureBox(int ChannelIndex = 0)
{
if (ActiveTexture == null)
@ -344,6 +346,9 @@ namespace Switch_Toolbox.Library.Forms
var image = ActiveTexture.GetBitmap(CurArrayDisplayLevel, CurMipDisplayLevel);
//Keep base image for channel viewer updating/editing
BaseImage = new Bitmap(image);
if (propertiesEditor.InvokeRequired)
{
propertiesEditor.Invoke(new MethodInvoker(
@ -695,6 +700,7 @@ namespace Switch_Toolbox.Library.Forms
mipLevelCounterLabel.Text = $"Mip Level: {CurMipDisplayLevel} / {TotalMipCount}";
propertiesEditor.UpdateProperties();
propertiesEditor.LoadImage(new Bitmap(image), this);
HasBeenEdited = true;
}
@ -758,6 +764,8 @@ namespace Switch_Toolbox.Library.Forms
}
}
public Image GetActiveImage() => pictureBoxCustom1.Image;
private void hueToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!IsFinished)
@ -990,7 +998,7 @@ namespace Switch_Toolbox.Library.Forms
}
}
private void SaveAndApplyImage(Bitmap image, bool DecodeBack)
public void SaveAndApplyImage(Bitmap image, bool DecodeBack)
{
if (saveBtn.InvokeRequired)
{
@ -1220,5 +1228,21 @@ namespace Switch_Toolbox.Library.Forms
ApplyEdit(newImage);
}
}
private void replacRedToolStripMenuItem_Click(object sender, EventArgs e) {
propertiesEditor.EditChannel(STChannelType.Red);
}
private void replaceGreenToolStripMenuItem_Click(object sender, EventArgs e) {
propertiesEditor.EditChannel(STChannelType.Green);
}
private void replaceBlueToolStripMenuItem_Click(object sender, EventArgs e) {
propertiesEditor.EditChannel(STChannelType.Blue);
}
private void replaceAlphaToolStripMenuItem_Click(object sender, EventArgs e) {
propertiesEditor.EditChannel(STChannelType.Alpha);
}
}
}

View File

@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>351, 17</value>
</metadata>
<metadata name="stContextMenuStrip2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>184, 17</value>
</metadata>
@ -172,9 +178,6 @@
gg==
</value>
</data>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>351, 17</value>
</metadata>
<data name="editBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6
@ -736,9 +739,6 @@
cL+T0fIXUvho1xJo195FiqmQ0PIqcY9VOy9ppv/4j/8PQJ1wavHnTdQAAAAASUVORK5CYII=
</value>
</data>
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>108</value>
</metadata>

View File

@ -28,15 +28,19 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.channelListView = new Switch_Toolbox.Library.Forms.ListViewCustom();
this.ChannelsColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.stTabControl1 = new Switch_Toolbox.Library.Forms.STTabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.stPropertyGrid1 = new Switch_Toolbox.Library.Forms.STPropertyGrid();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.stChannelToolstripMenu = new Switch_Toolbox.Library.Forms.STContextMenuStrip(this.components);
this.replaceChannelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stTabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage1.SuspendLayout();
this.stChannelToolstripMenu.SuspendLayout();
this.SuspendLayout();
//
// channelListView
@ -53,6 +57,7 @@
this.channelListView.UseCompatibleStateImageBehavior = false;
this.channelListView.View = System.Windows.Forms.View.Details;
this.channelListView.SelectedIndexChanged += new System.EventHandler(this.channelListView_SelectedIndexChanged);
this.channelListView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.channelListView_MouseClick);
//
// ChannelsColumn
//
@ -71,17 +76,6 @@
this.stTabControl1.Size = new System.Drawing.Size(233, 543);
this.stTabControl1.TabIndex = 1;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.channelListView);
this.tabPage1.Location = new System.Drawing.Point(4, 25);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(225, 514);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Channels";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.stPropertyGrid1);
@ -100,9 +94,35 @@
this.stPropertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPropertyGrid1.Location = new System.Drawing.Point(3, 3);
this.stPropertyGrid1.Name = "stPropertyGrid1";
this.stPropertyGrid1.ShowHintDisplay = true;
this.stPropertyGrid1.Size = new System.Drawing.Size(219, 508);
this.stPropertyGrid1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.channelListView);
this.tabPage1.Location = new System.Drawing.Point(4, 25);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(225, 514);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Channels";
this.tabPage1.UseVisualStyleBackColor = true;
//
// stChannelToolstripMenu
//
this.stChannelToolstripMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.replaceChannelToolStripMenuItem});
this.stChannelToolstripMenu.Name = "stChannelToolstripMenu";
this.stChannelToolstripMenu.Size = new System.Drawing.Size(181, 48);
//
// replaceChannelToolStripMenuItem
//
this.replaceChannelToolStripMenuItem.Name = "replaceChannelToolStripMenuItem";
this.replaceChannelToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.replaceChannelToolStripMenuItem.Text = "Replace Channel";
this.replaceChannelToolStripMenuItem.Click += new System.EventHandler(this.replaceChannelToolStripMenuItem_Click);
//
// ImagePropertiesEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -111,8 +131,9 @@
this.Name = "ImagePropertiesEditor";
this.Size = new System.Drawing.Size(233, 543);
this.stTabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.stChannelToolstripMenu.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -125,5 +146,7 @@
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.ColumnHeader ChannelsColumn;
private STPropertyGrid stPropertyGrid1;
private STContextMenuStrip stChannelToolstripMenu;
private System.Windows.Forms.ToolStripMenuItem replaceChannelToolStripMenuItem;
}
}

View File

@ -222,6 +222,21 @@ namespace Switch_Toolbox.Library.Forms
}
public void EditChannel(STChannelType ChannelType)
{
var Image = imageEditor.BaseImage;
if (Image != null)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
Bitmap ChannelDest = new Bitmap(ofd.FileName);
Bitmap newImage = BitmapExtension.ReplaceChannel(Image, ChannelDest, ChannelType);
imageEditor.SaveAndApplyImage(newImage, true);
}
}
}
private void tabPage2_Click(object sender, EventArgs e)
{
@ -234,5 +249,42 @@ namespace Switch_Toolbox.Library.Forms
imageEditor.UpdateMipDisplay();
}
}
private void channelListView_MouseClick(object sender, MouseEventArgs e)
{
if (channelListView.SelectedItems.Count <= 0)
return;
switch (e.Button)
{
case MouseButtons.Right:
{
Point p = new Point(e.X, e.Y);
stChannelToolstripMenu.Show(channelListView, p);
}
break;
}
}
private void replaceChannelToolStripMenuItem_Click(object sender, EventArgs e)
{
//Note first index (0) is RGBA display
int ChannelIndex = channelListView.SelectedIndices[0];
switch (ChannelIndex)
{
case 1:
EditChannel(STChannelType.Red);
break;
case 2:
EditChannel(STChannelType.Green);
break;
case 3:
EditChannel(STChannelType.Blue);
break;
case 4:
EditChannel(STChannelType.Alpha);
break;
}
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="stChannelToolstripMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -192,7 +192,10 @@ namespace Switch_Toolbox.Library
{ TEX_FORMAT.R8G8B8A8_UNORM, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.R8G8B8A8_UNORM_SRGB, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.R32G8X24_FLOAT, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.R8G8_B8G8_UNORM, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.B8G8R8X8_UNORM, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.B5G5R5A1_UNORM, new FormatInfo(2, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.R10G10B10A2_UINT, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.R10G10B10A2_UNORM, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
{ TEX_FORMAT.R32_SINT, new FormatInfo(4, 1, 1, 1, TargetBuffer.Color) },
@ -615,9 +618,54 @@ namespace Switch_Toolbox.Library
}
public void SaveBitMap(string FileName, int SurfaceLevel = 0, int MipLevel = 0)
{
STProgressBar progressBar = new STProgressBar();
progressBar.Task = "Exporting Image Data...";
progressBar.Value = 0;
progressBar.StartPosition = FormStartPosition.CenterScreen;
progressBar.Show();
progressBar.Refresh();
if (ArrayCount > 1)
{
progressBar.Task = "Select dialog option... ";
var result = MessageBox.Show("Multiple image surfaces found! Would you like to export them all?", "Image Exporter",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
string ext = Path.GetExtension(FileName);
int index = FileName.LastIndexOf('.');
string name = index == -1 ? FileName : FileName.Substring(0, index);
for (int i = 0; i < ArrayCount; i++)
{
progressBar.Task = $"Decoding Surface [{i}] for image {Text}... ";
progressBar.Value = (i * 100) / (int)ArrayCount;
progressBar.Refresh();
Bitmap arrayBitMap = GetBitmap(i, 0);
arrayBitMap.Save($"{name}_Slice_{i}_{ext}");
arrayBitMap.Dispose();
}
progressBar.Value = 100;
progressBar.Close();
return;
}
}
progressBar.Task = $"Decoding image {Text}... ";
progressBar.Value = 20;
progressBar.Refresh();
Bitmap bitMap = GetBitmap(SurfaceLevel, MipLevel);
bitMap.Save(FileName);
bitMap.Dispose();
progressBar.Value = 100;
progressBar.Close();
}
public void SaveDDS(string FileName, int SurfaceLevel = 0, int MipLevel = 0)
{
@ -634,8 +682,8 @@ namespace Switch_Toolbox.Library
dds.header.mipmapCount = (uint)MipCount;
dds.header.pitchOrLinearSize = (uint)surfaces[0].mipmaps[0].Length;
if (surfaces.Count > 0)
dds.SetFlags((DDS.DXGI_FORMAT)Format);
if (surfaces.Count > 0) //Use DX10 format for array surfaces as it can do custom amounts
dds.SetFlags((DDS.DXGI_FORMAT)Format, true);
else
dds.SetFlags((DDS.DXGI_FORMAT)Format);

View File

@ -210,6 +210,7 @@ namespace Switch_Toolbox.Library.IO
}
}
}
public class Type_LZ4F
{
public static byte[] Decompress(byte[] data)

View File

@ -48,6 +48,85 @@ namespace Switch_Toolbox.Library
// return new Bitmap(original, new Size(width, height));
}
public static Bitmap ReplaceChannel(Image OriginalImage, Image ChannelImage, STChannelType ChannelType)
{
Bitmap b = new Bitmap(OriginalImage);
Bitmap c = new Bitmap(ChannelImage, new Size(b.Width, b.Height)); //Force to be same size
c = GrayScale(c); //Convert to grayscale
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
BitmapData cmData = c.LockBits(new Rectangle(0, 0, c.Width, c.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int cstride = cmData.Stride;
System.IntPtr cScan0 = cmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
byte* channelPointer = (byte*)(void*)cScan0;
int nOffset = stride - b.Width * 4;
byte red, green, blue, alpha;
for (int y = 0; y < b.Height; ++y)
{
for (int x = 0; x < b.Width; ++x)
{
blue = p[0];
green = p[1];
red = p[2];
alpha = p[3];
if (ChannelType == STChannelType.Red)
{
p[2] = channelPointer[2];
p[1] = green;
p[0] = blue;
p[3] = alpha;
}
else if (ChannelType == STChannelType.Green)
{
p[2] = red;
p[1] = channelPointer[2];
p[0] = blue;
p[3] = alpha;
}
else if (ChannelType == STChannelType.Blue)
{
p[2] = red;
p[1] = green;
p[0] = channelPointer[2];
p[3] = alpha;
}
else if (ChannelType == STChannelType.Alpha)
{
p[2] = red;
p[1] = green;
p[0] = blue;
p[3] = channelPointer[2];
}
p += 4;
channelPointer += 4;
}
p += nOffset;
channelPointer += nOffset;
}
}
b.UnlockBits(bmData);
c.UnlockBits(cmData);
return b;
}
public static Bitmap SwapBlueRedChannels(Image image)
{
Bitmap b = new Bitmap(image);

View File

@ -10,6 +10,17 @@ namespace Switch_Toolbox.Library
{
public class Utils
{
public static byte[] CreateMD5Hash(string filename)
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
return md5.ComputeHash(stream);
}
}
}
public static bool HasInterface(Type objectType, Type interfaceType)
{
foreach (var inter in objectType.GetInterfaces())

Binary file not shown.

View File

@ -433,6 +433,9 @@
<None Include="Resources\Save.png" />
<None Include="Resources\UpdateIcon.png" />
<Content Include="Switch_Toolbox.csproj.user" />
<Content Include="System.Numerics.Vectors.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Tool.ico" />
<None Include="Resources\Logo.png" />
<Content Include="Version.txt">

View File

@ -14,10 +14,12 @@ namespace Toolbox
{
static Release[] releases;
public static bool CanUpdate = false;
public static bool Downloaded = false;
public static Release LatestRelease;
public static List<GitHubCommit> CommitList = new List<GitHubCommit>();
public static DateTime LatestReleaseTime;
public static void CheckLatest()
{
try
@ -37,9 +39,16 @@ namespace Toolbox
if (Runtime.CompileDate != latest.Assets[0].UpdatedAt.ToString())
{
LatestReleaseTime = latest.Assets[0].UpdatedAt.DateTime;
CanUpdate = true;
LatestRelease = latest;
DownloadRelease();
if (CanUpdate)
{
LatestReleaseTime = latest.Assets[0].UpdatedAt.DateTime;
LatestRelease = latest;
}
else
{
}
}
break;
}
@ -49,6 +58,31 @@ namespace Toolbox
Console.WriteLine($"Failed to get latest update\n{ex.ToString()}");
}
}
static void DownloadRelease()
{
ProcessStartInfo p = new ProcessStartInfo();
p.WindowStyle = ProcessWindowStyle.Hidden;
p.CreateNoWindow = true;
p.FileName = Path.Combine(Runtime.ExecutableDir, "Updater.exe");
p.WorkingDirectory = Path.Combine(Runtime.ExecutableDir, "updater/");
Console.WriteLine($"Updater: {p.FileName}");
p.Arguments = "-d";
Process process = new Process();
process.StartInfo = p;
Console.WriteLine("Downloading...");
process.Start();
process.WaitForExit();
if (process.ExitCode != 0)
throw new TimeoutException();
Console.WriteLine("Finished downloading");
string updateExe = Path.Combine(Runtime.ExecutableDir, "master\\Toolbox.exe"),
currentExe = System.Reflection.Assembly.GetEntryAssembly().Location;
if (!Utils.CreateMD5Hash(currentExe).SequenceEqual(Utils.CreateMD5Hash(updateExe)))
CanUpdate = true;
}
static async Task GetCommits(GitHubClient client)
{
var options = new ApiOptions