From 303140000986c4f23bba7fbf0f89e6ef1e174fae Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sat, 3 Sep 2022 10:20:56 +0200 Subject: [PATCH] Did not push all files.... --- src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs | 3 ++- src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs | 5 +++-- src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs | 5 +++-- src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs | 3 ++- tests/ImageSharp.Tests/Common/NumericsTests.cs | 7 ++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs b/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs index e1639b8990..52e3907e96 100644 --- a/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs +++ b/src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs @@ -4,6 +4,7 @@ using System.Buffers; using System.Buffers.Binary; using System.IO; +using System.Numerics; using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Memory; @@ -111,7 +112,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitReader range = split + 1; } - int shift = 7 ^ Numerics.Log2(range); + int shift = 7 ^ BitOperations.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 c6d0d1cfa1..cb826f75d1 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -1041,7 +1042,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless /// private static int PrefixEncodeBitsNoLut(int distance, ref int extraBits) { - int highestBit = Numerics.Log2((uint)--distance); + int highestBit = BitOperations.Log2((uint)--distance); int secondHighestBit = (distance >> (highestBit - 1)) & 1; extraBits = highestBit - 1; int code = (2 * highestBit) + secondHighestBit; @@ -1050,7 +1051,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless private static int PrefixEncodeNoLut(int distance, ref int extraBits, ref int extraBitsValue) { - int highestBit = Numerics.Log2((uint)--distance); + int highestBit = BitOperations.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 473c92d8de..a09cdb8bcb 100644 --- a/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs +++ b/src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs @@ -6,6 +6,7 @@ using System.Buffers; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Formats.Webp.BitWriter; @@ -382,7 +383,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 = Numerics.Log2((uint)this.PaletteSize) + 1; + this.CacheBits = BitOperations.Log2((uint)this.PaletteSize) + 1; } } @@ -951,7 +952,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless } else { - int nBits = Numerics.Log2((uint)trimmedLength - 2); + int nBits = BitOperations.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/Lossy/Vp8Residual.cs b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs index 42116932a1..9541ee1f7b 100644 --- a/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs +++ b/src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System; +using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -62,7 +63,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy // The position of the most significant non-zero bit indicates the position of // the last non-zero value. - this.Last = mask != 0 ? Numerics.Log2(mask) : -1; + this.Last = mask != 0 ? BitOperations.Log2(mask) : -1; } else { diff --git a/tests/ImageSharp.Tests/Common/NumericsTests.cs b/tests/ImageSharp.Tests/Common/NumericsTests.cs index e8643de279..30345390ae 100644 --- a/tests/ImageSharp.Tests/Common/NumericsTests.cs +++ b/tests/ImageSharp.Tests/Common/NumericsTests.cs @@ -2,6 +2,7 @@ // Licensed under the Six Labors Split License. using System; +using System.Numerics; using Xunit; using Xunit.Abstractions; @@ -34,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Common { uint value = 0; int expected = 0; - int actual = Numerics.Log2(value); + int actual = BitOperations.Log2(value); Assert.Equal(expected, actual); } @@ -47,7 +48,7 @@ namespace SixLabors.ImageSharp.Tests.Common // from 2^0 to 2^32 uint value = (uint)(1 << i); int expected = i; - int actual = Numerics.Log2(value); + int actual = BitOperations.Log2(value); Assert.Equal(expected, actual); } @@ -66,7 +67,7 @@ namespace SixLabors.ImageSharp.Tests.Common rng.NextBytes(bytes); uint value = BitConverter.ToUInt32(bytes, 0); int expected = Log2_ReferenceImplementation(value); - int actual = Numerics.Log2(value); + int actual = BitOperations.Log2(value); Assert.Equal(expected, actual); }