From ceb5da4d619cc89660e248cd27fdb070cc31af36 Mon Sep 17 00:00:00 2001 From: heavycube4u Date: Fri, 4 Oct 2024 21:59:06 +0000 Subject: [PATCH] revert 7dc853603972d523d52ddadd615f1052c499126e revert Upload files to "VTFXUtil" --- VTFXUtil/Form2.Designer.cs | 340 ------------------------------ VTFXUtil/Form2.resx | 123 ----------- VTFXUtil/Formats.cs | 50 ----- VTFXUtil/ImageImportProperties.cs | 36 ---- VTFXUtil/ImageImporter.cs | 269 ----------------------- 5 files changed, 818 deletions(-) delete mode 100644 VTFXUtil/Form2.Designer.cs delete mode 100644 VTFXUtil/Form2.resx delete mode 100644 VTFXUtil/Formats.cs delete mode 100644 VTFXUtil/ImageImportProperties.cs delete mode 100644 VTFXUtil/ImageImporter.cs diff --git a/VTFXUtil/Form2.Designer.cs b/VTFXUtil/Form2.Designer.cs deleted file mode 100644 index ce4b4bd..0000000 --- a/VTFXUtil/Form2.Designer.cs +++ /dev/null @@ -1,340 +0,0 @@ -namespace VTFXUtil -{ - partial class Form2 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.TexTypeCombo = new System.Windows.Forms.ComboBox(); - this.AlphaCombo = new System.Windows.Forms.ComboBox(); - this.NonAlphaCombo = new System.Windows.Forms.ComboBox(); - this.label3 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); - this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.MakeMipCheckBox = new System.Windows.Forms.CheckBox(); - this.groupBox3 = new System.Windows.Forms.GroupBox(); - this.label6 = new System.Windows.Forms.Label(); - this.ClampHeight = new System.Windows.Forms.ComboBox(); - this.label5 = new System.Windows.Forms.Label(); - this.ClampWidth = new System.Windows.Forms.ComboBox(); - this.ClampCheckbox = new System.Windows.Forms.CheckBox(); - this.ResizeMethodCombo = new System.Windows.Forms.ComboBox(); - this.label4 = new System.Windows.Forms.Label(); - this.ResizeCheckbox = new System.Windows.Forms.CheckBox(); - this.OKButton = new System.Windows.Forms.Button(); - this.CancelButton = new System.Windows.Forms.Button(); - this.label7 = new System.Windows.Forms.Label(); - this.PlatformCombo = new System.Windows.Forms.ComboBox(); - this.PlatformTooltip = new System.Windows.Forms.ToolTip(this.components); - this.groupBox1.SuspendLayout(); - this.groupBox2.SuspendLayout(); - this.groupBox3.SuspendLayout(); - this.SuspendLayout(); - // - // groupBox1 - // - this.groupBox1.Controls.Add(this.TexTypeCombo); - this.groupBox1.Controls.Add(this.AlphaCombo); - this.groupBox1.Controls.Add(this.NonAlphaCombo); - this.groupBox1.Controls.Add(this.label3); - this.groupBox1.Controls.Add(this.label2); - this.groupBox1.Controls.Add(this.label1); - this.groupBox1.Location = new System.Drawing.Point(13, 13); - this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(265, 100); - this.groupBox1.TabIndex = 0; - this.groupBox1.TabStop = false; - this.groupBox1.Text = "General"; - // - // TexTypeCombo - // - this.TexTypeCombo.FormattingEnabled = true; - this.TexTypeCombo.Items.AddRange(new object[] { - "Animated/Non-Animated", - "Environment Map", - "Volumetric"}); - this.TexTypeCombo.Location = new System.Drawing.Point(83, 65); - this.TexTypeCombo.Name = "TexTypeCombo"; - this.TexTypeCombo.Size = new System.Drawing.Size(176, 21); - this.TexTypeCombo.TabIndex = 5; - // - // AlphaCombo - // - this.AlphaCombo.FormattingEnabled = true; - this.AlphaCombo.Location = new System.Drawing.Point(83, 37); - this.AlphaCombo.Name = "AlphaCombo"; - this.AlphaCombo.Size = new System.Drawing.Size(176, 21); - this.AlphaCombo.TabIndex = 4; - // - // NonAlphaCombo - // - this.NonAlphaCombo.FormattingEnabled = true; - this.NonAlphaCombo.Location = new System.Drawing.Point(105, 11); - this.NonAlphaCombo.Name = "NonAlphaCombo"; - this.NonAlphaCombo.Size = new System.Drawing.Size(154, 21); - this.NonAlphaCombo.TabIndex = 3; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(8, 68); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(70, 13); - this.label3.TabIndex = 2; - this.label3.Text = "Texture Type"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(9, 40); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(69, 13); - this.label2.TabIndex = 1; - this.label2.Text = "Alpha Format"; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(8, 14); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(91, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Non-alpha Format"; - // - // groupBox2 - // - this.groupBox2.Controls.Add(this.MakeMipCheckBox); - this.groupBox2.Location = new System.Drawing.Point(285, 13); - this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(200, 100); - this.groupBox2.TabIndex = 1; - this.groupBox2.TabStop = false; - this.groupBox2.Text = "Mipmaps"; - // - // MakeMipCheckBox - // - this.MakeMipCheckBox.AutoSize = true; - this.MakeMipCheckBox.Location = new System.Drawing.Point(7, 20); - this.MakeMipCheckBox.Name = "MakeMipCheckBox"; - this.MakeMipCheckBox.Size = new System.Drawing.Size(115, 17); - this.MakeMipCheckBox.TabIndex = 0; - this.MakeMipCheckBox.Text = "Generate Mipmaps"; - this.MakeMipCheckBox.UseVisualStyleBackColor = true; - // - // groupBox3 - // - this.groupBox3.Controls.Add(this.label6); - this.groupBox3.Controls.Add(this.ClampHeight); - this.groupBox3.Controls.Add(this.label5); - this.groupBox3.Controls.Add(this.ClampWidth); - this.groupBox3.Controls.Add(this.ClampCheckbox); - this.groupBox3.Controls.Add(this.ResizeMethodCombo); - this.groupBox3.Controls.Add(this.label4); - this.groupBox3.Controls.Add(this.ResizeCheckbox); - this.groupBox3.Location = new System.Drawing.Point(13, 120); - this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(265, 152); - this.groupBox3.TabIndex = 2; - this.groupBox3.TabStop = false; - this.groupBox3.Text = "Resize"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(10, 123); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(38, 13); - this.label6.TabIndex = 7; - this.label6.Text = "Height"; - // - // ClampHeight - // - this.ClampHeight.FormattingEnabled = true; - this.ClampHeight.Location = new System.Drawing.Point(51, 120); - this.ClampHeight.Name = "ClampHeight"; - this.ClampHeight.Size = new System.Drawing.Size(208, 21); - this.ClampHeight.TabIndex = 6; - // - // label5 - // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(10, 95); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(35, 13); - this.label5.TabIndex = 5; - this.label5.Text = "Width"; - // - // ClampWidth - // - this.ClampWidth.FormattingEnabled = true; - this.ClampWidth.Location = new System.Drawing.Point(51, 92); - this.ClampWidth.Name = "ClampWidth"; - this.ClampWidth.Size = new System.Drawing.Size(208, 21); - this.ClampWidth.TabIndex = 4; - // - // ClampCheckbox - // - this.ClampCheckbox.AutoSize = true; - this.ClampCheckbox.Location = new System.Drawing.Point(7, 71); - this.ClampCheckbox.Name = "ClampCheckbox"; - this.ClampCheckbox.Size = new System.Drawing.Size(55, 17); - this.ClampCheckbox.TabIndex = 3; - this.ClampCheckbox.Text = "Clamp"; - this.ClampCheckbox.UseVisualStyleBackColor = true; - this.ClampCheckbox.CheckedChanged += new System.EventHandler(this.ClampCheckbox_CheckedChanged); - // - // ResizeMethodCombo - // - this.ResizeMethodCombo.FormattingEnabled = true; - this.ResizeMethodCombo.Items.AddRange(new object[] { - "Nearest Power of 2", - "Biggest Power of 2", - "Smallest Power of 2"}); - this.ResizeMethodCombo.Location = new System.Drawing.Point(91, 41); - this.ResizeMethodCombo.Name = "ResizeMethodCombo"; - this.ResizeMethodCombo.Size = new System.Drawing.Size(168, 21); - this.ResizeMethodCombo.TabIndex = 2; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(7, 44); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(78, 13); - this.label4.TabIndex = 1; - this.label4.Text = "Resize Method"; - // - // ResizeCheckbox - // - this.ResizeCheckbox.AutoSize = true; - this.ResizeCheckbox.Location = new System.Drawing.Point(7, 20); - this.ResizeCheckbox.Name = "ResizeCheckbox"; - this.ResizeCheckbox.Size = new System.Drawing.Size(58, 17); - this.ResizeCheckbox.TabIndex = 0; - this.ResizeCheckbox.Text = "Resize"; - this.ResizeCheckbox.UseVisualStyleBackColor = true; - this.ResizeCheckbox.CheckedChanged += new System.EventHandler(this.ResizeCheckbox_CheckedChanged); - // - // OKButton - // - this.OKButton.Location = new System.Drawing.Point(285, 243); - this.OKButton.Name = "OKButton"; - this.OKButton.Size = new System.Drawing.Size(75, 23); - this.OKButton.TabIndex = 3; - this.OKButton.Text = "OK"; - this.OKButton.UseVisualStyleBackColor = true; - this.OKButton.Click += new System.EventHandler(this.OKButton_Click); - // - // CancelButton - // - this.CancelButton.Location = new System.Drawing.Point(410, 243); - this.CancelButton.Name = "CancelButton"; - this.CancelButton.Size = new System.Drawing.Size(75, 23); - this.CancelButton.TabIndex = 4; - this.CancelButton.Text = "Cancel"; - this.CancelButton.UseVisualStyleBackColor = true; - this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click); - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(286, 123); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(45, 13); - this.label7.TabIndex = 5; - this.label7.Text = "Platform"; - // - // PlatformCombo - // - this.PlatformCombo.FormattingEnabled = true; - this.PlatformCombo.Items.AddRange(new object[] { - "PlayStation 3", - "Xbox 360"}); - this.PlatformCombo.Location = new System.Drawing.Point(337, 120); - this.PlatformCombo.Name = "PlatformCombo"; - this.PlatformCombo.Size = new System.Drawing.Size(148, 21); - this.PlatformCombo.TabIndex = 6; - // - // PlatformTooltip - // - this.PlatformTooltip.ToolTipTitle = "hello"; - // - // Form2 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(497, 278); - this.Controls.Add(this.PlatformCombo); - this.Controls.Add(this.label7); - this.Controls.Add(this.CancelButton); - this.Controls.Add(this.OKButton); - this.Controls.Add(this.groupBox3); - this.Controls.Add(this.groupBox2); - this.Controls.Add(this.groupBox1); - this.Name = "Form2"; - this.Text = "Form2"; - this.Load += new System.EventHandler(this.Form2_Load); - this.groupBox1.ResumeLayout(false); - this.groupBox1.PerformLayout(); - this.groupBox2.ResumeLayout(false); - this.groupBox2.PerformLayout(); - this.groupBox3.ResumeLayout(false); - this.groupBox3.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.GroupBox groupBox1; - private System.Windows.Forms.ComboBox NonAlphaCombo; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.ComboBox TexTypeCombo; - private System.Windows.Forms.ComboBox AlphaCombo; - private System.Windows.Forms.GroupBox groupBox2; - private System.Windows.Forms.CheckBox MakeMipCheckBox; - private System.Windows.Forms.GroupBox groupBox3; - private System.Windows.Forms.CheckBox ResizeCheckbox; - private System.Windows.Forms.ComboBox ResizeMethodCombo; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.CheckBox ClampCheckbox; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.ComboBox ClampHeight; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.ComboBox ClampWidth; - private System.Windows.Forms.Button OKButton; - private System.Windows.Forms.Button CancelButton; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.ComboBox PlatformCombo; - private System.Windows.Forms.ToolTip PlatformTooltip; - } -} \ No newline at end of file diff --git a/VTFXUtil/Form2.resx b/VTFXUtil/Form2.resx deleted file mode 100644 index 2c1729c..0000000 --- a/VTFXUtil/Form2.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - \ No newline at end of file diff --git a/VTFXUtil/Formats.cs b/VTFXUtil/Formats.cs deleted file mode 100644 index b5506f8..0000000 --- a/VTFXUtil/Formats.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VTFXUtil -{ - // format handling/construction type things should go here from now on - public class Formats - { - public class VTFFile - { - public readonly byte[] Magic = { 0x56, 0x54, 0x46, 0x00 }; - public byte[] FileVersion = new byte[8]; - public int HeaderLength; // may vary upon how many resources the image contains, but a 7.3 header has a length of 0x50 when resource info is stripped - public int Width; - public int Height; - public byte[] Flags = new byte[4]; - public int Frames; - public int FirstFrame = 0; // will usually be zero, so it should be fine to hardcode it here - // 4 bytes of padding - public byte[] ReflectivityVector = new byte[12]; // contains three 4 byte floats - // another 4 bytes of padding - public float BumpScale; // single float - public byte[] Format = new byte[4]; - public int MipmapCount; // 8-bit integer - public byte[] ThumbFormat = new byte[4]; - public int ThumbWidth; - public int ThumbHeight; - public int ImageDepth; // all 3 of these are also 8-bit integers, depth will only apply to 7.2 and above - // another 4 bytes of padding - public int ResourceCount; // will only apply to 7.3 and above - // 8 bytes of padding - public List Resources = new List(); // also only applies to 7.3 and above - - public bool CheckMagic(byte[] Magic) - { - if (Magic.Equals(this.Magic)) - { - return true; - } - else - { - return false; - } - } - } - } -} diff --git a/VTFXUtil/ImageImportProperties.cs b/VTFXUtil/ImageImportProperties.cs deleted file mode 100644 index 872d132..0000000 --- a/VTFXUtil/ImageImportProperties.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VTFXUtil -{ - public class ImageImportProperties - { - public string OutAlphaFmt; - public string OutNoAlphaFmt; - public string OutTexType; - public bool DemandedResize; - public bool DemandedClamps; - public bool CanGenerateMips; - public string Ree; - public int ClampingWidth; - public int ClampingHeight; - public string Platform; - - public ImageImportProperties(string Alphafmt, string Regfmt, string Textype, bool Resizetrig, bool Clampable, bool Genmips, string Resmethod, int Clampwidth, int Clampheight, string Plat) - { - OutAlphaFmt = Alphafmt; - OutNoAlphaFmt = Regfmt; - OutTexType = Textype; - DemandedResize = Resizetrig; - DemandedClamps = Clampable; - CanGenerateMips = Genmips; - Ree = Resmethod; - ClampingWidth = Clampwidth; - ClampingHeight = Clampheight; - Platform = Plat; - } - } -} diff --git a/VTFXUtil/ImageImporter.cs b/VTFXUtil/ImageImporter.cs deleted file mode 100644 index c8cc32f..0000000 --- a/VTFXUtil/ImageImporter.cs +++ /dev/null @@ -1,269 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -// image importing methods will be left up to this thing, as i may have cluttered the fuck out of Form1.cs - -namespace VTFXUtil -{ /// -/// Handles methods for general texture import/export/manipulation uses. -/// - class ImageImporter - { - - public enum ImportableFormats - { - DDS, - JPG, - PNG, - TIF, - TGA, - VTF - } - - /// - /// Decompresses LZMA compressed files. Primarily used on Xbox 360 textures. - /// - /// - /// - /// - /// - public static byte[] LZMADecompress(byte[] inData, string inPath, string outPath) - { - System.IO.FileStream TempLZMAIn = new System.IO.FileStream(inPath, System.IO.FileMode.Create); - TempLZMAIn.Write(inData, 0, inData.Length); - TempLZMAIn.Close(); - TempLZMAIn = new System.IO.FileStream(inPath, System.IO.FileMode.Open); - System.IO.FileStream TempLZMAOut = new System.IO.FileStream(outPath, System.IO.FileMode.Create); - byte[] HeaderBytes = new byte[4]; - byte[] UncompressedSizeBytes = new byte[4]; - byte[] CompressedSizeBytes = new byte[4]; - byte[] DecoderProperties = new byte[5]; - TempLZMAIn.Read(HeaderBytes, 0, 4); - TempLZMAIn.Read(UncompressedSizeBytes, 0, 4); - TempLZMAIn.Read(CompressedSizeBytes, 0, 4); - TempLZMAIn.Read(DecoderProperties, 0, 5); - int UncompressedSize = System.BitConverter.ToInt32(UncompressedSizeBytes, 0); - int CompressedSize = System.BitConverter.ToInt32(CompressedSizeBytes, 0); - SevenZip.Compression.LZMA.Decoder LZMADec = new SevenZip.Compression.LZMA.Decoder(); - LZMADec.SetDecoderProperties(DecoderProperties); - LZMADec.Code(TempLZMAIn, TempLZMAOut, CompressedSize, UncompressedSize, null); - TempLZMAIn.Flush(); - TempLZMAOut.Flush(); - TempLZMAOut.Close(); - TempLZMAOut = new System.IO.FileStream(outPath, System.IO.FileMode.Open, System.IO.FileAccess.Read); - byte[] Texture = new byte[UncompressedSize]; - using (TempLZMAOut) - { - TempLZMAOut.Read(Texture, 0, UncompressedSize); - } - TempLZMAOut.Close(); - TempLZMAIn.Close(); - return Texture; - } - - /// - /// Returns an LZMA compressed version of the input data as a MemoryStream. - /// - /// - /// - public static System.IO.MemoryStream LZMACompress(byte[] InData) - { - SevenZip.CoderPropID[] Properties = { SevenZip.CoderPropID.DictionarySize, SevenZip.CoderPropID.PosStateBits, SevenZip.CoderPropID.LitContextBits, SevenZip.CoderPropID.LitPosBits, SevenZip.CoderPropID.Algorithm, SevenZip.CoderPropID.NumFastBytes, SevenZip.CoderPropID.MatchFinder, SevenZip.CoderPropID.EndMarker }; - object[] Props2 = { (1 << 23), 2, 3, 0, 2, 128, "bt4", false }; // default properties - SevenZip.Compression.LZMA.Encoder LZMAEnc = new SevenZip.Compression.LZMA.Encoder(); - LZMAEnc.SetCoderProperties(Properties, Props2); - System.IO.MemoryStream TempInStream = new System.IO.MemoryStream(); - TempInStream.Write(InData, 0, InData.Length); - TempInStream.Position = 0; - System.IO.MemoryStream TempOutStream = new System.IO.MemoryStream(); - System.IO.MemoryStream CompressedTexture = new System.IO.MemoryStream(); - LZMAEnc.Code(TempInStream, CompressedTexture, -1, -1, null); - long CompressedSize = CompressedTexture.Length; - byte[] LZMAIdent = { 0x4c, 0x5a, 0x4d, 0x41 }; // "LZMA", had to make this a byte array, as you can't copy string values to a stream - TempOutStream.Write(LZMAIdent, 0, 4); - TempOutStream.Write(System.BitConverter.GetBytes(InData.Length), 0, 4); - TempOutStream.Write(System.BitConverter.GetBytes(CompressedSize), 0, 4); - LZMAEnc.WriteCoderProperties(TempOutStream); - TempOutStream.Write(CompressedTexture.ToArray(), 0, CompressedTexture.ToArray().Length); // had to manually append the contents of the texture stream onto the other stream, as apparently resetting the stream screws up with the LZMA coder, which then refuses to properly write the texture - CompressedTexture.Dispose(); // free resources - return TempOutStream; - } - - /// - /// Just a simple endian swap. Nothing more, nothing less. - /// - /// - /// - /// - public static byte[] EndianSwap(byte[] Data, int BufferSize) - { - byte[] ByteBuffer = new byte[BufferSize]; //create bytebuffer for endianswapping - byte[] TextureTemp = new byte[Data.Length]; - for (int i = 0; i < Data.Length; i += ByteBuffer.Length) - { - Array.Copy(Data, i, ByteBuffer, 0, ByteBuffer.Length); - Array.Reverse(ByteBuffer); - Array.Copy(ByteBuffer, 0, TextureTemp, i, ByteBuffer.Length); - } - return TextureTemp; - } - - /// - /// Arranges any Block Compressed texture formats from a format usable by the Xbox 360 into one that a PC can comprehend - /// - /// - /// - /// - public static byte[] RearrangeCompressedTexture(byte[] TexData, int Format) //compressed textures on the 360 need to be endianswapped, yet the PS3 counterparts don't - { - byte[] NewTexData = new byte[TexData.Length]; - int ColorValLen = 0; - int ColorBlendLen = 0; - int AlphaValLen = 0; - if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1) - { - ColorValLen = 2; //will be doubled!!! - ColorBlendLen = 4; - AlphaValLen = 0; - } - else if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT3 || Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT5) - { - AlphaValLen = 8; - ColorValLen = 2; //will be doubled!! - ColorBlendLen = 4; - } - else - { - return TexData; - } - int BlockLength = (ColorValLen * 2) + ColorBlendLen + AlphaValLen; - byte[] EditingBlock = new byte[BlockLength]; - for (int i = 0; i < TexData.Length; i += BlockLength) - { - byte[] Color0 = new byte[ColorValLen]; - byte[] Color1 = new byte[ColorValLen]; - byte[] ColorBlendInfo = new byte[ColorBlendLen]; - if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT1) - { - Array.Copy(TexData, i, Color0, 0, ColorValLen); - Array.Copy(TexData, i + ColorValLen, Color1, 0, ColorValLen); - Array.Copy(TexData, i + BlockLength - AlphaValLen - ColorBlendLen, ColorBlendInfo, 0, ColorBlendLen); - Array.Reverse(Color0); - Array.Reverse(Color1); // reverse color data, as our endianness is not the same as the Xenon - byte[] DuplicateOfColorLayout = new byte[4]; - Array.Copy(ColorBlendInfo, DuplicateOfColorLayout, 4); - ColorBlendInfo[0] = DuplicateOfColorLayout[1]; - ColorBlendInfo[1] = DuplicateOfColorLayout[0]; - ColorBlendInfo[2] = DuplicateOfColorLayout[3]; - ColorBlendInfo[3] = DuplicateOfColorLayout[2]; // color layout inside of the 4x4 blocks is arranged strangely, as [row 2, row 1, row 3, row 4] - Array.Copy(Color0, 0, EditingBlock, 0, ColorValLen); - Array.Copy(Color1, 0, EditingBlock, ColorValLen, ColorValLen); - Array.Copy(ColorBlendInfo, 0, EditingBlock, ColorValLen * 2, ColorBlendLen); //copy new values into the newly created block - } - else //for formats with alpha - { - byte[] AlphaInfo = new byte[AlphaValLen]; - Array.Copy(TexData, i, AlphaInfo, 0, AlphaValLen); - byte[] NewAlphaInfo = new byte[AlphaValLen]; // make this for reversible alphas - //Array.Reverse(AlphaInfo); - Array.Copy(TexData, i + AlphaValLen, Color0, 0, ColorValLen); - Array.Copy(TexData, i + AlphaValLen + ColorValLen, Color1, 0, ColorValLen); - Array.Copy(TexData, i + AlphaValLen + BlockLength - AlphaValLen - ColorBlendLen, ColorBlendInfo, 0, ColorBlendLen); - if (Format == (int)VTFGeneral.TEXTURE_FORMATS.IMAGE_FORMAT_DXT5) // the 360's DXT5 type files are reversed in an odd kind of way, i personally haven't encountered many DXT3 files, and will have to be added later if i find one - { - for (int k = 1; k < AlphaValLen; k += 2) - { - NewAlphaInfo[k - 1] = AlphaInfo[k]; - NewAlphaInfo[k] = AlphaInfo[k - 1]; - } - AlphaInfo = NewAlphaInfo; - } - Array.Reverse(Color0); - Array.Reverse(Color1); - byte[] DuplicateOfColorLayout = new byte[4]; - Array.Copy(ColorBlendInfo, DuplicateOfColorLayout, 4); - ColorBlendInfo[0] = DuplicateOfColorLayout[1]; - ColorBlendInfo[1] = DuplicateOfColorLayout[0]; - ColorBlendInfo[2] = DuplicateOfColorLayout[3]; - ColorBlendInfo[3] = DuplicateOfColorLayout[2]; // cloned from dxt1 - Array.Copy(AlphaInfo, 0, EditingBlock, 0, AlphaValLen); - Array.Copy(Color0, 0, EditingBlock, AlphaValLen, ColorValLen); - Array.Copy(Color1, 0, EditingBlock, AlphaValLen + ColorValLen, ColorValLen); - Array.Copy(ColorBlendInfo, 0, EditingBlock, AlphaValLen + ColorValLen * 2, ColorBlendLen); - } - Array.Copy(EditingBlock, 0, NewTexData, i, BlockLength); //reconstruct texture data with new stuff - } - return NewTexData; - } - - /// - /// Outputs a MemoryStream with the specified texture data, and reverses the mipmap order, for use in VTF/VTFX or other smallest-mip-first formats. - /// - /// - /// - /// - /// - /// - /// - public static System.IO.MemoryStream ReverseMipsIntoMemoryStream(byte[] TexData, int Width, int Height, int Format, MipMaker.MipMap[] MipList) - { - System.IO.MemoryStream CurrentTexture = new System.IO.MemoryStream(); - List Mips = new List(); - CurrentTexture.Write(TexData, 0, TexData.Length); - CurrentTexture.Position = 0; // reset back to beginning of the stream, we will need this for what comes next - for (int i = 0; i < MipList.Length; i++) - { - byte[] CurrentMip = new byte[MipList[i].TotalBytes]; - CurrentTexture.Read(CurrentMip, 0, MipList[i].TotalBytes); - Mips.Add(CurrentMip); // take the texture data from the stream, and shove it into the list - } - CurrentTexture.Flush(); - CurrentTexture.Dispose(); - Mips.Reverse(); - CurrentTexture = new System.IO.MemoryStream(); - foreach (byte[] Mip in Mips) - { - CurrentTexture.Write(Mip, 0, Mip.Length); - } - return CurrentTexture; - } - - /// - /// Converts and outputs texture data as a TIF file in a MemoryStream. - /// - /// - /// - /// - /// - /// - public static System.IO.MemoryStream GenerateImage(byte[] Texture, int Mipcount, int Format, VTFXHandler.VTFXFile Imported) - { - System.IO.MemoryStream TextureStream = new System.IO.MemoryStream(); - TextureStream.Write(Texture, 0, Texture.Length); - CSharpImageLibrary.ImageEngineFormat ParsedEnum = (CSharpImageLibrary.ImageEngineFormat)Enum.Parse(typeof(VTFGeneral.TEXTURE_FORMATS_INTEROP), Enum.GetName(typeof(VTFGeneral.TEXTURE_FORMATS), Format)); - Console.WriteLine(ParsedEnum); - - CSharpImageLibrary.Headers.DDS_Header newDDSHeader = new CSharpImageLibrary.Headers.DDS_Header(Mipcount, Imported.ImageHeight, Imported.ImageWidth, ParsedEnum, CSharpImageLibrary.Headers.DDS_Header.DXGI_FORMAT.DXGI_FORMAT_UNKNOWN); - byte[] DDSHeader = new byte[newDDSHeader.dwSize + 4]; - newDDSHeader.WriteToArray(DDSHeader, 0); - byte[] RealTexture = new byte[DDSHeader.Length + Texture.Length]; - Array.Copy(DDSHeader, 0, RealTexture, 0, DDSHeader.Length); - Array.Copy(Texture, 0, RealTexture, DDSHeader.Length, Texture.Length); - TextureStream.Flush(); - TextureStream.Write(RealTexture, 0, RealTexture.Length); - CSharpImageLibrary.ImageEngineImage CSILImage = new CSharpImageLibrary.ImageEngineImage(RealTexture); - //Console.WriteLine(CSILImage.ToString()); - CSharpImageLibrary.ImageFormats.ImageEngineFormatDetails DestinationDetails = new CSharpImageLibrary.ImageFormats.ImageEngineFormatDetails(CSharpImageLibrary.ImageEngineFormat.TIF); - bool AlphaRemovalFlag = !(VTFGeneral.HasAlpha(Format)); - byte[] ConvertedToPNG = CSILImage.Save(DestinationDetails, CSharpImageLibrary.MipHandling.KeepTopOnly, 8192, 0, false); //show only the first mip, as this is just a preview - System.IO.MemoryStream PNGStream = new System.IO.MemoryStream(); //import our file into ram - PNGStream.Write(ConvertedToPNG, 0, ConvertedToPNG.Length); - return PNGStream; - } - - - } -}