From 2ae07a2cc3b0c59255f71b591d9a20e9824352ce Mon Sep 17 00:00:00 2001 From: Lucas Teske Date: Wed, 22 Feb 2017 21:08:53 -0300 Subject: [PATCH 1/2] Changed Decompress.exe to libdecompress --- XRIT/Tools/AEC.cs | 58 +++++++++++ XRIT/XRIT.csproj | 3 + XRITLibraryTest/MainWindow.cs | 2 +- goesdump.userprefs | 20 ++-- goesdump/GoesDecoder/PacketManager.cs | 141 +++++++++++++------------- 5 files changed, 143 insertions(+), 81 deletions(-) create mode 100644 XRIT/Tools/AEC.cs diff --git a/XRIT/Tools/AEC.cs b/XRIT/Tools/AEC.cs new file mode 100644 index 0000000..ff66120 --- /dev/null +++ b/XRIT/Tools/AEC.cs @@ -0,0 +1,58 @@ +using System; +using System.Runtime.InteropServices; + +namespace OpenSatelliteProject.Tools { + /// + /// libaec Wrapper Class + /// + /// Used for decompressing LRIT Rice + /// + public static class AEC { + public static readonly int ALLOW_K13_OPTION_MASK = 1; + public static readonly int CHIP_OPTION_MASK = 2; + public static readonly int EC_OPTION_MASK = 4; + public static readonly int LSB_OPTION_MASK = 8; + public static readonly int MSB_OPTION_MASK = 16; + public static readonly int NN_OPTION_MASK = 32; + public static readonly int RAW_OPTION_MASK = 128; + + [DllImport("satdecompress", CallingConvention = CallingConvention.Cdecl)] + public static unsafe extern int Decompress(byte *input, byte *output, uint inputLength, uint outputLength, int bitsPerPixel, int pixelsPerBlock, int pixelsPerScanline, int mask); + + public static int LritRiceDecompress(ref byte[] dest, byte[] source, int bitsPerPixel, int pixelsPerBlock, int pixelsPerScanline, int mask) { + int status = -100; + unsafe { + fixed (byte* destPtr = dest) { + fixed (byte *srcPtr = source) { + status = Decompress(srcPtr, destPtr, (uint) source.Length, (uint) dest.Length, bitsPerPixel, pixelsPerBlock, pixelsPerScanline, mask); + } + } + } + + if (status <= 0) { + throw new AECException((AECStatus)status); + } + + return status; + } + } + + public class AECException: Exception { + public AECStatus status; + + public AECException(AECStatus error) { + this.status = error; + } + } + + public enum AECStatus { + INTERNAL_ERROR = -100, + MEMORY_ERROR = -4, + DATA_ERROR = -3, + STREAM_ERROR = -2, + CONFIG_ERROR = -1, + OK = 0, + OUTPUT_BUFFER_FULL = 2, + } +} + diff --git a/XRIT/XRIT.csproj b/XRIT/XRIT.csproj index 48ff547..c6fdb19 100644 --- a/XRIT/XRIT.csproj +++ b/XRIT/XRIT.csproj @@ -18,6 +18,7 @@ prompt 4 false + true full @@ -26,6 +27,7 @@ prompt 4 false + true @@ -73,6 +75,7 @@ + diff --git a/XRITLibraryTest/MainWindow.cs b/XRITLibraryTest/MainWindow.cs index 446f907..7f9c332 100644 --- a/XRITLibraryTest/MainWindow.cs +++ b/XRITLibraryTest/MainWindow.cs @@ -19,7 +19,7 @@ public MainWindow() : base(Gtk.WindowType.Toplevel) { private void ProcessFile(string filename) { string outputFolder = System.IO.Path.GetDirectoryName(filename); //ImageHandler.Handler.HandleFile(filename, outputFolder); - TextHandler.Handler.HandleFile(filename, outputFolder); + //TextHandler.Handler.HandleFile(filename, outputFolder); } protected void OnDeleteEvent(object sender, DeleteEventArgs a) { diff --git a/goesdump.userprefs b/goesdump.userprefs index 4b5b44c..58ae242 100644 --- a/goesdump.userprefs +++ b/goesdump.userprefs @@ -1,21 +1,17 @@  - + - - - - - - - - - - + + + + - + + + \ No newline at end of file diff --git a/goesdump/GoesDecoder/PacketManager.cs b/goesdump/GoesDecoder/PacketManager.cs index 48ac588..4383f43 100644 --- a/goesdump/GoesDecoder/PacketManager.cs +++ b/goesdump/GoesDecoder/PacketManager.cs @@ -228,98 +228,103 @@ public static void DumpFile(string filename, XRITHeader fileHeader, string newEx } public static string Decompressor(string filename, int pixels) { + /** + * Temporary Workarround. Needs to change directly on Demuxer + */ + string outputFile = String.Format("{0}_decomp.lrit", filename); + byte[] outputData = new byte[pixels]; + + for (int i = 0; i < pixels; i++) { + outputData[i] = 0x00; + } + try { - Process decompressor = new Process(); - ProcessStartInfo startInfo = new ProcessStartInfo(); - startInfo.WindowStyle = ProcessWindowStyle.Hidden; - - if (LLTools.IsLinux) { - startInfo.FileName = "wine"; - startInfo.Arguments = String.Format("Decompress.exe {0} {1} a", pixels, filename); - startInfo.EnvironmentVariables.Add("WINEDEBUG", "fixme-all,err-winediag"); + byte[] inputData = File.ReadAllBytes(filename); + AEC.LritRiceDecompress(ref outputData, inputData, 8, 16, pixels, AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK); + } catch (Exception e) { + if (e is AECException) { + AECException aece = (AECException)e; + UIConsole.GlobalConsole.Error(string.Format("AEC Decompress Error: {0}", aece.status.ToString())); } else { - startInfo.FileName = "Decompress.exe"; - startInfo.Arguments = String.Format("{0} {1} a", pixels, filename); + UIConsole.GlobalConsole.Error(string.Format("Decompress error: {0}", e.ToString())); } + } - startInfo.RedirectStandardError = true; - startInfo.RedirectStandardOutput = true; - startInfo.CreateNoWindow = true; - startInfo.UseShellExecute = false; - - decompressor.StartInfo = startInfo; + File.WriteAllBytes(outputFile, outputData); + return outputFile; + } - UIConsole.GlobalConsole.Debug(String.Format("Calling {0}", startInfo.Arguments)); - decompressor.Start(); - decompressor.WaitForExit(); - if (decompressor.ExitCode != 0) { - string stderr = decompressor.StandardError.ReadToEnd(); - UIConsole.GlobalConsole.Error(String.Format("Error Decompressing: {0}", stderr)); - } else { - UIConsole.GlobalConsole.Debug(String.Format("Decompress sucessful to {0}", String.Format("{0}_decomp.lrit", filename))); - try { - File.Delete(filename); - } catch (Exception e) { - Console.WriteLine("Cannot delete file {0}: {1}", filename, e); - } - } + public static string Decompressor(string prefix, int pixels, int startnum, int endnum) { + /** + * Temporary Workarround. Needs to change directly on Demuxer + */ - } catch (Exception e) { - UIConsole.GlobalConsole.Error(String.Format("Error running decompressor: {0}", e)); - } + string outputFile = String.Format("{0}_decomp{1}.lrit", prefix, startnum); + try { + byte[] input = File.ReadAllBytes(string.Format("{0}{1}.lrit", prefix, startnum)); + byte[] outputData = new byte[pixels]; - return String.Format("{0}_decomp.lrit", filename); - } + FileStream f = File.OpenWrite(outputFile); + startnum++; + // First file only contains header + f.Write(input, 0, input.Length); + int overflowCaseLast = -1; - public static string Decompressor(string prefix, int pixels, int startnum, int endnum) { - try { - Process decompressor = new Process(); - ProcessStartInfo startInfo = new ProcessStartInfo(); - startInfo.WindowStyle = ProcessWindowStyle.Hidden; - if (LLTools.IsLinux) { - startInfo.FileName = "wine"; - startInfo.Arguments = String.Format("Decompress.exe {0} {1} {2} {3} a", prefix, pixels, startnum + 1, endnum); - startInfo.EnvironmentVariables.Add("WINEDEBUG", "fixme-all,err-winediag"); - } else { - startInfo.FileName = "Decompress.exe"; - startInfo.Arguments = String.Format("{0} {1} {2} {3} a", prefix, pixels, startnum + 1, endnum); + // Check for overflow in file number + if (endnum < startnum) { + overflowCaseLast = endnum; + endnum = 16383; } - startInfo.RedirectStandardError = true; - startInfo.RedirectStandardOutput = true; - startInfo.CreateNoWindow = true; - startInfo.UseShellExecute = false; + for (int i = startnum; i <= endnum; i++) { + string ifile = string.Format("{0}{1}.lrit", prefix, i); + input = File.ReadAllBytes(ifile); - decompressor.StartInfo = startInfo; + for (int z = 0; z < outputData.Length; z++) { + outputData[z] = 0x00; + } - UIConsole.GlobalConsole.Debug(String.Format("Calling {0}", startInfo.Arguments)); - decompressor.Start(); - decompressor.WaitForExit(); + try { + AEC.LritRiceDecompress(ref outputData, input, 8, 16, pixels, AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK); + } catch (AECException e) { + Console.WriteLine("AEC Decompress problem decompressing file {0}: {1}", ifile, e.status.ToString()); + Console.WriteLine("AEC Params: {0} - {1} - {2}", 8, 16, pixels); + } + + f.Write(outputData, 0, outputData.Length); + } + + if (overflowCaseLast != -1) { + for (int i = 0; i < overflowCaseLast; i++) { + string ifile = string.Format("{0}{1}.lrit", prefix, i); + input = File.ReadAllBytes(ifile); + for (int z = 0; z < outputData.Length; z++) { + outputData[z] = 0x00; + } - if (decompressor.ExitCode != 0) { - string stderr = decompressor.StandardError.ReadToEnd(); - UIConsole.GlobalConsole.Error(String.Format("Error Decompressing: {0}", stderr)); - } else { - UIConsole.GlobalConsole.Debug(String.Format("Decompress sucessful to {0}", String.Format("{0}_decomp{1}.lrit", prefix, startnum))); - for (int i=startnum; i Date: Thu, 23 Feb 2017 00:52:52 -0300 Subject: [PATCH 2/2] Changed assembly version to 1.0.2 --- goesdump/Properties/AssemblyInfo.cs | 6 +++--- goesdump/UIComponents/MouseCursor.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/goesdump/Properties/AssemblyInfo.cs b/goesdump/Properties/AssemblyInfo.cs index d11b816..77c0cf6 100644 --- a/goesdump/Properties/AssemblyInfo.cs +++ b/goesdump/Properties/AssemblyInfo.cs @@ -7,8 +7,8 @@ [assembly: AssemblyTitle ("GOES Dumper")] [assembly: AssemblyDescription ("OpenSatelliteProject GOES Data Dumper")] [assembly: AssemblyConfiguration ("")] -[assembly: AssemblyCompany ("")] -[assembly: AssemblyProduct ("")] +[assembly: AssemblyCompany ("OpenSatelliteProject")] +[assembly: AssemblyProduct ("GOES Dumper")] [assembly: AssemblyCopyright ("Lucas Teske")] [assembly: AssemblyTrademark ("")] [assembly: AssemblyCulture ("")] @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion ("1.0.0")] +[assembly: AssemblyVersion ("1.0.2")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. diff --git a/goesdump/UIComponents/MouseCursor.cs b/goesdump/UIComponents/MouseCursor.cs index 61bd0fc..64d5589 100644 --- a/goesdump/UIComponents/MouseCursor.cs +++ b/goesdump/UIComponents/MouseCursor.cs @@ -27,8 +27,8 @@ public void draw(SpriteBatch spriteBatch, Microsoft.Xna.Framework.GameTime gameT #region Updatable implementation public void update(Microsoft.Xna.Framework.GameTime gameTime) { - Point mPos = Mouse.GetState().Position; - position = new Rectangle(mPos.X, mPos.Y, cursorSize, cursorSize); + //Point mPos = Mouse.GetState().Position; + //position = new Rectangle(mPos.X, mPos.Y, cursorSize, cursorSize); } #endregion