|
|
@ -5,7 +5,6 @@ using System; |
|
|
using System.Runtime.CompilerServices; |
|
|
using System.Runtime.CompilerServices; |
|
|
using System.Runtime.InteropServices; |
|
|
using System.Runtime.InteropServices; |
|
|
using SixLabors.ImageSharp.Memory; |
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
|
|
|
|
|
#if SUPPORTS_RUNTIME_INTRINSICS
|
|
|
#if SUPPORTS_RUNTIME_INTRINSICS
|
|
|
using System.Runtime.Intrinsics; |
|
|
using System.Runtime.Intrinsics; |
|
|
using System.Runtime.Intrinsics.X86; |
|
|
using System.Runtime.Intrinsics.X86; |
|
|
@ -67,31 +66,27 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless |
|
|
{ |
|
|
{ |
|
|
if (distance < PrefixLookupIdxMax) |
|
|
if (distance < PrefixLookupIdxMax) |
|
|
{ |
|
|
{ |
|
|
(int code, int extraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; |
|
|
(int Code, int ExtraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; |
|
|
extraBits = prefixCode.extraBits; |
|
|
extraBits = prefixCode.ExtraBits; |
|
|
return prefixCode.code; |
|
|
return prefixCode.Code; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return PrefixEncodeBitsNoLut(distance, ref extraBits); |
|
|
return PrefixEncodeBitsNoLut(distance, ref extraBits); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static int PrefixEncode(int distance, ref int extraBits, ref int extraBitsValue) |
|
|
public static int PrefixEncode(int distance, ref int extraBits, ref int extraBitsValue) |
|
|
{ |
|
|
{ |
|
|
if (distance < PrefixLookupIdxMax) |
|
|
if (distance < PrefixLookupIdxMax) |
|
|
{ |
|
|
{ |
|
|
(int code, int extraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; |
|
|
(int Code, int ExtraBits) prefixCode = WebpLookupTables.PrefixEncodeCode[distance]; |
|
|
extraBits = prefixCode.extraBits; |
|
|
extraBits = prefixCode.ExtraBits; |
|
|
extraBitsValue = WebpLookupTables.PrefixEncodeExtraBitsValue[distance]; |
|
|
extraBitsValue = WebpLookupTables.PrefixEncodeExtraBitsValue[distance]; |
|
|
|
|
|
|
|
|
return prefixCode.code; |
|
|
return prefixCode.Code; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return PrefixEncodeNoLut(distance, ref extraBits, ref extraBitsValue); |
|
|
return PrefixEncodeNoLut(distance, ref extraBits, ref extraBitsValue); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Add green to blue and red channels (i.e. perform the inverse transform of 'subtract green').
|
|
|
/// Add green to blue and red channels (i.e. perform the inverse transform of 'subtract green').
|
|
|
@ -402,9 +397,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless |
|
|
var maskalphagreen = Vector128.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255); |
|
|
var maskalphagreen = Vector128.Create(0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255); |
|
|
var maskredblue = Vector128.Create(255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0); |
|
|
var maskredblue = Vector128.Create(255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0); |
|
|
byte shufflemask = SimdUtils.Shuffle.MmShuffle(2, 2, 0, 0); |
|
|
byte shufflemask = SimdUtils.Shuffle.MmShuffle(2, 2, 0, 0); |
|
|
int idx; |
|
|
|
|
|
fixed (uint* src = data) |
|
|
fixed (uint* src = data) |
|
|
{ |
|
|
{ |
|
|
|
|
|
int idx; |
|
|
for (idx = 0; idx + 4 <= numPixels; idx += 4) |
|
|
for (idx = 0; idx + 4 <= numPixels; idx += 4) |
|
|
{ |
|
|
{ |
|
|
uint* pos = src + idx; |
|
|
uint* pos = src + idx; |
|
|
@ -535,6 +530,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless |
|
|
Span<uint> outputSpan) |
|
|
Span<uint> outputSpan) |
|
|
{ |
|
|
{ |
|
|
fixed (uint* inputFixed = pixelData) |
|
|
fixed (uint* inputFixed = pixelData) |
|
|
|
|
|
{ |
|
|
fixed (uint* outputFixed = outputSpan) |
|
|
fixed (uint* outputFixed = outputSpan) |
|
|
{ |
|
|
{ |
|
|
uint* input = inputFixed; |
|
|
uint* input = inputFixed; |
|
|
@ -636,6 +632,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
outputSpan.CopyTo(pixelData); |
|
|
outputSpan.CopyTo(pixelData); |
|
|
} |
|
|
} |
|
|
@ -839,11 +836,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless |
|
|
|
|
|
|
|
|
return (float)log2; |
|
|
return (float)log2; |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return (float)(Log2Reciprocal * Math.Log(v)); |
|
|
return (float)(Log2Reciprocal * Math.Log(v)); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Splitting of distance and length codes into prefixes and
|
|
|
/// Splitting of distance and length codes into prefixes and
|
|
|
|