General cleanup and refactor.

This commit is contained in:
2022-03-07 07:36:44 +00:00
parent bc6e432565
commit 762e3eb6d2
1321 changed files with 44657 additions and 45479 deletions

View File

@@ -31,23 +31,20 @@
// Copyright © 2018-2019 David Ryskalczyk
// ****************************************************************************/
using System.Runtime.InteropServices;
namespace Aaru.Compression;
using System.Runtime.InteropServices;
/// <summary>Implements the Apple version of RLE</summary>
public static class AppleRle
{
/// <summary>
/// Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.
/// </summary>
const uint DART_CHUNK = 20960;
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
public static bool IsSupported => true;
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int AARU_apple_rle_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size);
const uint DART_CHUNK = 20960;
/// <summary>Decodes a buffer compressed with Apple RLE</summary>
/// <param name="source">Encoded buffer</param>
/// <param name="destination">Buffer where to write the decoded data</param>
@@ -57,10 +54,10 @@ public static class AppleRle
if(Native.IsSupported)
return AARU_apple_rle_decode_buffer(destination, destination.Length, source, source.Length);
int count = 0;
bool nextA = true; // true if A, false if B
var count = 0;
var nextA = true; // true if A, false if B
byte repeatedByteA = 0, repeatedByteB = 0;
bool repeatMode = false; // true if we're repeating, false if we're just copying
var repeatMode = false; // true if we're repeating, false if we're just copying
int inPosition = 0, outPosition = 0;
while(inPosition <= source.Length &&
@@ -100,9 +97,9 @@ public static class AppleRle
while(true)
{
byte b1 = source[inPosition++];
byte b2 = source[inPosition++];
short s = (short)((b1 << 8) | b2);
byte b1 = source[inPosition++];
byte b2 = source[inPosition++];
var s = (short)((b1 << 8) | b2);
if(s == 0 ||
s >= DART_CHUNK ||
@@ -114,7 +111,7 @@ public static class AppleRle
repeatMode = true;
repeatedByteA = source[inPosition++];
repeatedByteB = source[inPosition++];
count = (-s * 2) - 1;
count = -s * 2 - 1;
nextA = false;
destination[outPosition++] = repeatedByteA;
@@ -123,7 +120,7 @@ public static class AppleRle
}
repeatMode = false;
count = (s * 2) - 1;
count = s * 2 - 1;
destination[outPosition++] = source[inPosition++];