Skip to content

Commit 5ed690d

Browse files
authored
Merge branch 'main' into bp/arithmeticcoding
2 parents 1d37679 + cfd19ca commit 5ed690d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/ImageSharp/Formats/Webp/Lossy/QuantEnc.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
1616
/// </summary>
1717
internal static unsafe class QuantEnc
1818
{
19-
private static readonly byte[] Zigzag = { 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 };
20-
2119
private static readonly ushort[] WeightY = { 38, 32, 20, 9, 32, 28, 17, 7, 20, 17, 10, 4, 9, 7, 4, 2 };
2220

2321
private const int MaxLevel = 2047;
@@ -47,6 +45,9 @@ internal static unsafe class QuantEnc
4745
private const int DSHIFT = 4;
4846
private const int DSCALE = 1; // storage descaling, needed to make the error fit byte
4947

48+
// This uses C#'s optimization to refer to the static data segment of the assembly, no allocation occurs.
49+
private static ReadOnlySpan<byte> Zigzag => new byte[] { 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 };
50+
5051
public static void PickBestIntra16(Vp8EncIterator it, ref Vp8ModeScore rd, Vp8SegmentInfo[] segmentInfos, Vp8EncProba proba)
5152
{
5253
const int numBlocks = 16;

src/ImageSharp/Formats/Webp/Lossy/Vp8Matrix.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
5+
46
namespace SixLabors.ImageSharp.Formats.Webp.Lossy
57
{
68
internal unsafe struct Vp8Matrix
@@ -13,10 +15,6 @@ internal unsafe struct Vp8Matrix
1315
new[] { 110, 115 }
1416
};
1517

16-
// Sharpening by (slightly) raising the hi-frequency coeffs.
17-
// Hack-ish but helpful for mid-bitrate range. Use with care.
18-
private static readonly byte[] FreqSharpening = { 0, 30, 60, 90, 30, 60, 90, 90, 60, 90, 90, 90, 90, 90, 90, 90 };
19-
2018
/// <summary>
2119
/// Number of descaling bits for sharpening bias.
2220
/// </summary>
@@ -47,6 +45,11 @@ internal unsafe struct Vp8Matrix
4745
/// </summary>
4846
public fixed short Sharpen[16];
4947

48+
// Sharpening by (slightly) raising the hi-frequency coeffs.
49+
// Hack-ish but helpful for mid-bitrate range. Use with care.
50+
// This uses C#'s optimization to refer to the static data segment of the assembly, no allocation occurs.
51+
private static ReadOnlySpan<byte> FreqSharpening => new byte[] { 0, 30, 60, 90, 30, 60, 90, 90, 60, 90, 90, 90, 90, 90, 90, 90 };
52+
5053
/// <summary>
5154
/// Returns the average quantizer.
5255
/// </summary>

0 commit comments

Comments
 (0)