diff --git a/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs b/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs
index 5fc68e0956..abf44127a9 100644
--- a/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs
+++ b/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs
@@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitReader
range = split + 1;
}
- int shift = 7 ^ WebpCommonUtils.BitsLog2Floor(range);
+ int shift = 7 ^ Numerics.Log2(range);
range <<= shift;
this.bits -= shift;
diff --git a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs
index 43e87061ce..b7f94415be 100644
--- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs
+++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs
@@ -847,7 +847,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
///
private static int PrefixEncodeBitsNoLut(int distance, ref int extraBits)
{
- int highestBit = WebpCommonUtils.BitsLog2Floor((uint)--distance);
+ int highestBit = Numerics.Log2((uint)--distance);
int secondHighestBit = (distance >> (highestBit - 1)) & 1;
extraBits = highestBit - 1;
int code = (2 * highestBit) + secondHighestBit;
@@ -856,7 +856,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static int PrefixEncodeNoLut(int distance, ref int extraBits, ref int extraBitsValue)
{
- int highestBit = WebpCommonUtils.BitsLog2Floor((uint)--distance);
+ int highestBit = Numerics.Log2((uint)--distance);
int secondHighestBit = (distance >> (highestBit - 1)) & 1;
extraBits = highestBit - 1;
extraBitsValue = distance & ((1 << extraBits) - 1);
diff --git a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
index ccf74e14e2..c95b8e3621 100644
--- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
+++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
@@ -330,7 +330,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// If using a color cache, do not have it bigger than the number of colors.
if (useCache && this.PaletteSize < 1 << WebpConstants.MaxColorCacheBits)
{
- this.CacheBits = WebpCommonUtils.BitsLog2Floor((uint)this.PaletteSize) + 1;
+ this.CacheBits = Numerics.Log2((uint)this.PaletteSize) + 1;
}
}
@@ -893,7 +893,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
else
{
- int nBits = WebpCommonUtils.BitsLog2Floor((uint)trimmedLength - 2);
+ int nBits = Numerics.Log2((uint)trimmedLength - 2);
int nBitPairs = (nBits / 2) + 1;
this.bitWriter.PutBits((uint)nBitPairs - 1, 3);
this.bitWriter.PutBits((uint)trimmedLength - 2, nBitPairs * 2);
diff --git a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs
index cdd324b07e..d6e8d0a068 100644
--- a/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs
+++ b/src/ImageSharp/Formats/Webp/WebpCommonUtils.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
#if SUPPORTS_RUNTIME_INTRINSICS
@@ -17,22 +16,6 @@ namespace SixLabors.ImageSharp.Formats.Webp
///
internal static class WebpCommonUtils
{
- ///
- /// Returns 31 ^ clz(n) = log2(n).Returns 31 ^ clz(n) = log2(n).
- ///
- [MethodImpl(InliningOptions.ShortMethod)]
- public static int BitsLog2Floor(uint n)
- {
- int logValue = 0;
- while (n >= 256)
- {
- logValue += 8;
- n >>= 8;
- }
-
- return logValue + Unsafe.Add(ref MemoryMarshal.GetReference(WebpLookupTables.LogTable8Bit), (int)n);
- }
-
///
/// Checks if the pixel row is not opaque.
///