Skip to content

Commit 697d928

Browse files
authored
Merge pull request #7 from opensatelliteproject/libdecompress
Libdecompress
2 parents e7e1382 + 21e583f commit 697d928

File tree

7 files changed

+148
-86
lines changed

7 files changed

+148
-86
lines changed

XRIT/Tools/AEC.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace OpenSatelliteProject.Tools {
5+
/// <summary>
6+
/// libaec Wrapper Class
7+
///
8+
/// Used for decompressing LRIT Rice
9+
/// </summary>
10+
public static class AEC {
11+
public static readonly int ALLOW_K13_OPTION_MASK = 1;
12+
public static readonly int CHIP_OPTION_MASK = 2;
13+
public static readonly int EC_OPTION_MASK = 4;
14+
public static readonly int LSB_OPTION_MASK = 8;
15+
public static readonly int MSB_OPTION_MASK = 16;
16+
public static readonly int NN_OPTION_MASK = 32;
17+
public static readonly int RAW_OPTION_MASK = 128;
18+
19+
[DllImport("satdecompress", CallingConvention = CallingConvention.Cdecl)]
20+
public static unsafe extern int Decompress(byte *input, byte *output, uint inputLength, uint outputLength, int bitsPerPixel, int pixelsPerBlock, int pixelsPerScanline, int mask);
21+
22+
public static int LritRiceDecompress(ref byte[] dest, byte[] source, int bitsPerPixel, int pixelsPerBlock, int pixelsPerScanline, int mask) {
23+
int status = -100;
24+
unsafe {
25+
fixed (byte* destPtr = dest) {
26+
fixed (byte *srcPtr = source) {
27+
status = Decompress(srcPtr, destPtr, (uint) source.Length, (uint) dest.Length, bitsPerPixel, pixelsPerBlock, pixelsPerScanline, mask);
28+
}
29+
}
30+
}
31+
32+
if (status <= 0) {
33+
throw new AECException((AECStatus)status);
34+
}
35+
36+
return status;
37+
}
38+
}
39+
40+
public class AECException: Exception {
41+
public AECStatus status;
42+
43+
public AECException(AECStatus error) {
44+
this.status = error;
45+
}
46+
}
47+
48+
public enum AECStatus {
49+
INTERNAL_ERROR = -100,
50+
MEMORY_ERROR = -4,
51+
DATA_ERROR = -3,
52+
STREAM_ERROR = -2,
53+
CONFIG_ERROR = -1,
54+
OK = 0,
55+
OUTPUT_BUFFER_FULL = 2,
56+
}
57+
}
58+

XRIT/XRIT.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ErrorReport>prompt</ErrorReport>
1919
<WarningLevel>4</WarningLevel>
2020
<ConsolePause>false</ConsolePause>
21+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2122
</PropertyGroup>
2223
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2324
<DebugType>full</DebugType>
@@ -26,6 +27,7 @@
2627
<ErrorReport>prompt</ErrorReport>
2728
<WarningLevel>4</WarningLevel>
2829
<ConsolePause>false</ConsolePause>
30+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2931
</PropertyGroup>
3032
<ItemGroup>
3133
<Reference Include="System" />
@@ -73,6 +75,7 @@
7375
<Compile Include="Tools\LLTools.cs" />
7476
<Compile Include="Tools\ImageHandler.cs" />
7577
<Compile Include="Tools\TextHandler.cs" />
78+
<Compile Include="Tools\AEC.cs" />
7679
</ItemGroup>
7780
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7881
<ItemGroup>

