Skip to content

Commit

Permalink
Merge pull request #7 from opensatelliteproject/libdecompress
Browse files Browse the repository at this point in the history
Libdecompress
  • Loading branch information
racerxdl authored Feb 23, 2017
2 parents e7e1382 + 21e583f commit 697d928
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 86 deletions.
58 changes: 58 additions & 0 deletions XRIT/Tools/AEC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Runtime.InteropServices;

namespace OpenSatelliteProject.Tools {
/// <summary>
/// libaec Wrapper Class
///
/// Used for decompressing LRIT Rice
/// </summary>
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,
}
}

3 changes: 3 additions & 0 deletions XRIT/XRIT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -26,6 +27,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down Expand Up @@ -73,6 +75,7 @@
<Compile Include="Tools\LLTools.cs" />
<Compile Include="Tools\ImageHandler.cs" />
<Compile Include="Tools\TextHandler.cs" />
<Compile Include="Tools\AEC.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion XRITLibraryTest/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 8 additions & 12 deletions goesdump.userprefs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<Properties StartupItem="goesdump/GOES Dumper.csproj" RefactoringSettings.EnableRefactorings="True">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="XRIT/Tools/TextHandler.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="XRIT/Tools/AEC.cs">
<Files>
<File FileName="XRITLibraryTest/Program.cs" Line="1" Column="1" />
<File FileName="XRIT/Tools/ImageHandler.cs" Line="11" Column="31" />
<File FileName="XRITLibraryTest/MainWindow.cs" Line="16" Column="124" />
<File FileName="XRIT/Tools/LLTools.cs" Line="5" Column="37" />
<File FileName="goesdump/GoesDecoder/FileHandler.cs" Line="37" Column="9" />
<File FileName="goesdump/GoesDecoder/Connector.cs" Line="211" Column="1" />
<File FileName="goesdump/GoesDecoder/PacketManager.cs" Line="168" Column="13" />
<File FileName="goesdump/ChannelDecoder/DemuxManager.cs" Line="1" Column="1" />
<File FileName="goesdump/ChannelDecoder/Demuxer.cs" Line="109" Column="23" />
<File FileName="XRIT/Tools/TextHandler.cs" Line="3" Column="38" />
<File FileName="XRIT/Tools/AEC.cs" Line="28" Column="39" />
<File FileName="XRITLibraryTest/MainWindow.cs" Line="28" Column="16" />
<File FileName="goesdump/ChannelDecoder/Demuxer.cs" Line="137" Column="73" />
<File FileName="goesdump/GoesDecoder/PacketManager.cs" Line="291" Column="156" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<MonoDevelop.Ide.DebuggingService.PinnedWatches>
<Watch file="XRIT/Tools/AEC.cs" line="32" offsetX="528" offsetY="496" expression="param" liveUpdate="False" />
</MonoDevelop.Ide.DebuggingService.PinnedWatches>
</Properties>
141 changes: 73 additions & 68 deletions goesdump/GoesDecoder/PacketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<endnum+1; i++) {
string f = string.Format("{0}{1}.lrit", prefix, i);
try {
File.Delete(f);
} catch (Exception e) {
Console.WriteLine("Error deleting file {0}: {1}", f, e);
AEC.LritRiceDecompress(ref outputData, input, 8, 16, pixels, AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK);
File.Delete(ifile);
} catch (AECException e) {
Console.WriteLine("AEC Decompress problem decompressing file {0}", ifile);
} catch (IOException e) {
Console.WriteLine("Error deleting file {0}: {1}", ifile, e);
}

f.Write(outputData, 0, outputData.Length);
}
}

f.Close();

} catch (Exception e) {
UIConsole.GlobalConsole.Error(String.Format("Error running decompressor: {0}", e));
UIConsole.GlobalConsole.Error(string.Format("There was an error decompressing data: {0}", e));
}


return String.Format("{0}_decomp{1}.lrit", prefix, startnum);
return outputFile;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions goesdump/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("")]
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions goesdump/UIComponents/MouseCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 697d928

Please sign in to comment.