diff --git a/Readme.md b/Readme.md
index 5675e4c..c5dcb8e 100644
--- a/Readme.md
+++ b/Readme.md
@@ -8,16 +8,16 @@
A combination tool for managing Terraria content resources. Convert, extract, backup, and restore. The unofficial sequel to TExtract.
-![Window Preview](http://i.imgur.com/oTuVrGQ.png)
+![Window Preview](https://i.imgur.com/oTuVrGQ.png)
-### [Wiki](https://github.com/trigger-death/TConvert/wiki) | [Credits](https://github.com/trigger-death/TConvert/wiki/Credits) | [Image Album](http://imgur.com/a/QaoPd)
+### [Wiki](https://github.com/trigger-death/TConvert/wiki) | [Credits](https://github.com/trigger-death/TConvert/wiki/Credits) | [Image Album](https://imgur.com/a/QaoPd)
### [![Get TConvert](http://i.imgur.com/4BGRFF0.png)](https://github.com/trigger-death/TConvert/releases/latest)
## About
* **Created By:** Robert Jordan
-* **Version:** 1.0.1.0
+* **Version:** 1.0.2.0
* **Language:** C#, WPF
## Requirements for Running
diff --git a/TConvert/App.config b/TConvert/App.config
index af2dfb1..e02e280 100644
--- a/TConvert/App.config
+++ b/TConvert/App.config
@@ -98,6 +98,9 @@
True
+
+ True
+
\ No newline at end of file
diff --git a/TConvert/App.xaml.cs b/TConvert/App.xaml.cs
index 8f7ddac..15d9b6e 100644
--- a/TConvert/App.xaml.cs
+++ b/TConvert/App.xaml.cs
@@ -41,7 +41,7 @@ private Assembly OnResolveAssemblies(object sender, ResolveEventArgs args) {
string path = assemblyName.Name + ".dll";
if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false) {
- path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
+ path = string.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
}
using (Stream stream = executingAssembly.GetManifestResourceStream(path)) {
diff --git a/TConvert/CommandLine.cs b/TConvert/CommandLine.cs
index 18acf5c..3a0f6be 100644
--- a/TConvert/CommandLine.cs
+++ b/TConvert/CommandLine.cs
@@ -40,7 +40,9 @@ private enum ArgTypes {
//AutoCloseDef= 0x4000,
//KeepOpenDef = 0x8000,
Compress = 0x10000,
- DontCompress= 0x20000
+ DontCompress= 0x20000,
+ Premultiply = 0x40000,
+ DontPremultiply = 0x80000,
}
/**Information about a command line option.*/
@@ -96,6 +98,8 @@ public string OptionsToString() {
{ ArgTypes.Compress,new OptionInfo(ProcessCompress, "Compress", "Images will be compressed.", null, "-ic", "--compress") },
{ ArgTypes.DontCompress,new OptionInfo(ProcessDontCompress, "Don't Compress", "Images will not be compressed.", null, "-dc", "--dont-compress") },
+ { ArgTypes.Premultiply, new OptionInfo(ProcessPremultiply, "Premultiply", "RGB will be multiplied by alpha.", null, "-pr", "--premult") },
+ { ArgTypes.DontPremultiply, new OptionInfo(ProcessDontPremultiply, "Don't Premultiply", "RGB will not be modified.", null, "-dp", "--dont-premult") },
};
#endregion
@@ -124,6 +128,8 @@ public string OptionsToString() {
private static bool autoClose = Settings.Default.AutoCloseCmdProgress;
/**True if images are compressed.*/
private static bool compress = Settings.Default.CompressImages && XCompress.IsAvailable;
+ /**True if alpha is premultiplied.*/
+ private static bool premultiply = Settings.Default.PremultiplyAlpha;
/**True if a sound is played upon completion.*/
private static bool sound = Settings.Default.CompletionSound;
/**True if in console-only mode.*/
@@ -335,12 +341,12 @@ public static void ProcessFiles() {
});
#if !(CONSOLE)
if (!console) {
- Processing.StartProgressThread(null, "Processing Files...", autoClose, compress, sound, thread);
+ Processing.StartProgressThread(null, "Processing Files...", autoClose, compress, sound, premultiply, thread);
}
else
#endif
{
- Processing.StartConsoleThread("Processing Files...", silent, compress, sound, thread);
+ Processing.StartConsoleThread("Processing Files...", silent, compress, sound, premultiply, thread);
}
}
@@ -554,6 +560,24 @@ private static void ProcessDontCompress() {
else
compress = false;
}
+ /**Processes the Premultiply option.*/
+ private static void ProcessPremultiply() {
+ if (passedArgs.HasFlag(ArgTypes.Premultiply))
+ LogOptionAlreadySpecified(ArgTypes.Premultiply);
+ if (passedArgs.HasFlag(ArgTypes.DontPremultiply))
+ LogOptionAlreadySpecified(ArgTypes.DontPremultiply);
+ else
+ premultiply = true;
+ }
+ /**Processes the Premultiply option.*/
+ private static void ProcessDontPremultiply() {
+ if (passedArgs.HasFlag(ArgTypes.Premultiply))
+ LogOptionAlreadySpecified(ArgTypes.Premultiply);
+ if (passedArgs.HasFlag(ArgTypes.DontPremultiply))
+ LogOptionAlreadySpecified(ArgTypes.DontPremultiply);
+ else
+ premultiply = false;
+ }
#endregion
//--------------------------------
diff --git a/TConvert/Config.cs b/TConvert/Config.cs
index af1540b..a525b30 100644
--- a/TConvert/Config.cs
+++ b/TConvert/Config.cs
@@ -39,6 +39,8 @@ public static class Config {
public static bool CompressImages { get; set; }
/**True if a sound is played on completion.*/
public static bool CompletionSound { get; set; }
+ /**True if alpha is premultiplied by default when converting to xnb.*/
+ public static bool PremultiplyAlpha { get; set; }
#endregion
//=========== CLASSES ============
@@ -181,6 +183,7 @@ public static void Load() {
AutoCloseCmdProgress = Settings.Default.AutoCloseCmdProgress;
CompressImages = Settings.Default.CompressImages && XCompress.IsAvailable;
CompletionSound = Settings.Default.CompletionSound;
+ PremultiplyAlpha = Settings.Default.PremultiplyAlpha;
Extract.FolderInput = Settings.Default.ExtractFolderInput;
Extract.FolderOutput = Settings.Default.ExtractFolderOutput;
@@ -224,6 +227,7 @@ public static void Save() {
Settings.Default.AutoCloseCmdProgress = AutoCloseCmdProgress;
Settings.Default.CompressImages = CompressImages;
Settings.Default.CompletionSound = CompletionSound;
+ Settings.Default.PremultiplyAlpha = PremultiplyAlpha;
Settings.Default.ExtractFolderInput = Extract.FolderInput;
Settings.Default.ExtractFolderOutput = Extract.FolderOutput;
diff --git a/TConvert/Convert/PngConverter.cs b/TConvert/Convert/PngConverter.cs
index baf71a0..1a4b341 100644
--- a/TConvert/Convert/PngConverter.cs
+++ b/TConvert/Convert/PngConverter.cs
@@ -53,7 +53,7 @@ public class PngConverter {
#region Converting
/**Converts the specified input file and writes it to the output file.*/
- public static bool Convert(string inputFile, string outputFile, bool changeExtension, bool compressed, bool reach) {
+ public static bool Convert(string inputFile, string outputFile, bool changeExtension, bool compressed, bool reach, bool premultiply) {
if (changeExtension) {
outputFile = Path.ChangeExtension(outputFile, ".xnb");
}
@@ -80,11 +80,11 @@ public static bool Convert(string inputFile, string outputFile, bool changeExten
}
writer.Write(flagBits); // flag-bits; 00=reach, 01=hiprofile, 80=compressed, 00=uncompressed
if (compressed) {
- WriteCompressedData(writer, bmp);
+ WriteCompressedData(writer, bmp, premultiply);
}
else {
writer.Write(MetadataSize + bmp.Width * bmp.Height * 4); // compressed file size
- WriteData(bmp, writer);
+ WriteData(bmp, writer, premultiply);
}
}
}
@@ -97,11 +97,11 @@ public static bool Convert(string inputFile, string outputFile, bool changeExten
#region Writing
/**Write compressed image data.*/
- private static void WriteCompressedData(BinaryWriter writer, Bitmap png) {
+ private static void WriteCompressedData(BinaryWriter writer, Bitmap png, bool premultiply) {
using (MemoryStream stream = new MemoryStream()) {
byte[] uncompressedData;
using (BinaryWriter writer2 = new BinaryWriter(stream)) {
- WriteData(png, writer2);
+ WriteData(png, writer2, premultiply);
uncompressedData = stream.ToArray();
}
byte[] compressedData = XCompress.Compress(uncompressedData);
@@ -111,7 +111,7 @@ private static void WriteCompressedData(BinaryWriter writer, Bitmap png) {
}
}
/**Write uncompressed image data.*/
- private static void WriteData(Bitmap bmp, BinaryWriter writer) {
+ private static void WriteData(Bitmap bmp, BinaryWriter writer, bool premultiply) {
writer.Write7BitEncodedInt(1); // type-reader-count
writer.Write7BitEncodedString(Texture2DType); // type-reader-name
writer.Write((int)0); // reader version number
@@ -130,14 +130,30 @@ private static void WriteData(Bitmap bmp, BinaryWriter writer) {
}
BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
try {
- var length = bitmapData.Stride * bitmapData.Height;
+ int length = bitmapData.Stride * bitmapData.Height;
byte[] bytes = new byte[length];
Marshal.Copy(bitmapData.Scan0, bytes, 0, length);
- // Swap the R and B channels
for (int i = 0; i < bytes.Length; i += 4) {
- byte b = bytes[i];
- bytes[i] = bytes[i + 2];
- bytes[i + 2] = b;
+ // Always swap red and blue channels premultiply alpha if requested
+ int a = bytes[i + 3];
+ if (!premultiply || a == 255) {
+ // No premultiply necessary
+ byte b = bytes[i];
+ bytes[i] = bytes[i + 2];
+ bytes[i + 2] = b;
+ }
+ else if (a != 0) {
+ byte b = bytes[i];
+ bytes[i] = (byte) (bytes[i + 2] * a / 255);
+ bytes[i + 1] = (byte) (bytes[i + 1] * a / 255);
+ bytes[i + 2] = (byte) (b * a / 255);
+ }
+ else {
+ // alpha is zero, so just zero everything
+ bytes[i] = 0;
+ bytes[i + 1] = 0;
+ bytes[i + 2] = 0;
+ }
}
writer.Write(bytes);
}
diff --git a/TConvert/Convert/WavConverter.cs b/TConvert/Convert/WavConverter.cs
index 423d157..6adcd72 100644
--- a/TConvert/Convert/WavConverter.cs
+++ b/TConvert/Convert/WavConverter.cs
@@ -97,8 +97,7 @@ public static bool Convert(string inputFile, string outputFile, bool changeExten
throw new WavException("Average bytes per second number incorrect.");
if (nBlockAlign != (nChannels * (wBitsPerSample / 8)))
throw new WavException("Block align number incorrect.");
-
-
+
inputStream.Position = chunkSize;
format = new string(reader.ReadChars(4));
diff --git a/TConvert/Extract/Ffmpeg.cs b/TConvert/Extract/Ffmpeg.cs
index 243f4cf..fd409ca 100644
--- a/TConvert/Extract/Ffmpeg.cs
+++ b/TConvert/Extract/Ffmpeg.cs
@@ -61,8 +61,6 @@ public static bool Convert(string input, string output) {
"-acodec pcm_s16le " +
"-nostdin " +
"-ab 128k " +
- //"-fflags +bitexact -flags:a +bitexact " +
- //"-metadata title=\"\" " +
"-map_metadata -1 " +
"-y " +
"\"" + Path.GetFullPath(output) + "\"";
diff --git a/TConvert/MainWindow.xaml b/TConvert/MainWindow.xaml
index aab4bcb..2965e7d 100644
--- a/TConvert/MainWindow.xaml
+++ b/TConvert/MainWindow.xaml
@@ -44,6 +44,11 @@