Browse Source

Fix warnings

pull/1552/head
Brian Popow 6 years ago
parent
commit
7badb8c349
  1. 274
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
  2. 27
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
  3. 10
      src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs
  4. 24
      src/ImageSharp/Formats/WebP/Lossy/Vp8ModeScore.cs
  5. 18
      src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentInfo.cs
  6. 12
      src/ImageSharp/Formats/WebP/WebPLookupTables.cs

274
src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs

@ -152,9 +152,9 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
public int Y { get; set; } public int Y { get; set; }
/// <summary> /// <summary>
/// Gets or sets the input samples. /// Gets the input samples.
/// </summary> /// </summary>
public byte[] YuvIn { get; set; } public byte[] YuvIn { get; }
/// <summary> /// <summary>
/// Gets or sets the output samples. /// Gets or sets the output samples.
@ -167,39 +167,39 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
public byte[] YuvOut2 { get; set; } public byte[] YuvOut2 { get; set; }
/// <summary> /// <summary>
/// Gets or sets the scratch buffer for prediction. /// Gets the scratch buffer for prediction.
/// </summary> /// </summary>
public byte[] YuvP { get; set; } public byte[] YuvP { get; }
/// <summary> /// <summary>
/// Gets or sets the left luma samples. /// Gets the left luma samples.
/// </summary> /// </summary>
public byte[] YLeft { get; set; } public byte[] YLeft { get; }
/// <summary> /// <summary>
/// Gets or sets the left uv samples. /// Gets the left uv samples.
/// </summary> /// </summary>
public byte[] UvLeft { get; set; } public byte[] UvLeft { get; }
/// <summary> /// <summary>
/// Gets or sets the top luma samples at position 'X'. /// Gets the top luma samples at position 'X'.
/// </summary> /// </summary>
public IMemoryOwner<byte> YTop { get; set; } public IMemoryOwner<byte> YTop { get; }
/// <summary> /// <summary>
/// Gets or sets the top u/v samples at position 'X', packed as 16 bytes. /// Gets the top u/v samples at position 'X', packed as 16 bytes.
/// </summary> /// </summary>
public IMemoryOwner<byte> UvTop { get; set; } public IMemoryOwner<byte> UvTop { get; }
/// <summary> /// <summary>
/// Gets or sets the intra mode predictors (4x4 blocks). /// Gets the intra mode predictors (4x4 blocks).
/// </summary> /// </summary>
public IMemoryOwner<byte> Preds { get; set; } public IMemoryOwner<byte> Preds { get; }
/// <summary> /// <summary>
/// Gets or sets the non-zero pattern. /// Gets the non-zero pattern.
/// </summary> /// </summary>
public IMemoryOwner<uint> Nz { get; set; } public IMemoryOwner<uint> Nz { get; }
/// <summary> /// <summary>
/// Gets 32+5 boundary samples needed by intra4x4. /// Gets 32+5 boundary samples needed by intra4x4.
@ -217,12 +217,12 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
public int I4 { get; set; } public int I4 { get; set; }
/// <summary> /// <summary>
/// Gets or sets the top-non-zero context. /// Gets the top-non-zero context.
/// </summary> /// </summary>
public int[] TopNz { get; } public int[] TopNz { get; }
/// <summary> /// <summary>
/// Gets or sets the left-non-zero. leftNz[8] is independent. /// Gets the left-non-zero. leftNz[8] is independent.
/// </summary> /// </summary>
public int[] LeftNz { get; } public int[] LeftNz { get; }
@ -288,7 +288,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
} }
} }
NzToBytes(); // import the non-zero context. this.NzToBytes(); // import the non-zero context.
} }
// Import uncompressed samples from source. // Import uncompressed samples from source.
@ -864,9 +864,9 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
byte[] vals = byte[] vals =
{ {
LossyUtils.Avg3(top[-1], top[0], top[1]), LossyUtils.Avg3(top[-1], top[0], top[1]),
LossyUtils.Avg3(top[ 0], top[1], top[2]), LossyUtils.Avg3(top[0], top[1], top[2]),
LossyUtils.Avg3(top[ 1], top[2], top[3]), LossyUtils.Avg3(top[1], top[2], top[3]),
LossyUtils.Avg3(top[ 2], top[3], top[4]) LossyUtils.Avg3(top[2], top[3], top[4])
}; };
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
@ -878,223 +878,223 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
private void He4(Span<byte> dst, Span<byte> top) private void He4(Span<byte> dst, Span<byte> top)
{ {
// horizontal // horizontal
byte X = top[-1]; byte x = top[-1];
byte I = top[-2]; byte i = top[-2];
byte J = top[-3]; byte j = top[-3];
byte K = top[-4]; byte k = top[-4];
byte L = top[-5]; byte l = top[-5];
uint val = 0x01010101U * LossyUtils.Avg3(X, I, J); uint val = 0x01010101U * LossyUtils.Avg3(x, i, j);
BinaryPrimitives.WriteUInt32BigEndian(dst, val); BinaryPrimitives.WriteUInt32BigEndian(dst, val);
val = 0x01010101U * LossyUtils.Avg3(I, J, K); val = 0x01010101U * LossyUtils.Avg3(i, j, k);
BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(1 * WebPConstants.Bps), val); BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(1 * WebPConstants.Bps), val);
val = 0x01010101U * LossyUtils.Avg3(J, K, L); val = 0x01010101U * LossyUtils.Avg3(j, k, l);
BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(2 * WebPConstants.Bps), val); BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(2 * WebPConstants.Bps), val);
val = 0x01010101U * LossyUtils.Avg3(K, L, L); val = 0x01010101U * LossyUtils.Avg3(k, l, l);
BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(1 * WebPConstants.Bps), val); BinaryPrimitives.WriteUInt32BigEndian(dst.Slice(1 * WebPConstants.Bps), val);
} }
private void Rd4(Span<byte> dst, Span<byte> top) private void Rd4(Span<byte> dst, Span<byte> top)
{ {
byte X = top[-1]; byte x = top[-1];
byte I = top[-2]; byte i = top[-2];
byte J = top[-3]; byte j = top[-3];
byte K = top[-4]; byte k = top[-4];
byte L = top[-5]; byte l = top[-5];
byte A = top[0]; byte a = top[0];
byte B = top[1]; byte b = top[1];
byte C = top[2]; byte c = top[2];
byte D = top[3]; byte d = top[3];
LossyUtils.Dst(dst, 0, 3, LossyUtils.Avg3(J, K, L)); LossyUtils.Dst(dst, 0, 3, LossyUtils.Avg3(j, k, l));
var ijk = LossyUtils.Avg3(I, J, K); var ijk = LossyUtils.Avg3(i, j, k);
LossyUtils.Dst(dst, 0, 2, ijk); LossyUtils.Dst(dst, 0, 2, ijk);
LossyUtils.Dst(dst, 1, 3, ijk); LossyUtils.Dst(dst, 1, 3, ijk);
var xij = LossyUtils.Avg3(X, I, J); var xij = LossyUtils.Avg3(x, i, j);
LossyUtils.Dst(dst, 0, 1, xij); LossyUtils.Dst(dst, 0, 1, xij);
LossyUtils.Dst(dst, 1, 2, xij); LossyUtils.Dst(dst, 1, 2, xij);
LossyUtils.Dst(dst, 2, 3, xij); LossyUtils.Dst(dst, 2, 3, xij);
var axi = LossyUtils.Avg3(A, X, I); var axi = LossyUtils.Avg3(a, x, i);
LossyUtils.Dst(dst, 0, 0, axi); LossyUtils.Dst(dst, 0, 0, axi);
LossyUtils.Dst(dst, 1, 1, axi); LossyUtils.Dst(dst, 1, 1, axi);
LossyUtils.Dst(dst, 2, 2, axi); LossyUtils.Dst(dst, 2, 2, axi);
LossyUtils.Dst(dst, 3, 3, axi); LossyUtils.Dst(dst, 3, 3, axi);
var bax = LossyUtils.Avg3(B, A, X); var bax = LossyUtils.Avg3(b, a, x);
LossyUtils.Dst(dst, 1, 0, bax); LossyUtils.Dst(dst, 1, 0, bax);
LossyUtils.Dst(dst, 2, 1, bax); LossyUtils.Dst(dst, 2, 1, bax);
LossyUtils.Dst(dst, 3, 2, bax); LossyUtils.Dst(dst, 3, 2, bax);
var cba = LossyUtils.Avg3(C, B, A); var cba = LossyUtils.Avg3(c, b, a);
LossyUtils.Dst(dst, 2, 0, cba); LossyUtils.Dst(dst, 2, 0, cba);
LossyUtils.Dst(dst, 3, 1, cba); LossyUtils.Dst(dst, 3, 1, cba);
LossyUtils.Dst(dst, 3, 0, LossyUtils.Avg3(D, C, B)); LossyUtils.Dst(dst, 3, 0, LossyUtils.Avg3(d, c, b));
} }
private void Vr4(Span<byte> dst, Span<byte> top) private void Vr4(Span<byte> dst, Span<byte> top)
{ {
byte X = top[-1]; byte x = top[-1];
byte I = top[-2]; byte i = top[-2];
byte J = top[-3]; byte j = top[-3];
byte K = top[-4]; byte k = top[-4];
byte A = top[0]; byte a = top[0];
byte B = top[1]; byte b = top[1];
byte C = top[2]; byte c = top[2];
byte D = top[3]; byte d = top[3];
var xa = LossyUtils.Avg2(X, A); var xa = LossyUtils.Avg2(x, a);
LossyUtils.Dst(dst, 0, 0, xa); LossyUtils.Dst(dst, 0, 0, xa);
LossyUtils.Dst(dst, 1, 2, xa); LossyUtils.Dst(dst, 1, 2, xa);
var ab = LossyUtils.Avg2(A, B); var ab = LossyUtils.Avg2(a, b);
LossyUtils.Dst(dst, 1, 0, ab); LossyUtils.Dst(dst, 1, 0, ab);
LossyUtils.Dst(dst, 2, 2, ab); LossyUtils.Dst(dst, 2, 2, ab);
var bc = LossyUtils.Avg2(B, C); var bc = LossyUtils.Avg2(b, c);
LossyUtils.Dst(dst, 2, 0, bc); LossyUtils.Dst(dst, 2, 0, bc);
LossyUtils.Dst(dst, 3, 2, bc); LossyUtils.Dst(dst, 3, 2, bc);
LossyUtils.Dst(dst, 3, 0, LossyUtils.Avg2(C, D)); LossyUtils.Dst(dst, 3, 0, LossyUtils.Avg2(c, d));
LossyUtils.Dst(dst, 0, 3, LossyUtils.Avg3(K, J, I)); LossyUtils.Dst(dst, 0, 3, LossyUtils.Avg3(k, j, i));
LossyUtils.Dst(dst, 0, 2, LossyUtils.Avg3(J, I, X)); LossyUtils.Dst(dst, 0, 2, LossyUtils.Avg3(j, i, x));
var ixa = LossyUtils.Avg3(I, X, A); var ixa = LossyUtils.Avg3(i, x, a);
LossyUtils.Dst(dst, 0, 1, ixa); LossyUtils.Dst(dst, 0, 1, ixa);
LossyUtils.Dst(dst, 1, 3, ixa); LossyUtils.Dst(dst, 1, 3, ixa);
var xab = LossyUtils.Avg3(X, A, B); var xab = LossyUtils.Avg3(x, a, b);
LossyUtils.Dst(dst, 1, 1, xab); LossyUtils.Dst(dst, 1, 1, xab);
LossyUtils.Dst(dst, 2, 3, xab); LossyUtils.Dst(dst, 2, 3, xab);
var abc = LossyUtils.Avg3(A, B, C); var abc = LossyUtils.Avg3(a, b, c);
LossyUtils.Dst(dst, 2, 1, abc); LossyUtils.Dst(dst, 2, 1, abc);
LossyUtils.Dst(dst, 3, 3, abc); LossyUtils.Dst(dst, 3, 3, abc);
LossyUtils.Dst(dst, 3, 1, LossyUtils.Avg3(B, C, D)); LossyUtils.Dst(dst, 3, 1, LossyUtils.Avg3(b, c, d));
} }
private void Ld4(Span<byte> dst, Span<byte> top) private void Ld4(Span<byte> dst, Span<byte> top)
{ {
byte A = top[0]; byte a = top[0];
byte B = top[1]; byte b = top[1];
byte C = top[2]; byte c = top[2];
byte D = top[3]; byte d = top[3];
byte E = top[4]; byte e = top[4];
byte F = top[5]; byte f = top[5];
byte G = top[6]; byte g = top[6];
byte H = top[7]; byte h = top[7];
LossyUtils.Dst(dst, 0, 0, LossyUtils.Avg3(A, B, C)); LossyUtils.Dst(dst, 0, 0, LossyUtils.Avg3(a, b, c));
var bcd = LossyUtils.Avg3(B, C, D); var bcd = LossyUtils.Avg3(b, c, d);
LossyUtils.Dst(dst, 1, 0, bcd); LossyUtils.Dst(dst, 1, 0, bcd);
LossyUtils.Dst(dst, 0, 1, bcd); LossyUtils.Dst(dst, 0, 1, bcd);
var cde = LossyUtils.Avg3(C, D, E); var cde = LossyUtils.Avg3(c, d, e);
LossyUtils.Dst(dst, 2, 0, cde); LossyUtils.Dst(dst, 2, 0, cde);
LossyUtils.Dst(dst, 1, 1, cde); LossyUtils.Dst(dst, 1, 1, cde);
LossyUtils.Dst(dst, 0, 2, cde); LossyUtils.Dst(dst, 0, 2, cde);
var def = LossyUtils.Avg3(D, E, F); var def = LossyUtils.Avg3(d, e, f);
LossyUtils.Dst(dst, 3, 0, def); LossyUtils.Dst(dst, 3, 0, def);
LossyUtils.Dst(dst, 2, 1, def); LossyUtils.Dst(dst, 2, 1, def);
LossyUtils.Dst(dst, 1, 2, def); LossyUtils.Dst(dst, 1, 2, def);
LossyUtils.Dst(dst, 0, 3, def); LossyUtils.Dst(dst, 0, 3, def);
var efg = LossyUtils.Avg3(E, F, G); var efg = LossyUtils.Avg3(e, f, g);
LossyUtils.Dst(dst, 3, 1, efg); LossyUtils.Dst(dst, 3, 1, efg);
LossyUtils.Dst(dst, 2, 2, efg); LossyUtils.Dst(dst, 2, 2, efg);
LossyUtils.Dst(dst, 1, 3, efg); LossyUtils.Dst(dst, 1, 3, efg);
var fgh = LossyUtils.Avg3(F, G, H); var fgh = LossyUtils.Avg3(f, g, h);
LossyUtils.Dst(dst, 3, 2, fgh); LossyUtils.Dst(dst, 3, 2, fgh);
LossyUtils.Dst(dst, 2, 3, fgh); LossyUtils.Dst(dst, 2, 3, fgh);
LossyUtils.Dst(dst, 3, 3, LossyUtils.Avg3(G, H, H)); LossyUtils.Dst(dst, 3, 3, LossyUtils.Avg3(g, h, h));
} }
private void Vl4(Span<byte> dst, Span<byte> top) private void Vl4(Span<byte> dst, Span<byte> top)
{ {
byte A = top[0]; byte a = top[0];
byte B = top[1]; byte b = top[1];
byte C = top[2]; byte c = top[2];
byte D = top[3]; byte d = top[3];
byte E = top[4]; byte e = top[4];
byte F = top[5]; byte f = top[5];
byte G = top[6]; byte g = top[6];
byte H = top[7]; byte h = top[7];
LossyUtils.Dst(dst, 0, 0, LossyUtils.Avg2(A, B)); LossyUtils.Dst(dst, 0, 0, LossyUtils.Avg2(a, b));
var bc = LossyUtils.Avg2(B, C); var bc = LossyUtils.Avg2(b, c);
LossyUtils.Dst(dst, 1, 0, bc); LossyUtils.Dst(dst, 1, 0, bc);
LossyUtils.Dst(dst, 0, 2, bc); LossyUtils.Dst(dst, 0, 2, bc);
var cd = LossyUtils.Avg2(C, D); var cd = LossyUtils.Avg2(c, d);
LossyUtils.Dst(dst, 2, 0, cd); LossyUtils.Dst(dst, 2, 0, cd);
LossyUtils.Dst(dst, 1, 2, cd); LossyUtils.Dst(dst, 1, 2, cd);
var de = LossyUtils.Avg2(D, E); var de = LossyUtils.Avg2(d, e);
LossyUtils.Dst(dst, 3, 0, de); LossyUtils.Dst(dst, 3, 0, de);
LossyUtils.Dst(dst, 2, 2, de); LossyUtils.Dst(dst, 2, 2, de);
LossyUtils.Dst(dst, 0, 1, LossyUtils.Avg3(A, B, C)); LossyUtils.Dst(dst, 0, 1, LossyUtils.Avg3(a, b, c));
var bcd = LossyUtils.Avg3(B,C,D); var bcd = LossyUtils.Avg3(b, c, d);
LossyUtils.Dst(dst, 1, 1, bcd); LossyUtils.Dst(dst, 1, 1, bcd);
LossyUtils.Dst(dst, 0, 3, bcd); LossyUtils.Dst(dst, 0, 3, bcd);
var cde = LossyUtils.Avg3(C, D, E); var cde = LossyUtils.Avg3(c, d, e);
LossyUtils.Dst(dst, 2, 1, cde); LossyUtils.Dst(dst, 2, 1, cde);
LossyUtils.Dst(dst, 1, 3, cde); LossyUtils.Dst(dst, 1, 3, cde);
var def = LossyUtils.Avg3(D, E, F); var def = LossyUtils.Avg3(d, e, f);
LossyUtils.Dst(dst, 3, 1, def); LossyUtils.Dst(dst, 3, 1, def);
LossyUtils.Dst(dst, 2, 3, def); LossyUtils.Dst(dst, 2, 3, def);
LossyUtils.Dst(dst, 3,2, LossyUtils.Avg3(E, F, G)); LossyUtils.Dst(dst, 3, 2, LossyUtils.Avg3(e, f, g));
LossyUtils.Dst(dst, 3, 3, LossyUtils.Avg3(F, G, H)); LossyUtils.Dst(dst, 3, 3, LossyUtils.Avg3(f, g, h));
} }
private void Hd4(Span<byte> dst, Span<byte> top) private void Hd4(Span<byte> dst, Span<byte> top)
{ {
byte X = top[-1]; byte x = top[-1];
byte I = top[-2]; byte i = top[-2];
byte J = top[-3]; byte j = top[-3];
byte K = top[-4]; byte k = top[-4];
byte L = top[-5]; byte l = top[-5];
byte A = top[0]; byte a = top[0];
byte B = top[1]; byte b = top[1];
byte C = top[2]; byte c = top[2];
var ix = LossyUtils.Avg2(I, X); var ix = LossyUtils.Avg2(i, x);
LossyUtils.Dst(dst, 0, 0, ix); LossyUtils.Dst(dst, 0, 0, ix);
LossyUtils.Dst(dst, 2, 1, ix); LossyUtils.Dst(dst, 2, 1, ix);
var ji = LossyUtils.Avg2(J,I); var ji = LossyUtils.Avg2(j, i);
LossyUtils.Dst(dst, 0, 1, ji); LossyUtils.Dst(dst, 0, 1, ji);
LossyUtils.Dst(dst, 2, 2, ji); LossyUtils.Dst(dst, 2, 2, ji);
var kj = LossyUtils.Avg2(K, J); var kj = LossyUtils.Avg2(k, j);
LossyUtils.Dst(dst, 0, 2, kj); LossyUtils.Dst(dst, 0, 2, kj);
LossyUtils.Dst(dst, 2, 3, kj); LossyUtils.Dst(dst, 2, 3, kj);
LossyUtils.Dst(dst, 0, 3, LossyUtils.Avg2(L, K)); LossyUtils.Dst(dst, 0, 3, LossyUtils.Avg2(l, k));
LossyUtils.Dst(dst, 3, 0, LossyUtils.Avg3(A, B, C)); LossyUtils.Dst(dst, 3, 0, LossyUtils.Avg3(a, b, c));
LossyUtils.Dst(dst, 2, 0, LossyUtils.Avg3(X, A, B)); LossyUtils.Dst(dst, 2, 0, LossyUtils.Avg3(x, a, b));
var ixa = LossyUtils.Avg3(I, X, A); var ixa = LossyUtils.Avg3(i, x, a);
LossyUtils.Dst(dst, 1, 0, ixa); LossyUtils.Dst(dst, 1, 0, ixa);
LossyUtils.Dst(dst, 3, 1, ixa); LossyUtils.Dst(dst, 3, 1, ixa);
var jix = LossyUtils.Avg3(J, I, X); var jix = LossyUtils.Avg3(j, i, x);
LossyUtils.Dst(dst, 1, 1, jix); LossyUtils.Dst(dst, 1, 1, jix);
LossyUtils.Dst(dst, 3, 2, jix); LossyUtils.Dst(dst, 3, 2, jix);
var kji = LossyUtils.Avg3(K, J, I); var kji = LossyUtils.Avg3(k, j, i);
LossyUtils.Dst(dst, 1, 2, kji); LossyUtils.Dst(dst, 1, 2, kji);
LossyUtils.Dst(dst, 3, 3, kji); LossyUtils.Dst(dst, 3, 3, kji);
LossyUtils.Dst(dst, 1, 3, LossyUtils.Avg3(L, K, J)); LossyUtils.Dst(dst, 1, 3, LossyUtils.Avg3(l, k, j));
} }
private void Hu4(Span<byte> dst, Span<byte> top) private void Hu4(Span<byte> dst, Span<byte> top)
{ {
byte I = top[-2]; byte i = top[-2];
byte J = top[-3]; byte j = top[-3];
byte K = top[-4]; byte k = top[-4];
byte L = top[-5]; byte l = top[-5];
LossyUtils.Dst(dst, 0, 0, LossyUtils.Avg2(I, J)); LossyUtils.Dst(dst, 0, 0, LossyUtils.Avg2(i, j));
var jk = LossyUtils.Avg2(J, K); var jk = LossyUtils.Avg2(j, k);
LossyUtils.Dst(dst, 2, 0, jk); LossyUtils.Dst(dst, 2, 0, jk);
LossyUtils.Dst(dst, 0, 1, jk); LossyUtils.Dst(dst, 0, 1, jk);
var kl = LossyUtils.Avg2(K, L); var kl = LossyUtils.Avg2(k, l);
LossyUtils.Dst(dst, 2, 1, kl); LossyUtils.Dst(dst, 2, 1, kl);
LossyUtils.Dst(dst, 0, 2, kl); LossyUtils.Dst(dst, 0, 2, kl);
LossyUtils.Dst(dst, 1, 0, LossyUtils.Avg3(I, J, K)); LossyUtils.Dst(dst, 1, 0, LossyUtils.Avg3(i, j, k));
var jkl = LossyUtils.Avg3(J, K, L); var jkl = LossyUtils.Avg3(j, k, l);
LossyUtils.Dst(dst, 3, 0, jkl); LossyUtils.Dst(dst, 3, 0, jkl);
LossyUtils.Dst(dst, 1, 1, jkl); LossyUtils.Dst(dst, 1, 1, jkl);
var kll = LossyUtils.Avg3(K, L, L); var kll = LossyUtils.Avg3(k, l, l);
LossyUtils.Dst(dst, 3, 1, kll); LossyUtils.Dst(dst, 3, 1, kll);
LossyUtils.Dst(dst, 1, 2, kll); LossyUtils.Dst(dst, 1, 2, kll);
LossyUtils.Dst(dst, 3, 2, L); LossyUtils.Dst(dst, 3, 2, l);
LossyUtils.Dst(dst, 2, 2, L); LossyUtils.Dst(dst, 2, 2, l);
LossyUtils.Dst(dst, 0, 3, L); LossyUtils.Dst(dst, 0, 3, l);
LossyUtils.Dst(dst, 1, 3, L); LossyUtils.Dst(dst, 1, 3, l);
LossyUtils.Dst(dst, 2, 3, L); LossyUtils.Dst(dst, 2, 3, l);
LossyUtils.Dst(dst, 3, 3, L); LossyUtils.Dst(dst, 3, 3, l);
} }
private void Fill(Span<byte> dst, int value, int size) private void Fill(Span<byte> dst, int value, int size)