XRITLibraryTest/MainWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public MainWindow() : base(Gtk.WindowType.Toplevel) {
1919
private void ProcessFile(string filename) {
2020
string outputFolder = System.IO.Path.GetDirectoryName(filename);
2121
//ImageHandler.Handler.HandleFile(filename, outputFolder);
22-
TextHandler.Handler.HandleFile(filename, outputFolder);
22+
//TextHandler.Handler.HandleFile(filename, outputFolder);
2323
}
2424

2525
protected void OnDeleteEvent(object sender, DeleteEventArgs a) {

goesdump.userprefs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
<Properties StartupItem="goesdump/GOES Dumper.csproj" RefactoringSettings.EnableRefactorings="True">
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="XRIT/Tools/TextHandler.cs">
3+
<MonoDevelop.Ide.Workbench ActiveDocument="XRIT/Tools/AEC.cs">
44
<Files>
5-
<File FileName="XRITLibraryTest/Program.cs" Line="1" Column="1" />
6-
<File FileName="XRIT/Tools/ImageHandler.cs" Line="11" Column="31" />
7-
<File FileName="XRITLibraryTest/MainWindow.cs" Line="16" Column="124" />
8-
<File FileName="XRIT/Tools/LLTools.cs" Line="5" Column="37" />
9-
<File FileName="goesdump/GoesDecoder/FileHandler.cs" Line="37" Column="9" />
10-
<File FileName="goesdump/GoesDecoder/Connector.cs" Line="211" Column="1" />
11-
<File FileName="goesdump/GoesDecoder/PacketManager.cs" Line="168" Column="13" />
12-
<File FileName="goesdump/ChannelDecoder/DemuxManager.cs" Line="1" Column="1" />
13-
<File FileName="goesdump/ChannelDecoder/Demuxer.cs" Line="109" Column="23" />
14-
<File FileName="XRIT/Tools/TextHandler.cs" Line="3" Column="38" />
5+
<File FileName="XRIT/Tools/AEC.cs" Line="28" Column="39" />
6+
<File FileName="XRITLibraryTest/MainWindow.cs" Line="28" Column="16" />
7+
<File FileName="goesdump/ChannelDecoder/Demuxer.cs" Line="137" Column="73" />
8+
<File FileName="goesdump/GoesDecoder/PacketManager.cs" Line="291" Column="156" />
159
</Files>
1610
</MonoDevelop.Ide.Workbench>
1711
<MonoDevelop.Ide.DebuggingService.Breakpoints>
1812
<BreakpointStore />
1913
</MonoDevelop.Ide.DebuggingService.Breakpoints>
20-
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
14+
<MonoDevelop.Ide.DebuggingService.PinnedWatches>
15+
<Watch file="XRIT/Tools/AEC.cs" line="32" offsetX="528" offsetY="496" expression="param" liveUpdate="False" />
16+
</MonoDevelop.Ide.DebuggingService.PinnedWatches>
2117
</Properties>

goesdump/GoesDecoder/PacketManager.cs

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -228,98 +228,103 @@ public static void DumpFile(string filename, XRITHeader fileHeader, string newEx
228228
}
229229

230230
public static string Decompressor(string filename, int pixels) {
231+
/**
232+
* Temporary Workarround. Needs to change directly on Demuxer
233+
*/
234+
string outputFile = String.Format("{0}_decomp.lrit", filename);
235+
byte[] outputData = new byte[pixels];
236+
237+
for (int i = 0; i < pixels; i++) {
238+
outputData[i] = 0x00;
239+
}
240+
231241
try {
232-
Process decompressor = new Process();
233-
ProcessStartInfo startInfo = new ProcessStartInfo();
234-
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
235-
236-
if (LLTools.IsLinux) {
237-
startInfo.FileName = "wine";
238-
startInfo.Arguments = String.Format("Decompress.exe {0} {1} a", pixels, filename);
239-
startInfo.EnvironmentVariables.Add("WINEDEBUG", "fixme-all,err-winediag");
242+
byte[] inputData = File.ReadAllBytes(filename);
243+
AEC.LritRiceDecompress(ref outputData, inputData, 8, 16, pixels, AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK);
244+
} catch (Exception e) {
245+
if (e is AECException) {
246+
AECException aece = (AECException)e;
247+
UIConsole.GlobalConsole.Error(string.Format("AEC Decompress Error: {0}", aece.status.ToString()));
240248
} else {
241-
startInfo.FileName = "Decompress.exe";
242-
startInfo.Arguments = String.Format("{0} {1} a", pixels, filename);
249+
UIConsole.GlobalConsole.Error(string.Format("Decompress error: {0}", e.ToString()));
243250
}
251+
}
244252

245-
startInfo.RedirectStandardError = true;
246-
startInfo.RedirectStandardOutput = true;
247-
startInfo.CreateNoWindow = true;
248-
startInfo.UseShellExecute = false;
249-
250-
decompressor.StartInfo = startInfo;
253+
File.WriteAllBytes(outputFile, outputData);
254+
return outputFile;
255+
}
251256

252-
UIConsole.GlobalConsole.Debug(String.Format("Calling {0}", startInfo.Arguments));
253-
decompressor.Start();
254-
decompressor.WaitForExit();
255257

256-
if (decompressor.ExitCode != 0) {
257-
string stderr = decompressor.StandardError.ReadToEnd();
258-
UIConsole.GlobalConsole.Error(String.Format("Error Decompressing: {0}", stderr));
259-
} else {
260-
UIConsole.GlobalConsole.Debug(String.Format("Decompress sucessful to {0}", String.Format("{0}_decomp.lrit", filename)));
261-
try {
262-
File.Delete(filename);
263-
} catch (Exception e) {
264-
Console.WriteLine("Cannot delete file {0}: {1}", filename, e);
265-
}
266-
}
258+
public static string Decompressor(string prefix, int pixels, int startnum, int endnum) {
259+
/**
260+
* Temporary Workarround. Needs to change directly on Demuxer
261+
*/
267262

268-
} catch (Exception e) {
269-
UIConsole.GlobalConsole.Error(String.Format("Error running decompressor: {0}", e));
270-
}
263+
string outputFile = String.Format("{0}_decomp{1}.lrit", prefix, startnum);
271264

265+
try {
266+
byte[] input = File.ReadAllBytes(string.Format("{0}{1}.lrit", prefix, startnum));
267+
byte[] outputData = new byte[pixels];
272268

273-
return String.Format("{0}_decomp.lrit", filename);
274-
}
269+
FileStream f = File.OpenWrite(outputFile);
270+
startnum++;
271+
// First file only contains header
272+
f.Write(input, 0, input.Length);
275273

274+
int overflowCaseLast = -1;
276275

277-
public static string Decompressor(string prefix, int pixels, int startnum, int endnum) {
278-
try {
279-
Process decompressor = new Process();
280-
ProcessStartInfo startInfo = new ProcessStartInfo();
281-
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
282-
if (LLTools.IsLinux) {
283-
startInfo.FileName = "wine";
284-
startInfo.Arguments = String.Format("Decompress.exe {0} {1} {2} {3} a", prefix, pixels, startnum + 1, endnum);
285-
startInfo.EnvironmentVariables.Add("WINEDEBUG", "fixme-all,err-winediag");
286-
} else {
287-
startInfo.FileName = "Decompress.exe";
288-
startInfo.Arguments = String.Format("{0} {1} {2} {3} a", prefix, pixels, startnum + 1, endnum);
276+
// Check for overflow in file number
277+
if (endnum < startnum) {
278+
overflowCaseLast = endnum;
279+
endnum = 16383;
289280
}
290281

291-
startInfo.RedirectStandardError = true;
292-
startInfo.RedirectStandardOutput = true;
293-
startInfo.CreateNoWindow = true;
294-
startInfo.UseShellExecute = false;
282+
for (int i = startnum; i <= endnum; i++) {
283+
string ifile = string.Format("{0}{1}.lrit", prefix, i);
284+
input = File.ReadAllBytes(ifile);
295285

296-
decompressor.StartInfo = startInfo;
286+
for (int z = 0; z < outputData.Length; z++) {
287+
outputData[z] = 0x00;
288+
}
297289

298-
UIConsole.GlobalConsole.Debug(String.Format("Calling {0}", startInfo.Arguments));
299-
decompressor.Start();
300-
decompressor.WaitForExit();
290+
try {
291+
AEC.LritRiceDecompress(ref outputData, input, 8, 16, pixels, AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK);
292+
} catch (AECException e) {
293+
Console.WriteLine("AEC Decompress problem decompressing file {0}: {1}", ifile, e.status.ToString());
294+
Console.WriteLine("AEC Params: {0} - {1} - {2}", 8, 16, pixels);
295+
}
296+
297+
f.Write(outputData, 0, outputData.Length);
298+
}
299+
300+
if (overflowCaseLast != -1) {
301+
for (int i = 0; i < overflowCaseLast; i++) {
302+
string ifile = string.Format("{0}{1}.lrit", prefix, i);
303+
input = File.ReadAllBytes(ifile);
304+
for (int z = 0; z < outputData.Length; z++) {
305+
outputData[z] = 0x00;
306+
}
301307

302-
if (decompressor.ExitCode != 0) {
303-
string stderr = decompressor.StandardError.ReadToEnd();
304-
UIConsole.GlobalConsole.Error(String.Format("Error Decompressing: {0}", stderr));
305-
} else {
306-
UIConsole.GlobalConsole.Debug(String.Format("Decompress sucessful to {0}", String.Format("{0}_decomp{1}.lrit", prefix, startnum)));
307-
for (int i=startnum; i<endnum+1; i++) {
308-
string f = string.Format("{0}{1}.lrit", prefix, i);
309308
try {
310-
File.Delete(f);
311-
} catch (Exception e) {
312-
Console.WriteLine("Error deleting file {0}: {1}", f, e);
309+
AEC.LritRiceDecompress(ref outputData, input, 8, 16, pixels, AEC.ALLOW_K13_OPTION_MASK | AEC.MSB_OPTION_MASK | AEC.NN_OPTION_MASK);
310+
File.Delete(ifile);
311+
} catch (AECException e) {
312+
Console.WriteLine("AEC Decompress problem decompressing file {0}", ifile);
313+
} catch (IOException e) {
314+
Console.WriteLine("Error deleting file {0}: {1}", ifile, e);
313315
}
316+
317+
f.Write(outputData, 0, outputData.Length);
314318
}
315319
}
316320

321+
f.Close();
322+
317323
} catch (Exception e) {
318-
UIConsole.GlobalConsole.Error(String.Format("Error running decompressor: {0}", e));
324+
UIConsole.GlobalConsole.Error(string.Format("There was an error decompressing data: {0}", e));
319325
}
320326

321-
322-
return String.Format("{0}_decomp{1}.lrit", prefix, startnum);
327+
return outputFile;
323328
}
324329
}
325330
}

goesdump/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
[assembly: AssemblyTitle ("GOES Dumper")]
88
[assembly: AssemblyDescription ("OpenSatelliteProject GOES Data Dumper")]
99
[assembly: AssemblyConfiguration ("")]
10-
[assembly: AssemblyCompany ("")]
11-
[assembly: AssemblyProduct ("")]
10+
[assembly: AssemblyCompany ("OpenSatelliteProject")]
11+
[assembly: AssemblyProduct ("GOES Dumper")]
1212
[assembly: AssemblyCopyright ("Lucas Teske")]
1313
[assembly: AssemblyTrademark ("")]
1414
[assembly: AssemblyCulture ("")]
@@ -17,7 +17,7 @@
1717
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
1818
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
1919

20-
[assembly: AssemblyVersion ("1.0.0")]
20+
[assembly: AssemblyVersion ("1.0.2")]
2121

2222
// The following attributes are used to specify the signing key for the assembly,
2323
// if desired. See the Mono documentation for more information about signing.

goesdump/UIComponents/MouseCursor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public void draw(SpriteBatch spriteBatch, Microsoft.Xna.Framework.GameTime gameT
2727
#region Updatable implementation
2828

2929
public void update(Microsoft.Xna.Framework.GameTime gameTime) {
30-
Point mPos = Mouse.GetState().Position;
31-
position = new Rectangle(mPos.X, mPos.Y, cursorSize, cursorSize);
30+
//Point mPos = Mouse.GetState().Position;
31+
//position = new Rectangle(mPos.X, mPos.Y, cursorSize, cursorSize);
3232
}
3333

3434
#endregion

0 commit comments

Comments
 (0)