diff --git a/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs b/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs
index 5cc12259a2..fde8500252 100644
--- a/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs
+++ b/src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs
@@ -80,10 +80,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitReader
this.InitBitreader(partitionLength, startPos);
}
- public int Pos
- {
- get { return (int)this.pos; }
- }
+ public int Pos => (int)this.pos;
public uint ImageDataSize { get; }
diff --git a/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs b/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs
index f12bacd879..46f2dbdaf5 100644
--- a/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs
+++ b/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs
@@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter
/// The expected size in bytes.
protected BitWriterBase(int expectedSize)
{
- // TODO: use memory allocator here.
+ // TODO: should we use memory allocator here?
this.buffer = new byte[expectedSize];
}
@@ -30,10 +30,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter
///
private protected BitWriterBase(byte[] buffer) => this.buffer = buffer;
- public byte[] Buffer
- {
- get { return this.buffer; }
- }
+ public byte[] Buffer => this.buffer;
///
/// Writes the encoded bytes of the image to the stream. Call Finish() before this.
diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs
index e1483ce305..b9d326ada6 100644
--- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs
+++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs
@@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter
private uint pos;
- private int maxPos;
+ private readonly int maxPos;
///
/// Initializes a new instance of the class.
diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs
index 4bf3d5f05a..1764a190ce 100644
--- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs
+++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs
@@ -167,7 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter
// If needed, make some room by flushing some bits out.
if (this.cur + WriterBytes > this.end)
{
- var extraSize = (this.end - this.cur) + MinExtraSize;
+ var extraSize = this.end - this.cur + MinExtraSize;
this.BitWriterResize(extraSize);
}
diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs b/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs
index c6febb82d7..2c09be2cba 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
///
/// The GetLengthCost(costModel, k) are cached in a CostCacheInterval.
///
- [DebuggerDisplay("Start: {Start}, End: {End}, Cost: {Cost}, Position: {Position}")]
+ [DebuggerDisplay("Start: {Start}, End: {End}, Cost: {Cost}")]
internal class CostCacheInterval
{
public double Cost { get; set; }
diff --git a/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs b/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs
index 0cf6df2a7c..1eccc7af7d 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/CostManager.cs
@@ -255,17 +255,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
///
private void PositionOrphanInterval(CostInterval current, CostInterval previous)
{
- if (previous == null)
- {
- previous = this.head;
- }
+ previous ??= this.head;
while (previous != null && current.Start < previous.Start)
{
previous = previous.Previous;
}
- while (previous != null && previous.Next != null && previous.Next.Start < current.Start)
+ while (previous?.Next != null && previous.Next.Start < current.Start)
{
previous = previous.Next;
}
diff --git a/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs
index 6b1fee5a69..dd4a919610 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs
@@ -259,8 +259,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
doContinue = false;
for (int i = 0; i < numClusters; i++)
{
- int k;
- k = clusterMappings[i];
+ int k = clusterMappings[i];
while (k != clusterMappings[k])
{
clusterMappings[k] = clusterMappings[clusterMappings[k]];
@@ -336,8 +335,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
for (int iter = 0; iter < outerIters && numUsed >= minClusterSize && ++triesWithNoSuccess < numTriesNoSuccess; iter++)
{
double bestCost = (histoPriorityList.Count == 0) ? 0.0d : histoPriorityList[0].CostDiff;
- int bestIdx1 = -1;
- int bestIdx2 = 1;
int numTries = numUsed / 2;
uint randRange = (uint)((numUsed - 1) * numUsed);
@@ -377,8 +374,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
}
// Get the best histograms.
- bestIdx1 = histoPriorityList[0].Idx1;
- bestIdx2 = histoPriorityList[0].Idx2;
+ var bestIdx1 = histoPriorityList[0].Idx1;
+ var bestIdx2 = histoPriorityList[0].Idx2;
var mappingIndex = Array.IndexOf(mappings, bestIdx2);
Span src = mappings.AsSpan(mappingIndex + 1, numUsed - mappingIndex - 1);
diff --git a/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs b/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs
index 1329802ebf..c467ff827a 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs
@@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
public const uint HuffmanPackedTableSize = 1u << HuffmanPackedBits;
// Pre-reversed 4-bit values.
- private static byte[] reversedBits =
+ private static readonly byte[] ReversedBits =
{
0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf
@@ -427,7 +427,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
tableSize = 1 << tableBits;
totalSize += tableSize;
low = key & mask;
- uint v = (uint)(tablePos - low);
table[low] = new HuffmanCode
{
BitsUsed = tableBits + rootBits,
@@ -589,7 +588,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
while (i < numBits)
{
i += 4;
- retval |= (uint)(reversedBits[bits & 0xf] << (WebpConstants.MaxAllowedCodeLength + 1 - i));
+ retval |= (uint)(ReversedBits[bits & 0xf] << (WebpConstants.MaxAllowedCodeLength + 1 - i));
bits >>= 4;
}
diff --git a/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs b/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs
index 9f370513be..b37a9dd3a6 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs
@@ -14,8 +14,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
///
internal static unsafe class LosslessUtils
{
- private const uint Predictor0 = WebpConstants.ArgbBlack;
-
private const int PrefixLookupIdxMax = 512;
private const int LogLookupIdxMax = 256;
@@ -298,8 +296,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
Span transformData = transform.Data.GetSpan();
// First Row follows the L (mode=1) mode.
- PredictorAdd0(input, null, 1, output);
- PredictorAdd1(input + 1, null, width - 1, output + 1);
+ PredictorAdd0(input, 1, output);
+ PredictorAdd1(input + 1, width - 1, output + 1);
input += width;
output += width;
@@ -333,10 +331,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
switch (predictorMode)
{
case 0:
- PredictorAdd0(input + x, output + x - width, xEnd - x, output + x);
+ PredictorAdd0(input + x, xEnd - x, output + x);
break;
case 1:
- PredictorAdd1(input + x, output + x - width, xEnd - x, output + x);
+ PredictorAdd1(input + x, xEnd - x, output + x);
break;
case 2:
PredictorAdd2(input + x, output + x - width, xEnd - x, output + x);
@@ -549,14 +547,13 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
{
int logCnt = 0;
uint y = 1;
- int correction = 0;
- float vF = (float)v;
+ float vF = v;
uint origV = v;
do
{
++logCnt;
- v = v >> 1;
- y = y << 1;
+ v >>= 1;
+ y <<= 1;
}
while (v >= LogLookupIdxMax);
@@ -566,7 +563,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
// The correction factor: log(1 + d) ~ d; for very small d values, so
// log2(1 + (v % y) / v) ~ LOG_2_RECIPROCAL * (v % y)/v
// LOG_2_RECIPROCAL ~ 23/16
- correction = (int)((23 * (origV & (y - 1))) >> 4);
+ var correction = (int)((23 * (origV & (y - 1))) >> 4);
return (vF * (WebpLookupTables.Log2Table[v] + logCnt)) + correction;
}
else
@@ -633,7 +630,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
}
[MethodImpl(InliningOptions.ShortMethod)]
- private static void PredictorAdd0(uint* input, uint* upper, int numberOfPixels, uint* output)
+ private static void PredictorAdd0(uint* input, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
{
@@ -642,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
}
[MethodImpl(InliningOptions.ShortMethod)]
- private static void PredictorAdd1(uint* input, uint* upper, int numberOfPixels, uint* output)
+ private static void PredictorAdd1(uint* input, int numberOfPixels, uint* output)
{
uint left = output[-1];
for (int x = 0; x < numberOfPixels; ++x)
@@ -1092,7 +1089,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static int ColorTransformDelta(sbyte colorPred, sbyte color)
{
- return ((int)colorPred * color) >> 5;
+ return (colorPred * color) >> 5;
}
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
index b41a372fc2..c03000fd1e 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
@@ -210,7 +210,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
for (int mode = 0; mode < numPredModes; mode++)
{
- float curDiff;
for (int i = 0; i < 4; i++)
{
histoArgb[i].AsSpan().Fill(0);
@@ -256,7 +255,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
}
}
- curDiff = PredictionCostSpatialHistogram(accumulated, histoArgb);
+ var curDiff = PredictionCostSpatialHistogram(accumulated, histoArgb);
// Favor keeping the areas locally similar.
if (mode == leftMode)
@@ -436,16 +435,15 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
///
private static uint NearLossless(uint value, uint predict, int maxQuantization, int maxDiff, bool usedSubtractGreen)
{
- int quantization;
byte newGreen = 0;
byte greenDiff = 0;
- byte a, r, g, b;
+ byte a;
if (maxDiff <= 2)
{
return LosslessUtils.SubPixels(value, predict);
}
- quantization = maxQuantization;
+ var quantization = maxQuantization;
while (quantization >= maxDiff)
{
quantization >>= 1;
@@ -461,7 +459,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
a = NearLosslessComponent((byte)(value >> 24), (byte)(predict >> 24), 0xff, quantization);
}
- g = NearLosslessComponent((byte)((value >> 8) & 0xff), (byte)((predict >> 8) & 0xff), 0xff, quantization);
+ var g = NearLosslessComponent((byte)((value >> 8) & 0xff), (byte)((predict >> 8) & 0xff), 0xff, quantization);
if (usedSubtractGreen)
{
@@ -475,8 +473,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
greenDiff = NearLosslessDiff(newGreen, (byte)((value >> 8) & 0xff));
}
- r = NearLosslessComponent(NearLosslessDiff((byte)((value >> 16) & 0xff), greenDiff), (byte)((predict >> 16) & 0xff), (byte)(0xff - newGreen), quantization);
- b = NearLosslessComponent(NearLosslessDiff((byte)(value & 0xff), greenDiff), (byte)(predict & 0xff), (byte)(0xff - newGreen), quantization);
+ var r = NearLosslessComponent(NearLosslessDiff((byte)((value >> 16) & 0xff), greenDiff), (byte)((predict >> 16) & 0xff), (byte)(0xff - newGreen), quantization);
+ var b = NearLosslessComponent(NearLosslessDiff((byte)(value & 0xff), greenDiff), (byte)(predict & 0xff), (byte)(0xff - newGreen), quantization);
return ((uint)a << 24) | ((uint)r << 16) | ((uint)g << 8) | b;
}
diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
index 5b75874713..f1952c77ab 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
///
/// Encoder for lossless webp images.
///
- internal partial class Vp8LEncoder : IDisposable
+ internal class Vp8LEncoder : IDisposable
{
///
/// Maximum number of reference blocks the image will be segmented into.
@@ -1452,7 +1452,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
private static void GetHuffBitLengthsAndCodes(List histogramImage, HuffmanTreeCode[] huffmanCodes)
{
- long totalLengthSize = 0;
int maxNumSymbols = 0;
// Iterate over all histograms and get the aggregate number of codes used.
@@ -1466,7 +1465,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
(k == 0) ? histo.NumCodes() :
(k == 4) ? WebpConstants.NumDistanceCodes : 256;
huffmanCodes[startIdx + k].NumSymbols = numSymbols;
- totalLengthSize += numSymbols;
}
}
diff --git a/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs b/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs
index 3bfa94525e..de6b9d2227 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs
@@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
///
/// Data associated with a VP8L transformation to reduce the entropy.
///
- [DebuggerDisplay("Transformtype: {TransformType}")]
+ [DebuggerDisplay("Transformtype: {" + nameof(TransformType) + "}")]
internal class Vp8LTransform
{
public Vp8LTransform(Vp8LTransformType transformType, int xSize, int ySize)
diff --git a/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs b/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
index 79fbf4bbc2..7a58ccba04 100644
--- a/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
@@ -4,7 +4,6 @@
using System;
using System.Buffers;
using System.Collections.Generic;
-using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
diff --git a/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs b/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs
index 58d441e696..e45ba6b06d 100644
--- a/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs
+++ b/src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs
@@ -24,8 +24,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
public static int Quantize2Blocks(Span input, Span output, Vp8Matrix mtx)
{
- int nz;
- nz = QuantEnc.QuantizeBlock(input, output, mtx) << 0;
+ var nz = QuantEnc.QuantizeBlock(input, output, mtx) << 0;
nz |= QuantEnc.QuantizeBlock(input.Slice(1 * 16), output.Slice(1 * 16), mtx) << 1;
return nz;
}
@@ -110,16 +109,15 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
{
Span top = it.TopDerr.AsSpan((it.X * 4) + ch, 2);
Span left = it.LeftDerr.AsSpan(ch, 2);
- int err0, err1, err2, err3;
Span c = tmp.AsSpan(ch * 4 * 16, 4 * 16);
c[0] += (short)(((C1 * top[0]) + (C2 * left[0])) >> (DSHIFT - DSCALE));
- err0 = QuantEnc.QuantizeSingle(c, mtx);
+ var err0 = QuantEnc.QuantizeSingle(c, mtx);
c[1 * 16] += (short)(((C1 * top[1]) + (C2 * err0)) >> (DSHIFT - DSCALE));
- err1 = QuantEnc.QuantizeSingle(c.Slice(1 * 16), mtx);
+ var err1 = QuantEnc.QuantizeSingle(c.Slice(1 * 16), mtx);
c[2 * 16] += (short)(((C1 * err0) + (C2 * left[1])) >> (DSHIFT - DSCALE));
- err2 = QuantEnc.QuantizeSingle(c.Slice(2 * 16), mtx);
+ var err2 = QuantEnc.QuantizeSingle(c.Slice(2 * 16), mtx);
c[3 * 16] += (short)(((C1 * err1) + (C2 * err2)) >> (DSHIFT - DSCALE));
- err3 = QuantEnc.QuantizeSingle(c.Slice(3 * 16), mtx);
+ var err3 = QuantEnc.QuantizeSingle(c.Slice(3 * 16), mtx);
// TODO: set errors in rd
// rd->derr[ch][0] = (int8_t)err1;
diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs
index 070da84ae4..7a1b7ba3b2 100644
--- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs
@@ -239,13 +239,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
///
public Vp8FilterInfo[] FilterInfo { get; set; }
- public Vp8MacroBlock CurrentMacroBlock
- {
- get
- {
- return this.MacroBlockInfo[this.MbX];
- }
- }
+ public Vp8MacroBlock CurrentMacroBlock => this.MacroBlockInfo[this.MbX];
public Vp8MacroBlock LeftMacroBlock
{
@@ -260,13 +254,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
}
}
- public Vp8MacroBlockData CurrentBlockData
- {
- get
- {
- return this.MacroBlockData[this.MbX];
- }
- }
+ public Vp8MacroBlockData CurrentBlockData => this.MacroBlockData[this.MbX];
public void PrecomputeFilterStrengths()
{
diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
index 8f8c7676d2..38640e75f9 100644
--- a/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
+++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
@@ -153,13 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
///
/// Gets the current start index of the intra mode predictors.
///
- public int PredIdx
- {
- get
- {
- return this.predIdx;
- }
- }
+ public int PredIdx => this.predIdx;
///
/// Gets the non-zero pattern.
@@ -216,13 +210,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
///
public int CountDown { get; set; }
- public Vp8MacroBlockInfo CurrentMacroBlockInfo
- {
- get
- {
- return this.Mb[this.currentMbIdx];
- }
- }
+ public Vp8MacroBlockInfo CurrentMacroBlockInfo => this.Mb[this.currentMbIdx];
private Vp8MacroBlockInfo[] Mb { get; }
diff --git a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
index 333b845bc9..eed716c1b2 100644
--- a/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
@@ -358,8 +358,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
var alphas = new int[WebpConstants.MaxAlpha + 1];
this.alpha = this.MacroBlockAnalysis(width, height, it, y, u, v, yStride, uvStride, alphas, out this.uvAlpha);
int totalMb = this.mbw * this.mbw;
- this.alpha = this.alpha / totalMb;
- this.uvAlpha = this.uvAlpha / totalMb;
+ this.alpha /= totalMb;
+ this.uvAlpha /= totalMb;
// Analysis is done, proceed to actual encoding.
this.segmentHeader = new Vp8EncSegmentHeader(4);
@@ -601,7 +601,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
var centers = new int[NumMbSegments];
int weightedAverage = 0;
var map = new int[WebpConstants.MaxAlpha + 1];
- int a, n, k;
+ int n, k;
var accum = new int[NumMbSegments];
var distAccum = new int[NumMbSegments];
@@ -635,6 +635,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
// Assign nearest center for each 'a'
n = 0; // track the nearest center for current 'a'
+ int a;
for (a = minA; a <= maxA; ++a)
{
if (alphas[a] != 0)
@@ -871,8 +872,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
m.Uv.Q[1] = WebpLookupTables.AcTable[Clip(q + this.dqUvAc, 0, 127)];
var qi4 = m.Y1.Expand(0);
- var qi16 = m.Y2.Expand(1);
- var quv = m.Uv.Expand(2);
+ m.Y2.Expand(1); // qi16
+ m.Uv.Expand(2); // quv
m.I4Penalty = 1000 * qi4 * qi4;
}
diff --git a/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs b/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs
index cd501c45a6..058d4adb97 100644
--- a/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs
+++ b/src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs
@@ -807,8 +807,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
case 1:
LossyUtils.TransformDc(src, dst);
break;
- default:
- break;
}
}
diff --git a/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs b/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs
deleted file mode 100644
index 313b8e074d..0000000000
--- a/src/ImageSharp/Formats/WebP/Vp8HeaderType.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) Six Labors.
-// Licensed under the Apache License, Version 2.0.
-
-namespace SixLabors.ImageSharp.Formats.Experimental.Webp
-{
- ///
- /// Enum for the different VP8 chunk header types.
- ///
- public enum Vp8HeaderType
- {
- ///
- /// Invalid VP8 header.
- ///
- Invalid = 0,
-
- ///
- /// A VP8 header.
- ///
- Vp8 = 1,
-
- ///
- /// VP8 header, signaling the use of VP8L lossless format.
- ///
- Vp8L = 2,
-
- ///
- /// Header for a extended-VP8 chunk.
- ///
- Vp8X = 3,
- }
-}
diff --git a/src/ImageSharp/Formats/WebP/WebpAlphaFilterType.cs b/src/ImageSharp/Formats/WebP/WebpAlphaFilterType.cs
index a52d18d156..f32d2cf680 100644
--- a/src/ImageSharp/Formats/WebP/WebpAlphaFilterType.cs
+++ b/src/ImageSharp/Formats/WebP/WebpAlphaFilterType.cs
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
///
/// Enum for the different alpha filter types.
///
- internal enum WebpAlphaFilterType : int
+ internal enum WebpAlphaFilterType
{
///
/// No filtering.
diff --git a/src/ImageSharp/Formats/WebP/WebpDecoderCore.cs b/src/ImageSharp/Formats/WebP/WebpDecoderCore.cs
index 5f260deb72..24967841d3 100644
--- a/src/ImageSharp/Formats/WebP/WebpDecoderCore.cs
+++ b/src/ImageSharp/Formats/WebP/WebpDecoderCore.cs
@@ -193,8 +193,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
// The first two bit of it are reserved and should be 0.
if (imageFeatures >> 6 != 0)
{
- WebpThrowHelper.ThrowImageFormatException(
- "first two bits of the VP8X header are expected to be zero");
+ WebpThrowHelper.ThrowImageFormatException("first two bits of the VP8X header are expected to be zero");
}
// If bit 3 is set, a ICC Profile Chunk should be present.
diff --git a/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs b/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
index 73817e691e..2ff6c6001b 100644
--- a/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
+++ b/src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
@@ -4,11 +4,9 @@
using System.IO;
using System.Threading.Tasks;
-using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless;
using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy;
using SixLabors.ImageSharp.Memory;
-using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Experimental.Webp
@@ -24,14 +22,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
private readonly MemoryAllocator memoryAllocator;
///
- /// The global configuration.
- ///
- private Configuration configuration;
-
- ///
+ /// TODO: not used at the moment.
/// Indicating whether the alpha plane should be compressed with WebP lossless format.
///
- private bool alphaCompression;
+ private readonly bool alphaCompression;
///
/// Indicating whether lossy compression should be used. If false, lossless compression will be used.
@@ -80,9 +74,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
Guard.NotNull(image, nameof(image));
Guard.NotNull(stream, nameof(stream));
- this.configuration = image.GetConfiguration();
- ImageMetadata metadata = image.Metadata;
-
if (this.lossy)
{
var enc = new Vp8Encoder(this.memoryAllocator, image.Width, image.Height, this.quality, this.method, this.entropyPasses);
diff --git a/src/ImageSharp/Formats/WebP/WebpMetadata.cs b/src/ImageSharp/Formats/WebP/WebpMetadata.cs
index 60fccc020d..dea2672f1a 100644
--- a/src/ImageSharp/Formats/WebP/WebpMetadata.cs
+++ b/src/ImageSharp/Formats/WebP/WebpMetadata.cs
@@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
///
/// Gets or sets a value indicating whether the webp file contains an animation.
///
- public bool Animated { get; set; } = false;
+ public bool Animated { get; set; }
///
public IDeepCloneable DeepClone() => new WebpMetadata(this);