27
src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs

@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
it.Import(y, u, v, yStride, uvStride, width, height); it.Import(y, u, v, yStride, uvStride, width, height);
if (!this.Decimate(it, segmentInfos, info, method)) if (!this.Decimate(it, segmentInfos, info, method))
{ {
this.CodeResiduals(it); this.CodeResiduals(it, info);
} }
else else
{ {
@ -180,8 +180,8 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
private void SetSegmentProbas(Vp8SegmentInfo[] dqm) private void SetSegmentProbas(Vp8SegmentInfo[] dqm)
{ {
var p = new int[4]; // var p = new int[4];
int n; // int n;
// TODO: SetSegmentProbas // TODO: SetSegmentProbas
} }
@ -399,9 +399,8 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
rd.Score = bestScore; rd.Score = bestScore;
} }
private void CodeResiduals(Vp8EncIterator it) private void CodeResiduals(Vp8EncIterator it, Vp8ModeScore rd)
{ {
} }
private int ReconstructIntra16(Vp8EncIterator it, Vp8SegmentInfo dqm, Vp8ModeScore rd, Span<byte> yuvOut, int mode) private int ReconstructIntra16(Vp8EncIterator it, Vp8SegmentInfo dqm, Vp8ModeScore rd, Span<byte> yuvOut, int mode)
@ -560,9 +559,9 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
int b1 = a3 + a2; int b1 = a3 + a2;
int b2 = a3 - a2; int b2 = a3 - a2;
int b3 = a0 - a1; int b3 = a0 - a1;
output[ 0 + i] = (short)(b0 >> 1); // 15b output[0 + i] = (short)(b0 >> 1); // 15b
output[ 4 + i] = (short)(b1 >> 1); output[4 + i] = (short)(b1 >> 1);
output[ 8 + i] = (short)(b2 >> 1); output[8 + i] = (short)(b2 >> 1);
output[12 + i] = (short)(b3 >> 1); output[12 + i] = (short)(b3 >> 1);
} }
} }
@ -581,15 +580,15 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
int n; int n;
for (n = 0; n < 16; ++n) for (n = 0; n < 16; ++n)
{ {
int j = zigzag[n]; int j = this.zigzag[n];
bool sign = input[j] < 0; bool sign = input[j] < 0;
uint coeff = (uint)((sign ? -input[j] : input[j]) + mtx.Sharpen[j]); uint coeff = (uint)((sign ? -input[j] : input[j]) + mtx.Sharpen[j]);
if (coeff > mtx.ZThresh[j]) if (coeff > mtx.ZThresh[j])
{ {
uint Q = (uint)mtx.Q[j]; uint q = (uint)mtx.Q[j];
uint iQ = (uint)mtx.IQ[j]; uint iQ = (uint)mtx.IQ[j];
uint B = mtx.Bias[j]; uint b = mtx.Bias[j];
int level = this.QuantDiv(coeff, iQ, B); int level = this.QuantDiv(coeff, iQ, b);
if (level > MaxLevel) if (level > MaxLevel)
{ {
level = MaxLevel; level = MaxLevel;
@ -600,7 +599,7 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
level = -level; level = -level;
} }
input[j] = (short)(level * (int)Q); input[j] = (short)(level * (int)q);
output[n] = (short)level; output[n] = (short)level;
if (level != 0) if (level != 0)
{ {
@ -629,7 +628,9 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
private void ITransformOne(Span<byte> reference, Span<short> input, Span<byte> dst) private void ITransformOne(Span<byte> reference, Span<short> input, Span<byte> dst)
{ {
int i; int i;
#pragma warning disable SA1312 // Variable names should begin with lower-case letter
var C = new int[4 * 4]; var C = new int[4 * 4];
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
Span<int> tmp = C.AsSpan(); Span<int> tmp = C.AsSpan();
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i)
{ {

10
src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs

@ -18,27 +18,27 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
} }
/// <summary> /// <summary>
/// quantizer steps. /// Gets the quantizer steps.
/// </summary> /// </summary>
public short[] Q { get; } public short[] Q { get; }
/// <summary> /// <summary>
/// reciprocals, fixed point. /// Gets the reciprocals, fixed point.
/// </summary> /// </summary>
public short[] IQ { get; } public short[] IQ { get; }
/// <summary> /// <summary>
/// rounding bias. /// Gets the rounding bias.
/// </summary> /// </summary>
public uint[] Bias { get; } public uint[] Bias { get; }
/// <summary> /// <summary>
/// value below which a coefficient is zeroed. /// Gets the value below which a coefficient is zeroed.
/// </summary> /// </summary>
public uint[] ZThresh { get; } public uint[] ZThresh { get; }
/// <summary> /// <summary>
/// frequency boosters for slight sharpening. /// Gets the frequency boosters for slight sharpening.
/// </summary> /// </summary>
public short[] Sharpen { get; } public short[] Sharpen { get; }
} }

24
src/ImageSharp/Formats/WebP/Lossy/Vp8ModeScore.cs

@ -32,62 +32,62 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
} }
/// <summary> /// <summary>
/// Distortion. /// Gets or sets the distortion.
/// </summary> /// </summary>
public long D { get; set; } public long D { get; set; }
/// <summary> /// <summary>
/// Spectral distortion. /// Gets or sets the spectral distortion.
/// </summary> /// </summary>
public long SD { get; set; } public long SD { get; set; }
/// <summary> /// <summary>
/// Header bits. /// Gets or sets the header bits.
/// </summary> /// </summary>
public long H { get; set; } public long H { get; set; }
/// <summary> /// <summary>
/// Rate. /// Gets or sets the rate.
/// </summary> /// </summary>
public long R { get; set; } public long R { get; set; }
/// <summary> /// <summary>
/// Score. /// Gets or sets the score.
/// </summary> /// </summary>
public long Score { get; set; } public long Score { get; set; }
/// <summary> /// <summary>
/// Quantized levels for luma-DC. /// Gets the quantized levels for luma-DC.
/// </summary> /// </summary>
public short[] YDcLevels { get; } public short[] YDcLevels { get; }
/// <summary> /// <summary>
/// Quantized levels for luma-AC. /// Gets the quantized levels for luma-AC.
/// </summary> /// </summary>
public short[][] YAcLevels { get; } public short[][] YAcLevels { get; }
/// <summary> /// <summary>
/// Quantized levels for chroma. /// Gets the quantized levels for chroma.
/// </summary> /// </summary>
public short[][] UvLevels { get; } public short[][] UvLevels { get; }
/// <summary> /// <summary>
/// Mode number for intra16 prediction. /// Gets or sets the mode number for intra16 prediction.
/// </summary> /// </summary>
public int ModeI16 { get; set; } public int ModeI16 { get; set; }
/// <summary> /// <summary>
/// Mode numbers for intra4 predictions. /// Gets the mode numbers for intra4 predictions.
/// </summary> /// </summary>
public byte[] ModesI4 { get; } public byte[] ModesI4 { get; }
/// <summary> /// <summary>
/// Mode number of chroma prediction. /// Gets or sets the mode number of chroma prediction.
/// </summary> /// </summary>
public int ModeUv { get; set; } public int ModeUv { get; set; }
/// <summary> /// <summary>
/// Non-zero blocks. /// Gets or sets the Non-zero blocks.
/// </summary> /// </summary>
public uint Nz { get; set; } public uint Nz { get; set; }

18
src/ImageSharp/Formats/WebP/Lossy/Vp8SegmentInfo.cs

@ -6,47 +6,47 @@ namespace SixLabors.ImageSharp.Formats.WebP.Lossy
internal class Vp8SegmentInfo internal class Vp8SegmentInfo
{ {
/// <summary> /// <summary>
/// quantization matrix y1. /// Gets or sets the quantization matrix y1.
/// </summary> /// </summary>
public Vp8Matrix Y1 { get; set; } public Vp8Matrix Y1 { get; set; }
/// <summary> /// <summary>
/// quantization matrix y2. /// Gets or sets the quantization matrix y2.
/// </summary> /// </summary>
public Vp8Matrix Y2 { get; set; } public Vp8Matrix Y2 { get; set; }
/// <summary> /// <summary>
/// quantization matrix uv. /// Gets or sets the quantization matrix uv.
/// </summary> /// </summary>
public Vp8Matrix Uv { get; set; } public Vp8Matrix Uv { get; set; }
/// <summary> /// <summary>
/// quant-susceptibility, range [-127,127]. Zero is neutral. Lower values indicate a lower risk of blurriness. /// Gets or sets the quant-susceptibility, range [-127,127]. Zero is neutral. Lower values indicate a lower risk of blurriness.
/// </summary> /// </summary>
public int Alpha { get; set; } public int Alpha { get; set; }
/// <summary> /// <summary>
/// filter-susceptibility, range [0,255]. /// Gets or sets the filter-susceptibility, range [0,255].
/// </summary> /// </summary>
public int Beta { get; set; } public int Beta { get; set; }
/// <summary> /// <summary>
/// final segment quantizer. /// Gets or sets the final segment quantizer.
/// </summary> /// </summary>
public int Quant { get; set; } public int Quant { get; set; }
/// <summary> /// <summary>
/// final in-loop filtering strength. /// Gets or sets the final in-loop filtering strength.
/// </summary> /// </summary>
public int FStrength { get; set; } public int FStrength { get; set; }
/// <summary> /// <summary>
/// max edge delta (for filtering strength). /// Gets or sets the max edge delta (for filtering strength).
/// </summary> /// </summary>
public int MaxEdge { get; set; } public int MaxEdge { get; set; }
/// <summary> /// <summary>
/// penalty for using Intra4. /// Gets or sets the penalty for using Intra4.
/// </summary> /// </summary>
public long I4Penalty { get; set; } public long I4Penalty { get; set; }
} }

12
src/ImageSharp/Formats/WebP/WebPLookupTables.cs

@ -39,16 +39,16 @@ namespace SixLabors.ImageSharp.Formats.WebP
public static readonly short[] Vp8Scan = public static readonly short[] Vp8Scan =
{ {
// Luma // Luma
0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), 0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps),
0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps), 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps),
0 + (8 * WebPConstants.Bps), 4 + (8 * WebPConstants.Bps), 8 + (8 * WebPConstants.Bps), 12 + (8 * WebPConstants.Bps), 0 + (8 * WebPConstants.Bps), 4 + (8 * WebPConstants.Bps), 8 + (8 * WebPConstants.Bps), 12 + (8 * WebPConstants.Bps),
0 + (12 * WebPConstants.Bps), 4 + (12 * WebPConstants.Bps), 8 + (12 * WebPConstants.Bps), 12 + (12 * WebPConstants.Bps), 0 + (12 * WebPConstants.Bps), 4 + (12 * WebPConstants.Bps), 8 + (12 * WebPConstants.Bps), 12 + (12 * WebPConstants.Bps),
}; };
public static readonly short[] Vp8ScanUv = public static readonly short[] Vp8ScanUv =
{ {
0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), // U 0 + (0 * WebPConstants.Bps), 4 + (0 * WebPConstants.Bps), 0 + (4 * WebPConstants.Bps), 4 + (4 * WebPConstants.Bps), // U
8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps) // V 8 + (0 * WebPConstants.Bps), 12 + (0 * WebPConstants.Bps), 8 + (4 * WebPConstants.Bps), 12 + (4 * WebPConstants.Bps) // V
}; };
public static readonly short[,][] Vp8FixedCostsI4 = new short[10, 10][]; public static readonly short[,][] Vp8FixedCostsI4 = new short[10, 10][];

Loading…
Cancel
Save