Browse Source

Small code cleanup / improvements

pull/1552/head
Brian Popow 5 years ago
parent
commit
df8e5fa8bc
  1. 5
      src/ImageSharp/Formats/WebP/BitReader/Vp8BitReader.cs
  2. 7
      src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs
  3. 2
      src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs
  4. 2
      src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs
  5. 2
      src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs
  6. 7
      src/ImageSharp/Formats/WebP/Lossless/CostManager.cs
  7. 9
      src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs
  8. 5
      src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs
  9. 25
      src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs
  10. 14
      src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
  11. 4
      src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
  12. 2
      src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs
  13. 1
      src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
  14. 12
      src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs
  15. 16
      src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs
  16. 16
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
  17. 11
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
  18. 2
      src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs
  19. 31
      src/ImageSharp/Formats/WebP/Vp8HeaderType.cs
  20. 2
      src/ImageSharp/Formats/WebP/WebpAlphaFilterType.cs
  21. 3
      src/ImageSharp/Formats/WebP/WebpDecoderCore.cs
  22. 13
      src/ImageSharp/Formats/WebP/WebpEncoderCore.cs
  23. 2
      src/ImageSharp/Formats/WebP/WebpMetadata.cs

5
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; }

7
src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.BitWriter
/// <param name="expectedSize">The expected size in bytes.</param>
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
/// </summary>
private protected BitWriterBase(byte[] buffer) => this.buffer = buffer;
public byte[] Buffer
{
get { return this.buffer; }
}
public byte[] Buffer => this.buffer;
/// <summary>
/// Writes the encoded bytes of the image to the stream. Call Finish() before this.

2
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;
/// <summary>
/// Initializes a new instance of the <see cref="Vp8BitWriter"/> class.

2
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);
}

2
src/ImageSharp/Formats/WebP/Lossless/CostCacheInterval.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
/// <summary>
/// The GetLengthCost(costModel, k) are cached in a CostCacheInterval.
/// </summary>
[DebuggerDisplay("Start: {Start}, End: {End}, Cost: {Cost}, Position: {Position}")]
[DebuggerDisplay("Start: {Start}, End: {End}, Cost: {Cost}")]
internal class CostCacheInterval
{
public double Cost { get; set; }

7
src/ImageSharp/Formats/WebP/Lossless/CostManager.cs

@ -255,17 +255,14 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
/// </summary>
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;
}

9
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<int> src = mappings.AsSpan(mappingIndex + 1, numUsed - mappingIndex - 1);

5
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;
}

25
src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs

@ -14,8 +14,6 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
/// </summary>
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<uint> 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)]

14
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
/// </summary>
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;
}

4
src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
/// <summary>
/// Encoder for lossless webp images.
/// </summary>
internal partial class Vp8LEncoder : IDisposable
internal class Vp8LEncoder : IDisposable
{
/// <summary>
/// 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<Vp8LHistogram> 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;
}
}

2
src/ImageSharp/Formats/WebP/Lossless/Vp8LTransform.cs

@ -9,7 +9,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless
/// <summary>
/// Data associated with a VP8L transformation to reduce the entropy.
/// </summary>
[DebuggerDisplay("Transformtype: {TransformType}")]
[DebuggerDisplay("Transformtype: {" + nameof(TransformType) + "}")]
internal class Vp8LTransform
{
public Vp8LTransform(Vp8LTransformType transformType, int xSize, int ySize)

1
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;

12
src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs

@ -24,8 +24,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
public static int Quantize2Blocks(Span<short> input, Span<short> 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<sbyte> top = it.TopDerr.AsSpan((it.X * 4) + ch, 2);
Span<sbyte> left = it.LeftDerr.AsSpan(ch, 2);
int err0, err1, err2, err3;
Span<short> 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;

16
src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs

@ -239,13 +239,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
/// </summary>
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()
{

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

@ -153,13 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
/// <summary>
/// Gets the current start index of the intra mode predictors.
/// </summary>
public int PredIdx
{
get
{
return this.predIdx;
}
}
public int PredIdx => this.predIdx;
/// <summary>
/// Gets the non-zero pattern.
@ -216,13 +210,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp.Lossy
/// </summary>
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; }

11
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;
}

2
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;
}
}

31
src/ImageSharp/Formats/WebP/Vp8HeaderType.cs

@ -1,31 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Formats.Experimental.Webp
{
/// <summary>
/// Enum for the different VP8 chunk header types.
/// </summary>
public enum Vp8HeaderType
{
/// <summary>
/// Invalid VP8 header.
/// </summary>
Invalid = 0,
/// <summary>
/// A VP8 header.
/// </summary>
Vp8 = 1,
/// <summary>
/// VP8 header, signaling the use of VP8L lossless format.
/// </summary>
Vp8L = 2,
/// <summary>
/// Header for a extended-VP8 chunk.
/// </summary>
Vp8X = 3,
}
}

2
src/ImageSharp/Formats/WebP/WebpAlphaFilterType.cs

@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
/// <summary>
/// Enum for the different alpha filter types.
/// </summary>
internal enum WebpAlphaFilterType : int
internal enum WebpAlphaFilterType
{
/// <summary>
/// No filtering.

3
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.

13
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;
/// <summary>
/// The global configuration.
/// </summary>
private Configuration configuration;
/// <summary>
/// TODO: not used at the moment.
/// Indicating whether the alpha plane should be compressed with WebP lossless format.
/// </summary>
private bool alphaCompression;
private readonly bool alphaCompression;
/// <summary>
/// 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);

2
src/ImageSharp/Formats/WebP/WebpMetadata.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Webp
/// <summary>
/// Gets or sets a value indicating whether the webp file contains an animation.
/// </summary>
public bool Animated { get; set; } = false;
public bool Animated { get; set; }
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new WebpMetadata(this);

Loading…
Cancel
Save