[Refactor] Use LibraryImport instead of DllImport.

This commit is contained in:
2024-05-01 05:36:13 +01:00
parent 01116106d7
commit c2e6e12b37
23 changed files with 326 additions and 258 deletions

View File

@@ -44,7 +44,7 @@ namespace Aaru.Compression;
/// <summary>Implements the Apple version of RLE</summary>
// ReSharper disable once InconsistentNaming
public static class ADC
public static partial class ADC
{
const int PLAIN = 1;
const int TWO_BYTE = 2;
@@ -53,8 +53,8 @@ public static class ADC
/// <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_adc_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_adc_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static int GetChunkType(byte byt) => (byt & 0x80) == 0x80

View File

@@ -36,15 +36,16 @@ using System.Runtime.InteropServices;
namespace Aaru.Compression;
/// <summary>Implements the Apple version of RLE</summary>
public static class AppleRle
public static partial class AppleRle
{
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[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_apple_rle_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer,
int srcSize);
/// <summary>Decodes a buffer compressed with Apple RLE</summary>
/// <param name="source">Encoded buffer</param>

View File

@@ -33,17 +33,18 @@ using Ionic.BZip2;
namespace Aaru.Compression;
/// <summary>Implements the BZIP2 compression algorithm</summary>
public class BZip2
public partial class BZip2
{
/// <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_bzip2_decode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer, uint srcSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_bzip2_decode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer,
uint srcSize);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int AARU_bzip2_encode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer, uint srcSize,
int blockSize100K);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_bzip2_encode_buffer(byte[] dstBuffer, ref uint dstSize, byte[] srcBuffer,
uint srcSize, int blockSize100K);
/// <summary>Decodes a buffer compressed with BZIP2</summary>
/// <param name="source">Encoded buffer</param>

View File

@@ -36,23 +36,24 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// <summary>Implements the FLAC lossless audio compression algorithm</summary>
public class FLAC
public partial class FLAC
{
/// <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 nuint AARU_flac_decode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial nuint AARU_flac_decode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_flac_encode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize, uint blocksize, int doMidSideStereo,
int looseMidSideStereo, string apodization, uint maxLpcOrder,
uint qlpCoeffPrecision, int doQlpCoeffPrecSearch,
int doExhaustiveModelSearch, uint minResidualPartitionOrder,
uint maxResidualPartitionOrder, string applicationID,
uint applicationIDLen);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial nuint AARU_flac_encode_redbook_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize, uint blocksize, int doMidSideStereo,
int looseMidSideStereo, string apodization,
uint maxLpcOrder, uint qlpCoeffPrecision,
int doQlpCoeffPrecSearch, int doExhaustiveModelSearch,
uint minResidualPartitionOrder,
uint maxResidualPartitionOrder, string applicationID,
uint applicationIDLen);
/// <summary>Decodes a buffer compressed with FLAC</summary>
/// <param name="source">Encoded buffer</param>

View File

@@ -32,18 +32,18 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// <summary>Implements the LZFSE compression algorithm</summary>
public class LZFSE
public partial class LZFSE
{
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
public static bool IsSupported => Native.IsSupported;
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_lzfse_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
byte[] scratchBuffer);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial nuint AARU_lzfse_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize, byte[] scratchBuffer);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_lzfse_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
byte[] scratchBuffer);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial nuint AARU_lzfse_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize, byte[] scratchBuffer);
/// <summary>Decodes a buffer compressed with LZFSE</summary>
/// <param name="source">Encoded buffer</param>

View File

@@ -32,17 +32,17 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// <summary>Implements the LZIP compression algorithm</summary>
public class LZIP
public partial class LZIP
{
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
public static bool IsSupported => Native.IsSupported;
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int AARU_lzip_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_lzip_decode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int AARU_lzip_encode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize,
int dictionarySize, int matchLenLimit);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_lzip_encode_buffer(byte[] dstBuffer, int dstSize, byte[] srcBuffer, int srcSize,
int dictionarySize, int matchLenLimit);
/// <summary>Decodes a buffer compressed with LZIP</summary>
/// <param name="source">Encoded buffer</param>

View File

@@ -34,19 +34,20 @@ using SharpCompress.Compressors.LZMA;
namespace Aaru.Compression;
/// <summary>Implements the LZMA compression algorithm</summary>
public class LZMA
public partial class LZMA
{
/// <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_lzma_decode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer, ref nuint srcSize,
byte[] props, nuint propsSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_lzma_decode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer,
ref nuint srcSize, byte[] props, nuint propsSize);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int AARU_lzma_encode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer, nuint srcSize,
byte[] outProps, ref nuint outPropsSize, int level, uint dictSize, int lc,
int lp, int pb, int fb, int numThreads);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial int AARU_lzma_encode_buffer(byte[] dstBuffer, ref nuint dstSize, byte[] srcBuffer,
nuint srcSize, byte[] outProps, ref nuint outPropsSize,
int level, uint dictSize, int lc, int lp, int pb, int fb,
int numThreads);
/// <summary>Decodes a buffer compressed with LZMA</summary>
/// <param name="source">Encoded buffer</param>

View File

@@ -35,7 +35,7 @@ using System.Runtime.InteropServices;
namespace Aaru.Compression;
/// <summary>Handles native implementations of compression algorithms</summary>
public static class Native
public static partial class Native
{
static bool _checked;
static bool _supported;
@@ -76,6 +76,6 @@ public static class Native
}
}
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern ulong AARU_get_acn_version();
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial ulong AARU_get_acn_version();
}

View File

@@ -32,17 +32,18 @@ namespace Aaru.Compression;
// ReSharper disable once InconsistentNaming
/// <summary>Implements the zstandard compression algorithm</summary>
public class ZSTD
public partial class ZSTD
{
/// <summary>Set to <c>true</c> if this algorithm is supported, <c>false</c> otherwise.</summary>
public static bool IsSupported => Native.IsSupported;
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_zstd_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial nuint AARU_zstd_decode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_zstd_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer, nuint srcSize,
int compressionLevel);
[LibraryImport("libAaru.Compression.Native", SetLastError = true)]
private static partial nuint AARU_zstd_encode_buffer(byte[] dstBuffer, nuint dstSize, byte[] srcBuffer,
nuint srcSize, int compressionLevel);
/// <summary>Decodes a buffer compressed with ZSTD</summary>
/// <param name="source">Encoded buffer</param>