Browse Source

Use Numerics.Clamp

pull/1552/head
James Jackson-South 6 years ago
parent
commit
7e4879198b
  1. 4
      src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
  2. 6
      src/ImageSharp/Formats/WebP/Lossy/PassStats.cs
  3. 8
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs

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

@ -68,8 +68,8 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossless
var pixelCount = width * height;
int initialSize = pixelCount * 2;
this.quality = quality.Clamp(0, 100);
this.method = method.Clamp(0, 6);
this.quality = Numerics.Clamp(quality, 0, 100);
this.method = Numerics.Clamp(method, 0, 6);
this.bitWriter = new Vp8LBitWriter(initialSize);
this.Bgra = memoryAllocator.Allocate<uint>(pixelCount);
this.Palette = memoryAllocator.Allocate<uint>(WebPConstants.MaxPaletteSize);

6
src/ImageSharp/Formats/WebP/Lossy/PassStats.cs

@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
this.Dq = 10.0f;
this.Qmin = qMin;
this.Qmax = qMax;
this.Q = quality.Clamp(qMin, qMax);
this.Q = Numerics.Clamp(quality, qMin, qMax);
this.LastQ = this.Q;
this.Target = doSizeSearch ? targetSize
: (targetPsnr > 0.0f) ? targetPsnr
@ -65,10 +65,10 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
}
// Limit variable to avoid large swings.
this.Dq = dq.Clamp(-30.0f, 30.0f);
this.Dq = Numerics.Clamp(dq, -30.0f, 30.0f);
this.LastQ = this.Q;
this.LastValue = this.Value;
this.Q = (this.Q + this.Dq).Clamp(this.Qmin, this.Qmax);
this.Q = Numerics.Clamp(this.Q + this.Dq, this.Qmin, this.Qmax);
return this.Q;
}

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

@ -140,9 +140,9 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
this.Width = width;
this.Height = height;
this.memoryAllocator = memoryAllocator;
this.quality = quality.Clamp(0, 100);
this.method = method.Clamp(0, 6);
this.entropyPasses = entropyPasses.Clamp(1, 10);
this.quality = Numerics.Clamp(quality, 0, 100);
this.method = Numerics.Clamp(method, 0, 6);
this.entropyPasses = Numerics.Clamp(entropyPasses, 1, 10);
this.rdOptLevel = (method >= 6) ? Vp8RdLevel.RdOptTrellisAll
: (method >= 5) ? Vp8RdLevel.RdOptTrellis
: (method >= 3) ? Vp8RdLevel.RdOptBasic
@ -819,7 +819,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.WebP.Lossy
this.segmentHeader.UpdateMap = (probas[0] != 255) || (probas[1] != 255) || (probas[2] != 255);
if (!this.segmentHeader.UpdateMap)
{
this.ResetSegments();
this.ResetSegments();
}
this.segmentHeader.Size = (p[0] * (LossyUtils.Vp8BitCost(0, probas[0]) + LossyUtils.Vp8BitCost(0, probas[1]))) +

Loading…
Cancel
Save