Dirk Lemstra
4 years ago
No known key found for this signature in database
GPG Key ID: 40B84DE7D6271D30
5 changed files with
14 additions and
9 deletions
-
src/ImageSharp/Formats/Webp/BitReader/Vp8BitReader.cs
-
src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs
-
src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs
-
src/ImageSharp/Formats/Webp/Lossy/Vp8Residual.cs
-
tests/ImageSharp.Tests/Common/NumericsTests.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; |
|
|
|
|
|
|
|
|
|
|
|
@ -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 |
|
|
|
/// </summary>
|
|
|
|
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); |
|
|
|
|
|
|
|
@ -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); |
|
|
|
|
|
|
|
@ -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 |
|
|
|
{ |
|
|
|
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|