Skip to content

Commit

Permalink
Optical tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
halmaia authored Feb 26, 2024
1 parent f09fd71 commit b091e78
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions OtherLanguages/CSharp/LercCS_Impl_B.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public readonly bool UsesNoDataValue
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SkipLocalsInit]
get => UsesNoDataValueInternal is not 0;
get => UsesNoDataValueInternal is not 0u;
}

public readonly MaskType MaskType
Expand All @@ -70,8 +70,8 @@ public readonly MaskType MaskType
[SkipLocalsInit]
get => NMasks switch
{
0 => MaskType.AllValid,
1 => MaskType.SameMaskForAllBands,
0u => MaskType.AllValid,
1u => MaskType.SameMaskForAllBands,
_ => MaskType.UniqueMaskForEveryBand,
};
}
Expand All @@ -91,17 +91,12 @@ public readonly uint DecodedRasterDataSize
_ => ThrowUnsupportedDataType()
});

if (decodedRasterDataSize is 0u)
{
ThrowInvalidBlobSize();

[DoesNotReturn]
[SkipLocalsInit]
static void ThrowInvalidBlobSize() =>
throw new Exception("Invalid blob size. The struct might be uninitialized.");
}
return decodedRasterDataSize is not 0u ? decodedRasterDataSize : ThrowInvalidBlobSize();

return decodedRasterDataSize;
[DoesNotReturn]
[SkipLocalsInit]
static uint ThrowInvalidBlobSize() =>
throw new Exception("Invalid blob size. The struct might be uninitialized.");

[DoesNotReturn]
[SkipLocalsInit]
Expand Down Expand Up @@ -170,7 +165,7 @@ public static unsafe uint ComputeEncodedSize<T>(ReadOnlySpan<T> rasterData,
double maxZErr = 0d,
ReadOnlySpan<byte> pixelMasks = default) where T : unmanaged
{
fixed (void* pData = rasterData)
fixed (T* pData = rasterData)
fixed (byte* pValidBytes = pixelMasks)
{
Unsafe.SkipInit(out uint numBytes);
Expand Down Expand Up @@ -217,7 +212,7 @@ public static unsafe Span<byte> Encode<T>(ReadOnlySpan<T> rasterData,
DataType dataType = GetLercDataType<T>();
int nMasks = MaskTypeToNMask(nBands, maskType);

fixed (void* pData = rasterData)
fixed (T* pData = rasterData)
fixed (byte* pValidBytes = pixelMasks)
{
int bufferLength = encodedLercBlobBuffer.Length;
Expand Down Expand Up @@ -251,7 +246,7 @@ public static unsafe Span<byte> Encode<T>(ReadOnlySpan<T> rasterData,
&nBytesWritten));

int intBytesWritten = (int)nBytesWritten;
return intBytesWritten == bufferLength ?
return intBytesWritten == bufferLength ?
encodedLercBlobBuffer : encodedLercBlobBuffer[..intBytesWritten];
}
}
Expand Down Expand Up @@ -313,8 +308,8 @@ public static unsafe Span<byte> Decode(ReadOnlySpan<byte> encodedLercBlob,
(int)lercBlobInfo.NBands,
lercBlobInfo.DataType,
pData));
return rasterDataBuffer.Length != decodedRasterDataSize ?

return rasterDataBuffer.Length != decodedRasterDataSize ?
rasterDataBuffer[..decodedRasterDataSize] : rasterDataBuffer;
}
}
Expand Down Expand Up @@ -385,7 +380,6 @@ static int ThrowInvalidMaskType() =>
#endregion "Utility functions"

#region "Native P/Invoke"

private const string LercDLL = @"Lerc.dll";
public static bool IsLercDLLAvailable
{
Expand Down

0 comments on commit b091e78

Please sign in to comment.