@ -6,19 +6,19 @@ using System.Buffers.Binary;
using System.Runtime.CompilerServices ;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Formats.Experimental.WebP .Lossy
namespace SixLabors.ImageSharp.Formats.Experimental.Webp .Lossy
{
internal static class LossyUtils
{
public static void DC16 ( Span < byte > dst , Span < byte > yuv , int offset )
{
int offsetMinus1 = offset - 1 ;
int offsetMinusBps = offset - WebP Constants . Bps ;
int offsetMinusBps = offset - Webp Constants . Bps ;
int dc = 1 6 ;
for ( int j = 0 ; j < 1 6 ; + + j )
{
// DC += dst[-1 + j * BPS] + dst[j - BPS];
dc + = yuv [ offsetMinus1 + ( j * WebP Constants . Bps ) ] + yuv [ offsetMinusBps + j ] ;
dc + = yuv [ offsetMinus1 + ( j * Webp Constants . Bps ) ] + yuv [ offsetMinusBps + j ] ;
}
Put16 ( dc > > 5 , dst ) ;
@ -33,11 +33,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void VE16 ( Span < byte > dst , Span < byte > yuv , int offset )
{
// vertical
Span < byte > src = yuv . Slice ( offset - WebP Constants . Bps , 1 6 ) ;
Span < byte > src = yuv . Slice ( offset - Webp Constants . Bps , 1 6 ) ;
for ( int j = 0 ; j < 1 6 ; + + j )
{
// memcpy(dst + j * BPS, dst - BPS, 16);
src . CopyTo ( dst . Slice ( j * WebP Constants . Bps ) ) ;
src . CopyTo ( dst . Slice ( j * Webp Constants . Bps ) ) ;
}
}
@ -50,8 +50,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
// memset(dst, dst[-1], 16);
byte v = yuv [ offset ] ;
Memset ( dst , v , 0 , 1 6 ) ;
offset + = WebP Constants . Bps ;
dst = dst . Slice ( WebP Constants . Bps ) ;
offset + = Webp Constants . Bps ;
dst = dst . Slice ( Webp Constants . Bps ) ;
}
}
@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
for ( int j = 0 ; j < 1 6 ; + + j )
{
// DC += dst[-1 + j * BPS];
dc + = yuv [ - 1 + ( j * WebP Constants . Bps ) + offset ] ;
dc + = yuv [ - 1 + ( j * Webp Constants . Bps ) + offset ] ;
}
Put16 ( dc > > 4 , dst ) ;
@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
for ( int i = 0 ; i < 1 6 ; + + i )
{
// DC += dst[i - BPS];
dc + = yuv [ i - WebP Constants . Bps + offset ] ;
dc + = yuv [ i - Webp Constants . Bps + offset ] ;
}
Put16 ( dc > > 4 , dst ) ;
@ -92,11 +92,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
{
int dc0 = 8 ;
int offsetMinus1 = offset - 1 ;
int offsetMinusBps = offset - WebP Constants . Bps ;
int offsetMinusBps = offset - Webp Constants . Bps ;
for ( int i = 0 ; i < 8 ; + + i )
{
// dc0 += dst[i - BPS] + dst[-1 + i * BPS];
dc0 + = yuv [ offsetMinusBps + i ] + yuv [ offsetMinus1 + ( i * WebP Constants . Bps ) ] ;
dc0 + = yuv [ offsetMinusBps + i ] + yuv [ offsetMinus1 + ( i * Webp Constants . Bps ) ] ;
}
Put8x8uv ( ( byte ) ( dc0 > > 4 ) , dst ) ;
@ -112,10 +112,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void VE8uv ( Span < byte > dst , Span < byte > yuv , int offset )
{
// vertical
Span < byte > src = yuv . Slice ( offset - WebP Constants . Bps , 8 ) ;
Span < byte > src = yuv . Slice ( offset - Webp Constants . Bps , 8 ) ;
int endIdx = 8 * WebP Constants . Bps ;
for ( int j = 0 ; j < endIdx ; j + = WebP Constants . Bps )
int endIdx = 8 * Webp Constants . Bps ;
for ( int j = 0 ; j < endIdx ; j + = Webp Constants . Bps )
{
// memcpy(dst + j * BPS, dst - BPS, 8);
src . CopyTo ( dst . Slice ( j ) ) ;
@ -132,8 +132,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
// dst += BPS;
byte v = yuv [ offset ] ;
Memset ( dst , v , 0 , 8 ) ;
dst = dst . Slice ( WebP Constants . Bps ) ;
offset + = WebP Constants . Bps ;
dst = dst . Slice ( Webp Constants . Bps ) ;
offset + = Webp Constants . Bps ;
}
}
@ -142,8 +142,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
// DC with no top samples.
int dc0 = 4 ;
int offsetMinusOne = offset - 1 ;
int endIdx = 8 * WebP Constants . Bps ;
for ( int i = 0 ; i < endIdx ; i + = WebP Constants . Bps )
int endIdx = 8 * Webp Constants . Bps ;
for ( int i = 0 ; i < endIdx ; i + = Webp Constants . Bps )
{
// dc0 += dst[-1 + i * BPS];
dc0 + = yuv [ offsetMinusOne + i ] ;
@ -155,7 +155,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void DC8uvNoLeft ( Span < byte > dst , Span < byte > yuv , int offset )
{
// DC with no left samples.
int offsetMinusBps = offset - WebP Constants . Bps ;
int offsetMinusBps = offset - Webp Constants . Bps ;
int dc0 = 4 ;
for ( int i = 0 ; i < 8 ; + + i )
{
@ -176,16 +176,16 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void DC4 ( Span < byte > dst , Span < byte > yuv , int offset )
{
int dc = 4 ;
int offsetMinusBps = offset - WebP Constants . Bps ;
int offsetMinusBps = offset - Webp Constants . Bps ;
int offsetMinusOne = offset - 1 ;
for ( int i = 0 ; i < 4 ; + + i )
{
dc + = yuv [ offsetMinusBps + i ] + yuv [ offsetMinusOne + ( i * WebP Constants . Bps ) ] ;
dc + = yuv [ offsetMinusBps + i ] + yuv [ offsetMinusOne + ( i * Webp Constants . Bps ) ] ;
}
dc > > = 3 ;
int endIndx = 4 * WebP Constants . Bps ;
for ( int i = 0 ; i < endIndx ; i + = WebP Constants . Bps )
int endIndx = 4 * Webp Constants . Bps ;
for ( int i = 0 ; i < endIndx ; i + = Webp Constants . Bps )
{
Memset ( dst , ( byte ) dc , i , 4 ) ;
}
@ -200,7 +200,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void VE4 ( Span < byte > dst , Span < byte > yuv , int offset )
{
// vertical
int topOffset = offset - WebP Constants . Bps ;
int topOffset = offset - Webp Constants . Bps ;
byte [ ] vals =
{
Avg3 ( yuv [ topOffset - 1 ] , yuv [ topOffset ] , yuv [ topOffset + 1 ] ) ,
@ -209,8 +209,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
Avg3 ( yuv [ topOffset + 2 ] , yuv [ topOffset + 3 ] , yuv [ topOffset + 4 ] )
} ;
int endIdx = 4 * WebP Constants . Bps ;
for ( int i = 0 ; i < endIdx ; i + = WebP Constants . Bps )
int endIdx = 4 * Webp Constants . Bps ;
for ( int i = 0 ; i < endIdx ; i + = Webp Constants . Bps )
{
vals . CopyTo ( dst . Slice ( i ) ) ;
}
@ -220,19 +220,19 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
{
// horizontal
int offsetMinusOne = offset - 1 ;
byte a = yuv [ offsetMinusOne - WebP Constants . Bps ] ;
byte a = yuv [ offsetMinusOne - Webp Constants . Bps ] ;
byte b = yuv [ offsetMinusOne ] ;
byte c = yuv [ offsetMinusOne + WebP Constants . Bps ] ;
byte d = yuv [ offsetMinusOne + ( 2 * WebP Constants . Bps ) ] ;
byte e = yuv [ offsetMinusOne + ( 3 * WebP Constants . Bps ) ] ;
byte c = yuv [ offsetMinusOne + Webp Constants . Bps ] ;
byte d = yuv [ offsetMinusOne + ( 2 * Webp Constants . Bps ) ] ;
byte e = yuv [ offsetMinusOne + ( 3 * Webp Constants . Bps ) ] ;
uint val = 0x01010101 U * Avg3 ( a , b , c ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst , val ) ;
val = 0x01010101 U * Avg3 ( b , c , d ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst . Slice ( WebP Constants . Bps ) , val ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst . Slice ( Webp Constants . Bps ) , val ) ;
val = 0x01010101 U * Avg3 ( c , d , e ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst . Slice ( 2 * WebP Constants . Bps ) , val ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst . Slice ( 2 * Webp Constants . Bps ) , val ) ;
val = 0x01010101 U * Avg3 ( d , e , e ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst . Slice ( 3 * WebP Constants . Bps ) , val ) ;
BinaryPrimitives . WriteUInt32BigEndian ( dst . Slice ( 3 * Webp Constants . Bps ) , val ) ;
}
public static void RD4 ( Span < byte > dst , Span < byte > yuv , int offset )
@ -240,14 +240,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
// Down-right
int offsetMinusOne = offset - 1 ;
byte i = yuv [ offsetMinusOne ] ;
byte j = yuv [ offsetMinusOne + ( 1 * WebP Constants . Bps ) ] ;
byte k = yuv [ offsetMinusOne + ( 2 * WebP Constants . Bps ) ] ;
byte l = yuv [ offsetMinusOne + ( 3 * WebP Constants . Bps ) ] ;
byte x = yuv [ offsetMinusOne - WebP Constants . Bps ] ;
byte a = yuv [ offset - WebP Constants . Bps ] ;
byte b = yuv [ offset + 1 - WebP Constants . Bps ] ;
byte c = yuv [ offset + 2 - WebP Constants . Bps ] ;
byte d = yuv [ offset + 3 - WebP Constants . Bps ] ;
byte j = yuv [ offsetMinusOne + ( 1 * Webp Constants . Bps ) ] ;
byte k = yuv [ offsetMinusOne + ( 2 * Webp Constants . Bps ) ] ;
byte l = yuv [ offsetMinusOne + ( 3 * Webp Constants . Bps ) ] ;
byte x = yuv [ offsetMinusOne - Webp Constants . Bps ] ;
byte a = yuv [ offset - Webp Constants . Bps ] ;
byte b = yuv [ offset + 1 - Webp Constants . Bps ] ;
byte c = yuv [ offset + 2 - Webp Constants . Bps ] ;
byte d = yuv [ offset + 3 - Webp Constants . Bps ] ;
Dst ( dst , 0 , 3 , Avg3 ( j , k , l ) ) ;
byte ijk = Avg3 ( i , j , k ) ;
@ -277,13 +277,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
// Vertical-Right
int offsetMinusOne = offset - 1 ;
byte i = yuv [ offsetMinusOne ] ;
byte j = yuv [ offsetMinusOne + ( 1 * WebP Constants . Bps ) ] ;
byte k = yuv [ offsetMinusOne + ( 2 * WebP Constants . Bps ) ] ;
byte x = yuv [ offsetMinusOne - WebP Constants . Bps ] ;
byte a = yuv [ offset - WebP Constants . Bps ] ;
byte b = yuv [ offset + 1 - WebP Constants . Bps ] ;
byte c = yuv [ offset + 2 - WebP Constants . Bps ] ;
byte d = yuv [ offset + 3 - WebP Constants . Bps ] ;
byte j = yuv [ offsetMinusOne + ( 1 * Webp Constants . Bps ) ] ;
byte k = yuv [ offsetMinusOne + ( 2 * Webp Constants . Bps ) ] ;
byte x = yuv [ offsetMinusOne - Webp Constants . Bps ] ;
byte a = yuv [ offset - Webp Constants . Bps ] ;
byte b = yuv [ offset + 1 - Webp Constants . Bps ] ;
byte c = yuv [ offset + 2 - Webp Constants . Bps ] ;
byte d = yuv [ offset + 3 - Webp Constants . Bps ] ;
byte xa = Avg2 ( x , a ) ;
Dst ( dst , 0 , 0 , xa ) ;
@ -312,14 +312,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void LD4 ( Span < byte > dst , Span < byte > yuv , int offset )
{
// Down-Left
byte a = yuv [ offset - WebP Constants . Bps ] ;
byte b = yuv [ offset + 1 - WebP Constants . Bps ] ;
byte c = yuv [ offset + 2 - WebP Constants . Bps ] ;
byte d = yuv [ offset + 3 - WebP Constants . Bps ] ;
byte e = yuv [ offset + 4 - WebP Constants . Bps ] ;
byte f = yuv [ offset + 5 - WebP Constants . Bps ] ;
byte g = yuv [ offset + 6 - WebP Constants . Bps ] ;
byte h = yuv [ offset + 7 - WebP Constants . Bps ] ;
byte a = yuv [ offset - Webp Constants . Bps ] ;
byte b = yuv [ offset + 1 - Webp Constants . Bps ] ;
byte c = yuv [ offset + 2 - Webp Constants . Bps ] ;
byte d = yuv [ offset + 3 - Webp Constants . Bps ] ;
byte e = yuv [ offset + 4 - Webp Constants . Bps ] ;
byte f = yuv [ offset + 5 - Webp Constants . Bps ] ;
byte g = yuv [ offset + 6 - Webp Constants . Bps ] ;
byte h = yuv [ offset + 7 - Webp Constants . Bps ] ;
Dst ( dst , 0 , 0 , Avg3 ( a , b , c ) ) ;
byte bcd = Avg3 ( b , c , d ) ;
@ -347,14 +347,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void VL4 ( Span < byte > dst , Span < byte > yuv , int offset )
{
// Vertical-Left
byte a = yuv [ offset - WebP Constants . Bps ] ;
byte b = yuv [ offset + 1 - WebP Constants . Bps ] ;
byte c = yuv [ offset + 2 - WebP Constants . Bps ] ;
byte d = yuv [ offset + 3 - WebP Constants . Bps ] ;
byte e = yuv [ offset + 4 - WebP Constants . Bps ] ;
byte f = yuv [ offset + 5 - WebP Constants . Bps ] ;
byte g = yuv [ offset + 6 - WebP Constants . Bps ] ;
byte h = yuv [ offset + 7 - WebP Constants . Bps ] ;
byte a = yuv [ offset - Webp Constants . Bps ] ;
byte b = yuv [ offset + 1 - Webp Constants . Bps ] ;
byte c = yuv [ offset + 2 - Webp Constants . Bps ] ;
byte d = yuv [ offset + 3 - Webp Constants . Bps ] ;
byte e = yuv [ offset + 4 - Webp Constants . Bps ] ;
byte f = yuv [ offset + 5 - Webp Constants . Bps ] ;
byte g = yuv [ offset + 6 - Webp Constants . Bps ] ;
byte h = yuv [ offset + 7 - Webp Constants . Bps ] ;
Dst ( dst , 0 , 0 , Avg2 ( a , b ) ) ;
byte bc = Avg2 ( b , c ) ;
@ -384,13 +384,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
{
// Horizontal-Down
byte i = yuv [ offset - 1 ] ;
byte j = yuv [ offset - 1 + ( 1 * WebP Constants . Bps ) ] ;
byte k = yuv [ offset - 1 + ( 2 * WebP Constants . Bps ) ] ;
byte l = yuv [ offset - 1 + ( 3 * WebP Constants . Bps ) ] ;
byte x = yuv [ offset - 1 - WebP Constants . Bps ] ;
byte a = yuv [ offset - WebP Constants . Bps ] ;
byte b = yuv [ offset + 1 - WebP Constants . Bps ] ;
byte c = yuv [ offset + 2 - WebP Constants . Bps ] ;
byte j = yuv [ offset - 1 + ( 1 * Webp Constants . Bps ) ] ;
byte k = yuv [ offset - 1 + ( 2 * Webp Constants . Bps ) ] ;
byte l = yuv [ offset - 1 + ( 3 * Webp Constants . Bps ) ] ;
byte x = yuv [ offset - 1 - Webp Constants . Bps ] ;
byte a = yuv [ offset - Webp Constants . Bps ] ;
byte b = yuv [ offset + 1 - Webp Constants . Bps ] ;
byte c = yuv [ offset + 2 - Webp Constants . Bps ] ;
byte ix = Avg2 ( i , x ) ;
Dst ( dst , 0 , 0 , ix ) ;
@ -420,9 +420,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
{
// Horizontal-Up
byte i = yuv [ offset - 1 ] ;
byte j = yuv [ offset - 1 + ( 1 * WebP Constants . Bps ) ] ;
byte k = yuv [ offset - 1 + ( 2 * WebP Constants . Bps ) ] ;
byte l = yuv [ offset - 1 + ( 3 * WebP Constants . Bps ) ] ;
byte j = yuv [ offset - 1 + ( 1 * Webp Constants . Bps ) ] ;
byte k = yuv [ offset - 1 + ( 2 * Webp Constants . Bps ) ] ;
byte l = yuv [ offset - 1 + ( 3 * Webp Constants . Bps ) ] ;
Dst ( dst , 0 , 0 , Avg2 ( i , j ) ) ;
byte jk = Avg2 ( j , k ) ;
@ -532,7 +532,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
Store ( dst , 2 , 0 , b - c ) ;
Store ( dst , 3 , 0 , a - d ) ;
tmpOffset + + ;
dst = dst . Slice ( WebP Constants . Bps ) ;
dst = dst . Slice ( Webp Constants . Bps ) ;
}
}
@ -565,7 +565,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
public static void TransformUv ( Span < short > src , Span < byte > dst )
{
TransformTwo ( src . Slice ( 0 * 1 6 ) , dst ) ;
TransformTwo ( src . Slice ( 2 * 1 6 ) , dst . Slice ( 4 * WebP Constants . Bps ) ) ;
TransformTwo ( src . Slice ( 2 * 1 6 ) , dst . Slice ( 4 * Webp Constants . Bps ) ) ;
}
public static void TransformDcuv ( Span < short > src , Span < byte > dst )
@ -582,12 +582,12 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
if ( src [ 2 * 1 6 ] ! = 0 )
{
TransformDc ( src . Slice ( 2 * 1 6 ) , dst . Slice ( 4 * WebP Constants . Bps ) ) ;
TransformDc ( src . Slice ( 2 * 1 6 ) , dst . Slice ( 4 * Webp Constants . Bps ) ) ;
}
if ( src [ 3 * 1 6 ] ! = 0 )
{
TransformDc ( src . Slice ( 3 * 1 6 ) , dst . Slice ( ( 4 * WebP Constants . Bps ) + 4 ) ) ;
TransformDc ( src . Slice ( 3 * 1 6 ) , dst . Slice ( ( 4 * Webp Constants . Bps ) + 4 ) ) ;
}
}
@ -745,7 +745,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
[MethodImpl(InliningOptions.ShortMethod)]
public static void Dst ( Span < byte > dst , int x , int y , byte v )
{
dst [ x + ( y * WebP Constants . Bps ) ] = v ;
dst [ x + ( y * Webp Constants . Bps ) ] = v ;
}
[MethodImpl(InliningOptions.ShortMethod)]
@ -757,7 +757,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
// Cost of coding one event with probability 'proba'.
public static int Vp8BitCost ( int bit , byte proba )
{
return bit = = 0 ? WebP LookupTables . Vp8EntropyCost [ proba ] : WebP LookupTables . Vp8EntropyCost [ 2 5 5 - proba ] ;
return bit = = 0 ? Webp LookupTables . Vp8EntropyCost [ proba ] : Webp LookupTables . Vp8EntropyCost [ 2 5 5 - proba ] ;
}
[MethodImpl(InliningOptions.ShortMethod)]
@ -765,14 +765,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
{
for ( int j = 0 ; j < 1 6 ; + + j )
{
Memset ( dst . Slice ( j * WebP Constants . Bps ) , ( byte ) v , 0 , 1 6 ) ;
Memset ( dst . Slice ( j * Webp Constants . Bps ) , ( byte ) v , 0 , 1 6 ) ;
}
}
private static void TrueMotion ( Span < byte > dst , Span < byte > yuv , int offset , int size )
{
// For information about how true motion works, see rfc6386, page 52. ff and section 20.14.
int topOffset = offset - WebP Constants . Bps ;
int topOffset = offset - Webp Constants . Bps ;
Span < byte > top = yuv . Slice ( topOffset ) ;
byte p = yuv [ topOffset - 1 ] ;
int leftOffset = offset - 1 ;
@ -784,9 +784,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
dst [ x ] = ( byte ) Clamp255 ( left + top [ x ] - p ) ;
}
leftOffset + = WebP Constants . Bps ;
leftOffset + = Webp Constants . Bps ;
left = yuv [ leftOffset ] ;
dst = dst . Slice ( WebP Constants . Bps ) ;
dst = dst . Slice ( Webp Constants . Bps ) ;
}
}
@ -856,11 +856,11 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
int p0 = p [ offset - step ] ;
int q0 = p [ offset ] ;
int q1 = p [ offset + step ] ;
int a = ( 3 * ( q0 - p0 ) ) + WebP LookupTables . Sclip1 [ p1 - q1 ] ;
int a1 = WebP LookupTables . Sclip2 [ ( a + 4 ) > > 3 ] ;
int a2 = WebP LookupTables . Sclip2 [ ( a + 3 ) > > 3 ] ;
p [ offset - step ] = WebP LookupTables . Clip1 [ p0 + a2 ] ;
p [ offset ] = WebP LookupTables . Clip1 [ q0 - a1 ] ;
int a = ( 3 * ( q0 - p0 ) ) + Webp LookupTables . Sclip1 [ p1 - q1 ] ;
int a1 = Webp LookupTables . Sclip2 [ ( a + 4 ) > > 3 ] ;
int a2 = Webp LookupTables . Sclip2 [ ( a + 3 ) > > 3 ] ;
p [ offset - step ] = Webp LookupTables . Clip1 [ p0 + a2 ] ;
p [ offset ] = Webp LookupTables . Clip1 [ q0 - a1 ] ;
}
private static void DoFilter4 ( Span < byte > p , int offset , int step )
@ -872,13 +872,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
int q0 = p [ offset ] ;
int q1 = p [ offset + step ] ;
int a = 3 * ( q0 - p0 ) ;
int a1 = WebP LookupTables . Sclip2 [ ( a + 4 ) > > 3 ] ;
int a2 = WebP LookupTables . Sclip2 [ ( a + 3 ) > > 3 ] ;
int a1 = Webp LookupTables . Sclip2 [ ( a + 4 ) > > 3 ] ;
int a2 = Webp LookupTables . Sclip2 [ ( a + 3 ) > > 3 ] ;
int a3 = ( a1 + 1 ) > > 1 ;
p [ offsetMinus2Step ] = WebP LookupTables . Clip1 [ p1 + a3 ] ;
p [ offset - step ] = WebP LookupTables . Clip1 [ p0 + a2 ] ;
p [ offset ] = WebP LookupTables . Clip1 [ q0 - a1 ] ;
p [ offset + step ] = WebP LookupTables . Clip1 [ q1 - a3 ] ;
p [ offsetMinus2Step ] = Webp LookupTables . Clip1 [ p1 + a3 ] ;
p [ offset - step ] = Webp LookupTables . Clip1 [ p0 + a2 ] ;
p [ offset ] = Webp LookupTables . Clip1 [ q0 - a1 ] ;
p [ offset + step ] = Webp LookupTables . Clip1 [ q1 - a3 ] ;
}
private static void DoFilter6 ( Span < byte > p , int offset , int step )
@ -893,18 +893,18 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
int q0 = p [ offset ] ;
int q1 = p [ offset + step ] ;
int q2 = p [ offset + step2 ] ;
int a = WebP LookupTables . Sclip1 [ ( 3 * ( q0 - p0 ) ) + WebP LookupTables . Sclip1 [ p1 - q1 ] ] ;
int a = Webp LookupTables . Sclip1 [ ( 3 * ( q0 - p0 ) ) + Webp LookupTables . Sclip1 [ p1 - q1 ] ] ;
// a is in [-128,127], a1 in [-27,27], a2 in [-18,18] and a3 in [-9,9]
int a1 = ( ( 2 7 * a ) + 6 3 ) > > 7 ; // eq. to ((3 * a + 7) * 9) >> 7
int a2 = ( ( 1 8 * a ) + 6 3 ) > > 7 ; // eq. to ((2 * a + 7) * 9) >> 7
int a3 = ( ( 9 * a ) + 6 3 ) > > 7 ; // eq. to ((1 * a + 7) * 9) >> 7
p [ offset - step3 ] = WebP LookupTables . Clip1 [ p2 + a3 ] ;
p [ offset - step2 ] = WebP LookupTables . Clip1 [ p1 + a2 ] ;
p [ offsetMinusStep ] = WebP LookupTables . Clip1 [ p0 + a1 ] ;
p [ offset ] = WebP LookupTables . Clip1 [ q0 - a1 ] ;
p [ offset + step ] = WebP LookupTables . Clip1 [ q1 - a2 ] ;
p [ offset + step2 ] = WebP LookupTables . Clip1 [ q2 - a3 ] ;
p [ offset - step3 ] = Webp LookupTables . Clip1 [ p2 + a3 ] ;
p [ offset - step2 ] = Webp LookupTables . Clip1 [ p1 + a2 ] ;
p [ offsetMinusStep ] = Webp LookupTables . Clip1 [ p0 + a1 ] ;
p [ offset ] = Webp LookupTables . Clip1 [ q0 - a1 ] ;
p [ offset + step ] = Webp LookupTables . Clip1 [ q1 - a2 ] ;
p [ offset + step2 ] = Webp LookupTables . Clip1 [ q2 - a3 ] ;
}
[MethodImpl(InliningOptions.ShortMethod)]
@ -914,7 +914,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
int p0 = p [ offset - step ] ;
int q0 = p [ offset ] ;
int q1 = p [ offset + step ] ;
return ( ( 4 * WebP LookupTables . Abs0 [ p0 - q0 ] ) + WebP LookupTables . Abs0 [ p1 - q1 ] ) < = t ;
return ( ( 4 * Webp LookupTables . Abs0 [ p0 - q0 ] ) + Webp LookupTables . Abs0 [ p1 - q1 ] ) < = t ;
}
private static bool NeedsFilter2 ( Span < byte > p , int offset , int step , int t , int it )
@ -929,14 +929,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
int q1 = p [ offset + step ] ;
int q2 = p [ offset + step2 ] ;
int q3 = p [ offset + step3 ] ;
if ( ( ( 4 * WebP LookupTables . Abs0 [ p0 - q0 ] ) + WebP LookupTables . Abs0 [ p1 - q1 ] ) > t )
if ( ( ( 4 * Webp LookupTables . Abs0 [ p0 - q0 ] ) + Webp LookupTables . Abs0 [ p1 - q1 ] ) > t )
{
return false ;
}
return WebP LookupTables . Abs0 [ p3 - p2 ] < = it & & WebP LookupTables . Abs0 [ p2 - p1 ] < = it & &
WebP LookupTables . Abs0 [ p1 - p0 ] < = it & & WebP LookupTables . Abs0 [ q3 - q2 ] < = it & &
WebP LookupTables . Abs0 [ q2 - q1 ] < = it & & WebP LookupTables . Abs0 [ q1 - q0 ] < = it ;
return Webp LookupTables . Abs0 [ p3 - p2 ] < = it & & Webp LookupTables . Abs0 [ p2 - p1 ] < = it & &
Webp LookupTables . Abs0 [ p1 - p0 ] < = it & & Webp LookupTables . Abs0 [ q3 - q2 ] < = it & &
Webp LookupTables . Abs0 [ q2 - q1 ] < = it & & Webp LookupTables . Abs0 [ q1 - q0 ] < = it ;
}
[MethodImpl(InliningOptions.ShortMethod)]
@ -946,7 +946,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
int p0 = p [ offset - step ] ;
int q0 = p [ offset ] ;
int q1 = p [ offset + step ] ;
return ( WebP LookupTables . Abs0 [ p1 - p0 ] > thresh ) | | ( WebP LookupTables . Abs0 [ q1 - q0 ] > thresh ) ;
return ( Webp LookupTables . Abs0 [ p1 - p0 ] > thresh ) | | ( Webp LookupTables . Abs0 [ q1 - q0 ] > thresh ) ;
}
[MethodImpl(InliningOptions.ShortMethod)]
@ -958,7 +958,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
[MethodImpl(InliningOptions.ShortMethod)]
private static void Store ( Span < byte > dst , int x , int y , int v )
{
var index = x + ( y * WebP Constants . Bps ) ;
var index = x + ( y * Webp Constants . Bps ) ;
dst [ index ] = Clip8B ( dst [ index ] + ( v > > 3 ) ) ;
}
@ -993,8 +993,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
[MethodImpl(InliningOptions.ShortMethod)]
private static void Put8x8uv ( byte value , Span < byte > dst )
{
int end = 8 * WebP Constants . Bps ;
for ( int j = 0 ; j < end ; j + = WebP Constants . Bps )
int end = 8 * Webp Constants . Bps ;
for ( int j = 0 ; j < end ; j + = Webp Constants . Bps )
{
// memset(dst + j * BPS, value, 8);
Memset ( dst , value , j , 8 ) ;