Browse Source

Change ++i -> i++

pull/1552/head
Brian Popow 4 years ago
parent
commit
fa8892b148
  1. 22
      src/ImageSharp/Formats/WebP/AlphaDecoder.cs
  2. 4
      src/ImageSharp/Formats/WebP/BitReader/Vp8LBitReader.cs
  3. 4
      src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs
  4. 28
      src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs
  5. 4
      src/ImageSharp/Formats/WebP/Lossless/CostManager.cs
  6. 2
      src/ImageSharp/Formats/WebP/Lossless/HistogramEncoder.cs
  7. 12
      src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs
  8. 68
      src/ImageSharp/Formats/WebP/Lossless/LosslessUtils.cs
  9. 8
      src/ImageSharp/Formats/WebP/Lossless/NearLosslessEnc.cs
  10. 22
      src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs
  11. 2
      src/ImageSharp/Formats/WebP/Lossless/Vp8LBitEntropy.cs
  12. 30
      src/ImageSharp/Formats/WebP/Lossless/Vp8LEncoder.cs
  13. 2
      src/ImageSharp/Formats/WebP/Lossless/Vp8LHistogram.cs
  14. 4
      src/ImageSharp/Formats/WebP/Lossless/WebpLosslessDecoder.cs
  15. 46
      src/ImageSharp/Formats/WebP/Lossy/LossyUtils.cs
  16. 4
      src/ImageSharp/Formats/WebP/Lossy/QuantEnc.cs
  17. 2
      src/ImageSharp/Formats/WebP/Lossy/Vp8Decoder.cs
  18. 44
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncIterator.cs
  19. 2
      src/ImageSharp/Formats/WebP/Lossy/Vp8EncProba.cs
  20. 26
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoder.cs
  21. 38
      src/ImageSharp/Formats/WebP/Lossy/Vp8Encoding.cs
  22. 6
      src/ImageSharp/Formats/WebP/Lossy/Vp8Histogram.cs
  23. 6
      src/ImageSharp/Formats/WebP/Lossy/Vp8Matrix.cs
  24. 2
      src/ImageSharp/Formats/WebP/Lossy/Vp8Residual.cs
  25. 32
      src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs
  26. 8
      src/ImageSharp/Formats/WebP/WebpLookupTables.cs

22
src/ImageSharp/Formats/WebP/AlphaDecoder.cs

@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
Span<byte> deltas = dataSpan;
Span<byte> dst = alphaSpan;
Span<byte> prev = default;
for (int y = 0; y < this.Height; ++y)
for (int y = 0; y < this.Height; y++)
{
switch (this.AlphaFilterType)
{
@ -196,7 +196,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
Span<byte> alphaSpan = this.Alpha.Memory.Span;
Span<byte> prev = this.PrevRow == 0 ? null : alphaSpan.Slice(this.Width * this.PrevRow);
for (int y = firstRow; y < lastRow; ++y)
for (int y = firstRow; y < lastRow; y++)
{
switch (this.AlphaFilterType)
{
@ -282,10 +282,10 @@ namespace SixLabors.ImageSharp.Formats.Webp
int pixelsPerByte = 1 << transform.Bits;
int countMask = pixelsPerByte - 1;
int bitMask = (1 << bitsPerPixel) - 1;
for (int y = yStart; y < yEnd; ++y)
for (int y = yStart; y < yEnd; y++)
{
int packedPixels = 0;
for (int x = 0; x < width; ++x)
for (int x = 0; x < width; x++)
{
if ((x & countMask) == 0)
{
@ -309,7 +309,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
{
byte pred = (byte)(prev == null ? 0 : prev[0]);
for (int i = 0; i < width; ++i)
for (int i = 0; i < width; i++)
{
byte val = (byte)(pred + input[i]);
pred = val;
@ -325,7 +325,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
}
else
{
for (int i = 0; i < width; ++i)
for (int i = 0; i < width; i++)
{
dst[i] = (byte)(prev[i] + input[i]);
}
@ -343,7 +343,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
byte prev0 = prev[0];
byte topLeft = prev0;
byte left = prev0;
for (int i = 0; i < width; ++i)
for (int i = 0; i < width; i++)
{
byte top = prev[i];
left = (byte)(input[i] + GradientPredictor(left, top, topLeft));
@ -366,7 +366,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
return false;
}
for (int i = 0; i < hdr.NumHTreeGroups; ++i)
for (int i = 0; i < hdr.NumHTreeGroups; i++)
{
List<HuffmanCode[]> htrees = hdr.HTreeGroups[i].HTrees;
if (htrees[HuffIndex.Red][0].BitsUsed > 0)
@ -391,9 +391,9 @@ namespace SixLabors.ImageSharp.Formats.Webp
private static void MapAlpha(Span<byte> src, Span<uint> colorMap, Span<byte> dst, int yStart, int yEnd, int width)
{
int offset = 0;
for (int y = yStart; y < yEnd; ++y)
for (int y = yStart; y < yEnd; y++)
{
for (int x = 0; x < width; ++x)
for (int x = 0; x < width; x++)
{
dst[offset] = GetAlphaValue((int)colorMap[src[offset]]);
offset++;
@ -414,7 +414,7 @@ namespace SixLabors.ImageSharp.Formats.Webp
[MethodImpl(InliningOptions.ShortMethod)]
private static void ExtractGreen(Span<uint> argb, Span<byte> alpha, int size)
{
for (int i = 0; i < size; ++i)
for (int i = 0; i < size; i++)
{
alpha[i] = (byte)(argb[i] >> 8);
}

4
src/ImageSharp/Formats/WebP/BitReader/Vp8LBitReader.cs

@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitReader
ulong currentValue = 0;
System.Span<byte> dataSpan = this.Data.Memory.Span;
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 8; i++)
{
currentValue |= (ulong)dataSpan[i] << (8 * i);
}
@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitReader
ulong currentValue = 0;
System.Span<byte> dataSpan = this.Data.Memory.Span;
for (int i = 0; i < length; ++i)
for (int i = 0; i < length; i++)
{
currentValue |= (ulong)dataSpan[i] << (8 * i);
}

4
src/ImageSharp/Formats/WebP/BitWriter/Vp8BitWriter.cs

@ -597,10 +597,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter
else
{
Span<byte> topPred = it.Preds.AsSpan(predIdx - predsWidth);
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
int left = it.Preds[predIdx - 1];
for (int x = 0; x < 4; ++x)
for (int x = 0; x < 4; x++)
{
byte[] probas = WebpLookupTables.ModesProba[topPred[x], left];
left = bitWriter.PutI4Mode(it.Preds[predIdx + x], probas);

28
src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs

@ -188,7 +188,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
int extraBits = 0, extraBitsValue = 0;
int code = LosslessUtils.PrefixEncode(len, ref extraBits, ref extraBitsValue);
for (int i = 0; i <= cacheBitsMax; ++i)
for (int i = 0; i <= cacheBitsMax; i++)
{
++histos[i].Literal[WebpConstants.NumLiteralCodes + code];
}
@ -214,7 +214,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
}
for (int i = 0; i <= cacheBitsMax; ++i)
for (int i = 0; i <= cacheBitsMax; i++)
{
double entropy = histos[i].EstimateBits();
if (i == 0 || entropy < entropyMin)
@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Add first pixel as literal.
AddSingleLiteralWithCostModel(bgra, colorCache, costModel, 0, useColorCache, 0.0f, costManager.Costs, distArray);
for (int i = 1; i < pixCount; ++i)
for (int i = 1; i < pixCount; i++)
{
float prevCost = costManager.Costs[i - 1];
int offset = hashChain.FindOffset(i);
@ -315,7 +315,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{
int lenJ = 0;
int j;
for (j = i; j <= reach; ++j)
for (j = i; j <= reach; j++)
{
int offsetJ = hashChain.FindOffset(j + 1);
lenJ = hashChain.FindLength(j + 1);
@ -484,7 +484,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// [i,i+len) + [i+len, length of best match at i+len)
// while we check if we can use:
// [i,j) (where j<=i+len) + [j, length of best match at j)
for (j = iLastCheck + 1; j <= jMax; ++j)
for (j = iLastCheck + 1; j <= jMax; j++)
{
int lenJ = hashChain.FindLength(j);
int reach = j + (lenJ >= MinLength ? lenJ : 1); // 1 for single literal.
@ -514,7 +514,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
refs.Add(PixOrCopy.CreateCopy((uint)offset, (ushort)len));
if (useColorCache)
{
for (j = i; j < i + len; ++j)
for (j = i; j < i + len; j++)
{
colorCache.Insert(bgra[j]);
}
@ -563,9 +563,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Figure out the window offsets around a pixel. They are stored in a
// spiraling order around the pixel as defined by DistanceToPlaneCode.
for (int y = 0; y <= 6; ++y)
for (int y = 0; y <= 6; y++)
{
for (int x = -6; x <= 6; ++x)
for (int x = -6; x <= 6; x++)
{
int offset = (y * xSize) + x;
@ -586,7 +586,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
// For narrow images, not all plane codes are reached, so remove those.
for (i = 0; i < WindowOffsetsSizeMax; ++i)
for (i = 0; i < WindowOffsetsSizeMax; i++)
{
if (windowOffsets[i] == 0)
{
@ -598,10 +598,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Given a pixel P, find the offsets that reach pixels unreachable from P-1
// with any of the offsets in windowOffsets[].
for (i = 0; i < windowOffsetsSize; ++i)
for (i = 0; i < windowOffsetsSize; i++)
{
bool isReachable = false;
for (int j = 0; j < windowOffsetsSize && !isReachable; ++j)
for (int j = 0; j < windowOffsetsSize && !isReachable; j++)
{
isReachable |= windowOffsets[i] == windowOffsets[j] + 1;
}
@ -614,7 +614,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
hashChain.OffsetLength[0] = 0;
for (i = 1; i < pixelCount; ++i)
for (i = 1; i < pixelCount; i++)
{
int ind;
int bestLength = hashChainBest.FindLength(i);
@ -625,7 +625,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{
// Do not recompute the best match if we already have a maximal one in the window.
bestOffset = hashChainBest.FindOffset(i);
for (ind = 0; ind < windowOffsetsSize; ++ind)
for (ind = 0; ind < windowOffsetsSize; ind++)
{
if (bestOffset == windowOffsets[ind])
{
@ -645,7 +645,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
bestOffset = usePrev ? bestOffsetPrev : 0;
// Find the longest match in a window around the pixel.
for (ind = 0; ind < numInd; ++ind)
for (ind = 0; ind < numInd; ind++)
{
int currLength = 0;
int j = i;

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

@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
if (len < skipDistance)
{
for (int j = position; j < position + len; ++j)
for (int j = position; j < position + len; j++)
{
int k = j - position;
float costTmp = (float)(distanceCost + this.CostCache[k]);
@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
CostInterval interval = this.head;
for (int i = 0; i < this.CacheIntervalsSize && this.CacheIntervals[i].Start < len; ++i)
for (int i = 0; i < this.CacheIntervalsSize && this.CacheIntervals[i].Start < len; i++)
{
// Define the intersection of the ith interval with the new one.
int start = position + this.CacheIntervals[i].Start;

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

@ -152,7 +152,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static int HistogramCopyAndAnalyze(List<Vp8LHistogram> origHistograms, List<Vp8LHistogram> histograms, ushort[] histogramSymbols)
{
for (int clusterId = 0, i = 0; i < origHistograms.Count; ++i)
for (int clusterId = 0, i = 0; i < origHistograms.Count; i++)
{
Vp8LHistogram origHistogram = origHistograms[i];
origHistogram.UpdateHistogramCost();

12
src/ImageSharp/Formats/WebP/Lossless/HuffmanUtils.cs

@ -63,13 +63,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Mark any seq of non-0's that is longer as 7 as a goodForRle.
uint symbol = counts[0];
int stride = 0;
for (int i = 0; i < length + 1; ++i)
for (int i = 0; i < length + 1; i++)
{
if (i == length || counts[i] != symbol)
{
if ((symbol == 0 && stride >= 5) || (symbol != 0 && stride >= 7))
{
for (int k = 0; k < stride; ++k)
for (int k = 0; k < stride; k++)
{
goodForRle[i - k - 1] = true;
}
@ -91,7 +91,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
stride = 0;
uint limit = counts[0];
uint sum = 0;
for (int i = 0; i < length + 1; ++i)
for (int i = 0; i < length + 1; i++)
{
if (i == length || goodForRle[i] || (i != 0 && goodForRle[i - 1]) || !ValuesShouldBeCollapsedToStrideAverage((int)counts[i], (int)limit))
{
@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
count = 0;
}
for (k = 0; k < stride; ++k)
for (k = 0; k < stride; k++)
{
// We don't want to change value at counts[i],
// that is already belonging to the next stride. Thus - 1.
@ -164,7 +164,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
uint countMin;
int treeSizeOrig = 0;
for (int i = 0; i < histogramSize; ++i)
for (int i = 0; i < histogramSize; i++)
{
if (histogram[i] != 0)
{
@ -505,7 +505,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
if (repetitions < 3)
{
int i;
for (i = 0; i < repetitions; ++i)
for (i = 0; i < repetitions; i++)
{
tokens[pos].Code = (byte)value;
tokens[pos].ExtraBits = 0;

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

@ -296,10 +296,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
uint[] decodedPixelData = new uint[width * height];
int pixelDataPos = 0;
for (int y = 0; y < height; ++y)
for (int y = 0; y < height; y++)
{
uint packedPixels = 0;
for (int x = 0; x < width; ++x)
for (int x = 0; x < width; x++)
{
// We need to load fresh 'packed_pixels' once every
// 'pixelsPerByte' increments of x. Fortunately, pixelsPerByte
@ -319,9 +319,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
else
{
for (int y = 0; y < height; ++y)
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; ++x)
for (int x = 0; x < width; x++)
{
uint colorMapIndex = GetArgbIndex(pixelData[decodedPixels]);
pixelData[decodedPixels] = colorMap[(int)colorMapIndex];
@ -373,7 +373,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
pixelPos += remainingWidth;
}
++y;
y++;
if ((y & mask) == 0)
{
predRowIdxStart += tilesPerRow;
@ -623,7 +623,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
input += width;
output += width;
++y;
y++;
if ((y & mask) == 0)
{
@ -867,7 +867,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd0(uint* input, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
output[x] = AddPixels(input[x], WebpConstants.ArgbBlack);
}
@ -877,7 +877,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static void PredictorAdd1(uint* input, int numberOfPixels, uint* output)
{
uint left = output[-1];
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
output[x] = left = AddPixels(input[x], left);
}
@ -886,7 +886,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd2(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor2(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -896,7 +896,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd3(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor3(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -906,7 +906,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd4(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor4(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -916,7 +916,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd5(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor5(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -926,7 +926,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd6(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor6(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -936,7 +936,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd7(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor7(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -946,7 +946,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd8(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor8(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -956,7 +956,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd9(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor9(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -966,7 +966,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd10(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor10(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -976,7 +976,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd11(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor11(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -986,7 +986,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd12(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor12(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -996,7 +996,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
private static void PredictorAdd13(uint* input, uint* upper, int numberOfPixels, uint* output)
{
for (int x = 0; x < numberOfPixels; ++x)
for (int x = 0; x < numberOfPixels; x++)
{
uint pred = Predictor13(output[x - 1], upper + x);
output[x] = AddPixels(input[x], pred);
@ -1042,7 +1042,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub0(uint* input, int numPixels, uint* output)
{
for (int i = 0; i < numPixels; ++i)
for (int i = 0; i < numPixels; i++)
{
output[i] = SubPixels(input[i], WebpConstants.ArgbBlack);
}
@ -1051,7 +1051,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub1(uint* input, int numPixels, uint* output)
{
for (int i = 0; i < numPixels; ++i)
for (int i = 0; i < numPixels; i++)
{
output[i] = SubPixels(input[i], input[i - 1]);
}
@ -1060,7 +1060,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub2(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor2(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1070,7 +1070,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub3(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor3(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1080,7 +1080,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub4(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor4(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1090,7 +1090,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub5(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor5(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1100,7 +1100,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub6(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor6(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1110,7 +1110,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub7(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor7(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1120,7 +1120,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub8(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor8(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1130,7 +1130,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub9(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor9(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1140,7 +1140,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub10(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor10(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1150,7 +1150,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub11(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor11(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1160,7 +1160,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub12(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor12(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);
@ -1170,7 +1170,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
[MethodImpl(InliningOptions.ShortMethod)]
public static void PredictorSub13(uint* input, uint* upper, int numPixels, uint* output)
{
for (int x = 0; x < numPixels; ++x)
for (int x = 0; x < numPixels; x++)
{
uint pred = Predictor13(input[x - 1], upper + x);
output[x] = SubPixels(input[x], pred);

8
src/ImageSharp/Formats/WebP/Lossless/NearLosslessEnc.cs

@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// For small icon images, don't attempt to apply near-lossless compression.
if ((xSize < MinDimForNearLossless && ySize < MinDimForNearLossless) || ySize < 3)
{
for (int i = 0; i < ySize; ++i)
for (int i = 0; i < ySize; i++)
{
argbSrc.Slice(i * stride, xSize).CopyTo(argbDst.Slice(i * xSize, xSize));
}
@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
NearLossless(xSize, ySize, argbSrc, stride, limitBits, copyBuffer, argbDst);
for (int i = limitBits - 1; i != 0; --i)
for (int i = limitBits - 1; i != 0; i--)
{
NearLossless(xSize, ySize, argbDst, xSize, i, copyBuffer, argbDst);
}
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
int srcOffset = 0;
int dstOffset = 0;
for (y = 0; y < ySize; ++y)
for (y = 0; y < ySize; y++)
{
if (y == 0 || y == ySize - 1)
{
@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
argbSrc.Slice(srcOffset + stride, xSize).CopyTo(nextRow);
argbDst[dstOffset] = argbSrc[srcOffset];
argbDst[dstOffset + xSize - 1] = argbSrc[srcOffset + xSize - 1];
for (int x = 1; x < xSize - 1; ++x)
for (int x = 1; x < xSize - 1; x++)
{
if (IsSmooth(prevRow, currRow, nextRow, x, limit))
{

22
src/ImageSharp/Formats/WebP/Lossless/PredictorEncoder.cs

@ -60,16 +60,16 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
if (lowEffort)
{
for (int i = 0; i < tilesPerRow * tilesPerCol; ++i)
for (int i = 0; i < tilesPerRow * tilesPerCol; i++)
{
image[i] = WebpConstants.ArgbBlack | (PredLowEffort << 8);
}
}
else
{
for (int tileY = 0; tileY < tilesPerCol; ++tileY)
for (int tileY = 0; tileY < tilesPerCol; tileY++)
{
for (int tileX = 0; tileX < tilesPerRow; ++tileX)
for (int tileX = 0; tileX < tilesPerRow; tileX++)
{
int pred = GetBestPredictorForTile(
width,
@ -345,7 +345,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
fixed (uint* currentRow = currentRowSpan)
fixed (uint* upperRow = upperRowSpan)
{
for (int x = xStart; x < xEnd; ++x)
for (int x = xStart; x < xEnd; x++)
{
uint predict = 0;
uint residual;
@ -583,7 +583,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
Span<byte> currentMaxDiffs = MemoryMarshal.Cast<uint, byte>(currentRow.Slice(width + 1));
Span<byte> lowerMaxDiffs = currentMaxDiffs.Slice(width);
for (int y = 0; y < height; ++y)
for (int y = 0; y < height; y++)
{
Span<uint> tmp32 = upperRow;
upperRow = currentRow;
@ -747,7 +747,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
right = AddGreenToBlueAndRed(right);
}
for (int x = 1; x < width - 1; ++x)
for (int x = 1; x < width - 1; x++)
{
uint up = argb[offset - stride + x];
uint down = argb[offset + stride + x];
@ -991,7 +991,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
const int span = 8;
Span<ushort> values = stackalloc ushort[span];
for (int y = 0; y < tileHeight; ++y)
for (int y = 0; y < tileHeight; y++)
{
Span<uint> srcSpan = bgra.Slice(y * stride);
#pragma warning disable SA1503 // Braces should not be omitted
@ -1014,7 +1014,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
Vector128<byte> c = Sse2.Subtract(a.AsByte(), b.AsByte()); // x r'
Vector128<byte> d = Sse2.And(c, mask.AsByte()); // 0 r'
Sse2.Store(dst, d.AsUInt16());
for (int i = 0; i < span; ++i)
for (int i = 0; i < span; i++)
{
++histo[values[i]];
}
@ -1066,7 +1066,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
var shufflerLow = Vector128.Create(255, 2, 255, 6, 255, 10, 255, 14, 255, 255, 255, 255, 255, 255, 255, 255);
var shufflerHigh = Vector128.Create(255, 255, 255, 255, 255, 255, 255, 255, 255, 2, 255, 6, 255, 10, 255, 14);
for (int y = 0; y < tileHeight; ++y)
for (int y = 0; y < tileHeight; y++)
{
Span<uint> srcSpan = bgra.Slice(y * stride);
#pragma warning disable SA1503 // Braces should not be omitted
@ -1092,7 +1092,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
Vector128<byte> d = Sse2.Subtract(c, a.AsByte());
Vector128<byte> e = Sse2.And(d, maskblue);
Sse2.Store(dst, e.AsUInt16());
for (int i = 0; i < span; ++i)
for (int i = 0; i < span; i++)
{
++histo[values[i]];
}
@ -1132,7 +1132,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static float PredictionCostSpatialHistogram(int[][] accumulated, int[][] tile)
{
double retVal = 0.0d;
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
double kExpValue = 0.94;
retVal += PredictionCostSpatial(tile[i], 1, kExpValue);

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

@ -135,7 +135,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
this.Init();
for (i = 1; i < length; ++i)
for (i = 1; i < length; i++)
{
uint xi = x[i];
if (xi != xPrev)

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

@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// We round the block size up, so we're guaranteed to have at most MaxRefsBlockPerImage blocks used:
int refsBlockSize = ((pixelCount - 1) / MaxRefsBlockPerImage) + 1;
for (int i = 0; i < this.Refs.Length; ++i)
for (int i = 0; i < this.Refs.Length; i++)
{
this.Refs[i] = new Vp8LBackwardRefs
{
@ -458,7 +458,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Fill in the different LZ77s.
foreach (CrunchConfig crunchConfig in crunchConfigs)
{
for (int j = 0; j < nlz77s; ++j)
for (int j = 0; j < nlz77s; j++)
{
crunchConfig.SubConfigs.Add(new CrunchSubConfig
{
@ -559,7 +559,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
using IMemoryOwner<uint> histogramBgraBuffer = this.memoryAllocator.Allocate<uint>(histogramImageXySize);
Span<uint> histogramBgra = histogramBgraBuffer.GetSpan();
int maxIndex = 0;
for (int i = 0; i < histogramImageXySize; ++i)
for (int i = 0; i < histogramImageXySize; i++)
{
int symbolIndex = histogramSymbols[i] & 0xffff;
histogramBgra[i] = (uint)(symbolIndex << 8);
@ -584,7 +584,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Store Huffman codes.
// Find maximum number of symbols for the huffman tree-set.
int maxTokens = 0;
for (int i = 0; i < 5 * histogramImage.Count; ++i)
for (int i = 0; i < 5 * histogramImage.Count; i++)
{
HuffmanTreeCode codes = huffmanCodes[i];
if (maxTokens < codes.NumSymbols)
@ -599,7 +599,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
tokens[i] = new HuffmanTreeToken();
}
for (int i = 0; i < 5 * histogramImage.Count; ++i)
for (int i = 0; i < 5 * histogramImage.Count; i++)
{
HuffmanTreeCode codes = huffmanCodes[i];
this.StoreHuffmanCode(huffTree, tokens, codes);
@ -743,7 +743,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
// Find maximum number of symbols for the huffman tree-set.
int maxTokens = 0;
for (int i = 0; i < 5; ++i)
for (int i = 0; i < 5; i++)
{
HuffmanTreeCode codes = huffmanCodes[i];
if (maxTokens < codes.NumSymbols)
@ -753,13 +753,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
var tokens = new HuffmanTreeToken[maxTokens];
for (int i = 0; i < tokens.Length; ++i)
for (int i = 0; i < tokens.Length; i++)
{
tokens[i] = new HuffmanTreeToken();
}
// Store Huffman codes.
for (int i = 0; i < 5; ++i)
for (int i = 0; i < 5; i++)
{
HuffmanTreeCode codes = huffmanCodes[i];
this.StoreHuffmanCode(huffTree, tokens, codes);
@ -778,7 +778,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
int maxSymbol = 1 << maxBits;
// Check whether it's a small tree.
for (int i = 0; i < huffmanCode.NumSymbols && count < 3; ++i)
for (int i = 0; i < huffmanCode.NumSymbols && count < 3; i++)
{
if (huffmanCode.CodeLengths[i] != 0)
{
@ -1085,7 +1085,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
histo[(int)HistoIx.HistoBluePred * 256]++;
histo[(int)HistoIx.HistoAlphaPred * 256]++;
for (int j = 0; j < (int)HistoIx.HistoTotal; ++j)
for (int j = 0; j < (int)HistoIx.HistoTotal; j++)
{
var bitEntropy = new Vp8LBitEntropy();
Span<uint> curHisto = histo.Slice(j * 256, 256);
@ -1486,7 +1486,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{
uint predict = 0x000000;
byte signFound = 0x00;
for (int i = 0; i < numColors; ++i)
for (int i = 0; i < numColors; i++)
{
uint diff = LosslessUtils.SubPixels(palette[i], predict);
byte rd = (byte)((diff >> 16) & 0xff);
@ -1520,11 +1520,11 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static void GreedyMinimizeDeltas(Span<uint> palette, int numColors)
{
uint predict = 0x00000000;
for (int i = 0; i < numColors; ++i)
for (int i = 0; i < numColors; i++)
{
int bestIdx = i;
uint bestScore = ~0U;
for (int k = i; k < numColors; ++k)
for (int k = i; k < numColors; k++)
{
uint curScore = PaletteColorDistance(palette[k], predict);
if (bestScore > curScore)
@ -1645,7 +1645,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
int bitDepth = 1 << (3 - xBits);
int mask = (1 << xBits) - 1;
uint code = 0xff000000;
for (x = 0; x < width; ++x)
for (x = 0; x < width; x++)
{
int xSub = x & mask;
if (xSub == 0)
@ -1659,7 +1659,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
}
else
{
for (x = 0; x < width; ++x)
for (x = 0; x < width; x++)
{
dst[x] = (uint)(0xff000000 | (row[x] << 8));
}

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

@ -496,7 +496,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
private static double ExtraCost(Span<uint> population, int length)
{
double cost = 0.0d;
for (int i = 2; i < length - 2; ++i)
for (int i = 2; i < length - 2; i++)
{
cost += (i >> 1) * population[i + 2];
}

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

@ -384,7 +384,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
decoder.Metadata.HuffmanSubSampleBits = huffmanPrecision;
// TODO: Isn't huffmanPixels the length of the span?
for (int i = 0; i < huffmanPixels; ++i)
for (int i = 0; i < huffmanPixels; i++)
{
// The huffman data is stored in red and green bytes.
uint group = (huffmanImageSpan[i] >> 8) & 0xffff;
@ -983,7 +983,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless
{
Span<byte> dst = data.Slice(pos);
Span<byte> src = data.Slice(pos - dist);
for (int i = 0; i < length; ++i)
for (int i = 0; i < length; i++)
{
dst[i] = src[i];
}

46
src/ImageSharp/Formats/WebP/Lossy/LossyUtils.cs

@ -25,9 +25,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int count = 0;
int aOffset = 0;
int bOffset = 0;
for (int y = 0; y < h; ++y)
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; ++x)
for (int x = 0; x < w; x++)
{
int diff = a[aOffset + x] - b[bOffset + x];
count += diff * diff;
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
public static void Copy(Span<byte> src, Span<byte> dst, int w, int h)
{
int offset = 0;
for (int y = 0; y < h; ++y)
for (int y = 0; y < h; y++)
{
src.Slice(offset, w).CopyTo(dst.Slice(offset, w));
offset += WebpConstants.Bps;
@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int offsetMinus1 = offset - 1;
int offsetMinusBps = offset - WebpConstants.Bps;
int dc = 16;
for (int j = 0; j < 16; ++j)
for (int j = 0; j < 16; j++)
{
// DC += dst[-1 + j * BPS] + dst[j - BPS];
dc += yuv[offsetMinus1 + (j * WebpConstants.Bps)] + yuv[offsetMinusBps + j];
@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// vertical
Span<byte> src = yuv.Slice(offset - WebpConstants.Bps, 16);
for (int j = 0; j < 16; ++j)
for (int j = 0; j < 16; j++)
{
// memcpy(dst + j * BPS, dst - BPS, 16);
src.CopyTo(dst.Slice(j * WebpConstants.Bps));
@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// horizontal
offset--;
for (int j = 16; j > 0; --j)
for (int j = 16; j > 0; j--)
{
// memset(dst, dst[-1], 16);
byte v = yuv[offset];
@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// DC with top samples not available.
int dc = 8;
for (int j = 0; j < 16; ++j)
for (int j = 0; j < 16; j++)
{
// DC += dst[-1 + j * BPS];
dc += yuv[-1 + (j * WebpConstants.Bps) + offset];
@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// DC with left samples not available.
int dc = 8;
for (int i = 0; i < 16; ++i)
for (int i = 0; i < 16; i++)
{
// DC += dst[i - BPS];
dc += yuv[i - WebpConstants.Bps + offset];
@ -157,7 +157,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int dc0 = 8;
int offsetMinus1 = offset - 1;
int offsetMinusBps = offset - WebpConstants.Bps;
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 8; i++)
{
// dc0 += dst[i - BPS] + dst[-1 + i * BPS];
dc0 += yuv[offsetMinusBps + i] + yuv[offsetMinus1 + (i * WebpConstants.Bps)];
@ -187,7 +187,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// horizontal
offset--;
for (int j = 0; j < 8; ++j)
for (int j = 0; j < 8; j++)
{
// memset(dst, dst[-1], 8);
// dst += BPS;
@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// DC with no left samples.
int offsetMinusBps = offset - WebpConstants.Bps;
int dc0 = 4;
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 8; i++)
{
// dc0 += dst[i - BPS];
dc0 += yuv[offsetMinusBps + i];
@ -236,7 +236,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int dc = 4;
int offsetMinusBps = offset - WebpConstants.Bps;
int offsetMinusOne = offset - 1;
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
dc += yuv[offsetMinusBps + i] + yuv[offsetMinusOne + (i * WebpConstants.Bps)];
}
@ -507,7 +507,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
public static void TransformWht(Span<short> input, Span<short> output)
{
int[] tmp = new int[16];
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
int iPlus4 = 4 + i;
int iPlus8 = 8 + i;
@ -523,7 +523,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
}
int outputOffset = 0;
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
int imul4 = i * 4;
int dc = tmp[0 + imul4] + 3;
@ -551,7 +551,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// horizontal pass.
int inputOffset = 0;
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
int inputOffsetPlusOne = inputOffset + 1;
int inputOffsetPlusTwo = inputOffset + 2;
@ -569,7 +569,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
}
// vertical pass
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
int a0 = tmp[0 + i] + tmp[8 + i];
int a1 = tmp[4 + i] + tmp[12 + i];
@ -624,7 +624,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// In the worst case scenario, the input to clip_8b() can be as large as [-60713, 60968].
tmpOffset = 0;
int dstOffset = 0;
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
// horizontal pass
int tmpOffsetPlus4 = tmpOffset + 4;
@ -648,9 +648,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
public static void TransformDc(Span<short> src, Span<byte> dst)
{
int dc = src[0] + 4;
for (int j = 0; j < 4; ++j)
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
Store(dst, i, j, dc);
}
@ -705,7 +705,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int thresh2 = (2 * thresh) + 1;
int end = 16 + offset;
for (int i = offset; i < end; ++i)
for (int i = offset; i < end; i++)
{
if (NeedsFilter(p, i, stride, thresh2))
{
@ -841,7 +841,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
[MethodImpl(InliningOptions.ShortMethod)]
private static void Put16(int v, Span<byte> dst)
{
for (int j = 0; j < 16; ++j)
for (int j = 0; j < 16; j++)
{
Memset(dst.Slice(j * WebpConstants.Bps), (byte)v, 0, 16);
}
@ -855,9 +855,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
byte p = yuv[topOffset - 1];
int leftOffset = offset - 1;
byte left = yuv[leftOffset];
for (int y = 0; y < size; ++y)
for (int y = 0; y < size; y++)
{
for (int x = 0; x < size; ++x)
for (int x = 0; x < size; x++)
{
dst[x] = (byte)Clamp255(left + top[x] - p);
}

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

@ -592,7 +592,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
uint v = src[0] * 0x01010101u;
Span<byte> vSpan = BitConverter.GetBytes(v).AsSpan();
for (int i = 0; i < 16; ++i)
for (int i = 0; i < 16; i++)
{
if (!src.Slice(0, 4).SequenceEqual(vSpan) || !src.Slice(4, 4).SequenceEqual(vSpan) ||
!src.Slice(8, 4).SequenceEqual(vSpan) || !src.Slice(12, 4).SequenceEqual(vSpan))
@ -612,7 +612,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int score = 0;
while (numBlocks-- > 0)
{
for (int i = 1; i < 16; ++i)
for (int i = 1; i < 16; i++)
{
// omit DC, we're only interested in AC
score += levels[i] != 0 ? 1 : 0;

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

@ -271,7 +271,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
baseLevel = hdr.FilterLevel;
}
for (int i4x4 = 0; i4x4 <= 1; ++i4x4)
for (int i4x4 = 0; i4x4 <= 1; i4x4++)
{
Vp8FilterInfo info = this.FilterStrength[s, i4x4];
int level = baseLevel;

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

@ -238,14 +238,14 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
this.I4BoundaryIdx = this.vp8TopLeftI4[0];
// Import the boundary samples.
for (i = 0; i < 17; ++i)
for (i = 0; i < 17; i++)
{
// left
this.I4Boundary[i] = this.YLeft[15 - i + 1];
}
Span<byte> yTop = this.YTop.AsSpan(this.yTopIdx);
for (i = 0; i < 16; ++i)
for (i = 0; i < 16; i++)
{
// top
this.I4Boundary[17 + i] = yTop[i];
@ -254,7 +254,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// top-right samples have a special case on the far right of the picture.
if (this.X < this.mbw - 1)
{
for (i = 16; i < 16 + 4; ++i)
for (i = 16; i < 16 + 4; i++)
{
this.I4Boundary[17 + i] = yTop[i];
}
@ -262,7 +262,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
else
{
// else, replicate the last valid pixel four times
for (i = 16; i < 16 + 4; ++i)
for (i = 16; i < 16 + 4; i++)
{
this.I4Boundary[17 + i] = this.I4Boundary[17 + 15];
}
@ -476,7 +476,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
public void SetIntra16Mode(int mode)
{
Span<byte> preds = this.Preds.AsSpan(this.predIdx);
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
preds.Slice(0, 4).Fill((byte)mode);
preds = preds.Slice(this.predsWidth);
@ -489,7 +489,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int modesIdx = 0;
int predIdx = this.predIdx;
for (int y = 4; y > 0; --y)
for (int y = 4; y > 0; y--)
{
modes.AsSpan(modesIdx, 4).CopyTo(this.Preds.AsSpan(predIdx));
predIdx += this.predsWidth;
@ -514,9 +514,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// AC
res.Init(1, 0, proba);
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
for (int x = 0; x < 4; ++x)
for (int x = 0; x < 4; x++)
{
int ctx = this.TopNz[x] + this.LeftNz[y];
res.SetCoeffs(rd.YAcLevels.AsSpan((x + (y * 4)) * 16, 16));
@ -564,9 +564,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
res.Init(0, 2, proba);
for (int ch = 0; ch <= 2; ch += 2)
{
for (int y = 0; y < 2; ++y)
for (int y = 0; y < 2; y++)
{
for (int x = 0; x < 2; ++x)
for (int x = 0; x < 2; x++)
{
int ctx = this.TopNz[4 + ch + x] + this.LeftNz[4 + ch + y];
res.SetCoeffs(rd.UvLevels.AsSpan(((ch * 2) + x + (y * 2)) * 16, 16));
@ -643,12 +643,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
if (x < this.mbw - 1)
{
// left
for (int i = 0; i < 16; ++i)
for (int i = 0; i < 16; i++)
{
this.YLeft[i + 1] = ySrc[15 + (i * WebpConstants.Bps)];
}
for (int i = 0; i < 8; ++i)
for (int i = 0; i < 8; i++)
{
this.UvLeft[i + 1] = uvSrc[7 + (i * WebpConstants.Bps)];
this.UvLeft[i + 16 + 1] = uvSrc[15 + (i * WebpConstants.Bps)];
@ -676,7 +676,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int i;
// Update the cache with 7 fresh samples.
for (i = 0; i <= 3; ++i)
for (i = 0; i <= 3; i++)
{
top[topOffset - 4 + i] = blk[i + (3 * WebpConstants.Bps)]; // Store future top samples.
}
@ -684,7 +684,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
if ((this.I4 & 3) != 3)
{
// if not on the right sub-blocks #3, #7, #11, #15
for (i = 0; i <= 2; ++i)
for (i = 0; i <= 2; i++)
{
// store future left samples
top[topOffset + i] = blk[3 + ((2 - i) * WebpConstants.Bps)];
@ -693,7 +693,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
else
{
// else replicate top-right samples, as says the specs.
for (i = 0; i <= 3; ++i)
for (i = 0; i <= 3; i++)
{
top[topOffset + i] = top[topOffset + i + 4];
}
@ -816,12 +816,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
private void Mean16x4(Span<byte> input, Span<uint> dc)
{
for (int k = 0; k < 4; ++k)
for (int k = 0; k < 4; k++)
{
uint avg = 0;
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
for (int x = 0; x < 4; ++x)
for (int x = 0; x < 4; x++)
{
avg += input[x + (y * WebpConstants.Bps)];
}
@ -836,7 +836,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int dstIdx = 0;
int srcIdx = 0;
for (int i = 0; i < h; ++i)
for (int i = 0; i < h; i++)
{
// memcpy(dst, src, w);
src.Slice(srcIdx, w).CopyTo(dst.Slice(dstIdx));
@ -850,7 +850,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
srcIdx += srcStride;
}
for (int i = h; i < size; ++i)
for (int i = h; i < size; i++)
{
// memcpy(dst, dst - BPS, size);
dst.Slice(dstIdx - WebpConstants.Bps, size).CopyTo(dst.Slice(dstIdx));
@ -862,13 +862,13 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int i;
int srcIdx = 0;
for (i = 0; i < len; ++i)
for (i = 0; i < len; i++)
{
dst[i] = src[srcIdx];
srcIdx += srcStride;
}
for (; i < totalLen; ++i)
for (; i < totalLen; i++)
{
dst[i] = dst[len - 1];
}

2
src/ImageSharp/Formats/WebP/Lossy/Vp8EncProba.cs

@ -241,7 +241,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int pattern = WebpLookupTables.Vp8LevelCodes[level - 1][0];
int bits = WebpLookupTables.Vp8LevelCodes[level - 1][1];
int cost = 0;
for (int i = 2; pattern != 0; ++i)
for (int i = 2; pattern != 0; i++)
{
if ((pattern & 1) != 0)
{

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

@ -515,12 +515,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
Span<byte> top = this.Preds.AsSpan(); // original source top starts at: enc->preds_ - enc->preds_w_
Span<byte> left = this.Preds.AsSpan(this.PredsWidth - 1);
for (int i = 0; i < 4 * this.Mbw; ++i)
for (int i = 0; i < 4 * this.Mbw; i++)
{
top[i] = (int)IntraPredictionMode.DcPrediction;
}
for (int i = 0; i < 4 * this.Mbh; ++i)
for (int i = 0; i < 4 * this.Mbh; i++)
{
left[i * this.PredsWidth] = (int)IntraPredictionMode.DcPrediction;
}
@ -671,7 +671,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
Vp8SegmentInfo[] dqm = this.SegmentInfos;
double amp = WebpConstants.SnsToDq * this.spatialNoiseShaping / 100.0d / 128.0d;
double cBase = QualityToCompression(quality / 100.0d);
for (int i = 0; i < nb; ++i)
for (int i = 0; i < nb; i++)
{
// We modulate the base coefficient to accommodate for the quantization
// susceptibility and allow denser segments to be quantized more.
@ -717,7 +717,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// level0 is in [0..500]. Using '-f 50' as filter_strength is mid-filtering.
int level0 = 5 * this.filterStrength;
for (int i = 0; i < WebpConstants.NumMbSegments; ++i)
for (int i = 0; i < WebpConstants.NumMbSegments; i++)
{
Vp8SegmentInfo m = this.SegmentInfos[i];
@ -791,7 +791,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
private void SetupMatrices(Vp8SegmentInfo[] dqm)
{
int tlambdaScale = (this.method >= 4) ? this.spatialNoiseShaping : 0;
for (int i = 0; i < dqm.Length; ++i)
for (int i = 0; i < dqm.Length; i++)
{
Vp8SegmentInfo m = dqm[i];
int q = m.Quant;
@ -945,9 +945,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
}
// luma-AC
for (y = 0; y < 4; ++y)
for (y = 0; y < 4; y++)
{
for (x = 0; x < 4; ++x)
for (x = 0; x < 4; x++)
{
int ctx = it.TopNz[x] + it.LeftNz[y];
Span<short> coeffs = rd.YAcLevels.AsSpan(16 * (x + (y * 4)), 16);
@ -963,9 +963,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
residual.Init(0, 2, this.Proba);
for (ch = 0; ch <= 2; ch += 2)
{
for (y = 0; y < 2; ++y)
for (y = 0; y < 2; y++)
{
for (x = 0; x < 2; ++x)
for (x = 0; x < 2; x++)
{
int ctx = it.TopNz[4 + ch + x] + it.LeftNz[4 + ch + y];
residual.SetCoeffs(rd.UvLevels.AsSpan(16 * ((ch * 2) + x + (y * 2)), 16));
@ -1011,9 +1011,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
}
// luma-AC
for (y = 0; y < 4; ++y)
for (y = 0; y < 4; y++)
{
for (x = 0; x < 4; ++x)
for (x = 0; x < 4; x++)
{
int ctx = it.TopNz[x] + it.LeftNz[y];
Span<short> coeffs = rd.YAcLevels.AsSpan(16 * (x + (y * 4)), 16);
@ -1028,9 +1028,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
residual.Init(0, 2, this.Proba);
for (ch = 0; ch <= 2; ch += 2)
{
for (y = 0; y < 2; ++y)
for (y = 0; y < 2; y++)
{
for (x = 0; x < 2; ++x)
for (x = 0; x < 2; x++)
{
int ctx = it.TopNz[4 + ch + x] + it.LeftNz[4 + ch + y];
residual.SetCoeffs(rd.UvLevels.AsSpan(16 * ((ch * 2) + x + (y * 2)), 16));

38
src/ImageSharp/Formats/WebP/Lossy/Vp8Encoding.cs

@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
static Vp8Encoding()
{
for (int i = -255; i <= 255 + 255; ++i)
for (int i = -255; i <= 255 + 255; i++)
{
Clip1[255 + i] = Clip8b(i);
}
@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int[] C = new int[4 * 4];
#pragma warning restore SA1312 // Variable names should begin with lower-case letter
Span<int> tmp = C.AsSpan();
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
// vertical pass.
int a = input[0] + input[8];
@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
}
tmp = C.AsSpan();
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
// horizontal pass.
int dc = tmp[0] + 4;
@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int[] tmp = new int[16];
int srcIdx = 0;
int refIdx = 0;
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
int d0 = src[srcIdx] - reference[refIdx]; // 9bit dynamic range ([-255,255])
int d1 = src[srcIdx + 1] - reference[refIdx + 1];
@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
refIdx += WebpConstants.Bps;
}
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
int a0 = tmp[0 + i] + tmp[12 + i]; // 15b
int a1 = tmp[4 + i] + tmp[8 + i];
@ -165,7 +165,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int[] tmp = new int[16];
int i;
int inputIdx = 0;
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
int a0 = input[inputIdx + (0 * 16)] + input[inputIdx + (2 * 16)]; // 13b
int a1 = input[inputIdx + (1 * 16)] + input[inputIdx + (3 * 16)];
@ -179,7 +179,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
inputIdx += 64;
}
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
int a0 = tmp[0 + i] + tmp[8 + i]; // 15b
int a1 = tmp[4 + i] + tmp[12 + i];
@ -252,7 +252,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
if (top != null)
{
for (int j = 0; j < size; ++j)
for (int j = 0; j < size; j++)
{
top.Slice(0, size).CopyTo(dst.Slice(j * WebpConstants.Bps));
}
@ -268,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
if (left != null)
{
left = left.Slice(1); // in the reference implementation, left starts at - 1.
for (int j = 0; j < size; ++j)
for (int j = 0; j < size; j++)
{
dst.Slice(j * WebpConstants.Bps, size).Fill(left[j]);
}
@ -286,10 +286,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
if (top != null)
{
Span<byte> clip = Clip1.AsSpan(255 - left[0]); // left [0] instead of left[-1], original left starts at -1
for (int y = 0; y < size; ++y)
for (int y = 0; y < size; y++)
{
Span<byte> clipTable = clip.Slice(left[y + 1]); // left[y]
for (int x = 0; x < size; ++x)
for (int x = 0; x < size; x++)
{
dst[x] = clipTable[top[x]];
}
@ -325,7 +325,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int j;
if (top != null)
{
for (j = 0; j < size; ++j)
for (j = 0; j < size; j++)
{
dc += top[j];
}
@ -334,7 +334,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// top and left present.
left = left.Slice(1); // in the reference implementation, left starts at -1.
for (j = 0; j < size; ++j)
for (j = 0; j < size; j++)
{
dc += left[j];
}
@ -351,7 +351,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
// left but no top.
left = left.Slice(1); // in the reference implementation, left starts at -1.
for (j = 0; j < size; ++j)
for (j = 0; j < size; j++)
{
dc += left[j];
}
@ -372,7 +372,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
uint dc = 4;
int i;
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
dc += (uint)(top[topOffset + i] + top[topOffset - 5 + i]);
}
@ -383,10 +383,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
private static void Tm4(Span<byte> dst, Span<byte> top, int topOffset)
{
Span<byte> clip = Clip1.AsSpan(255 - top[topOffset - 1]);
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
Span<byte> clipTable = clip.Slice(top[topOffset - 2 - y]);
for (int x = 0; x < 4; ++x)
for (int x = 0; x < 4; x++)
{
dst[x] = clipTable[top[topOffset + x]];
}
@ -406,7 +406,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
LossyUtils.Avg3(top[topOffset + 2], top[topOffset + 3], top[topOffset + 4])
};
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 4; i++)
{
vals.AsSpan().CopyTo(dst.Slice(i * WebpConstants.Bps));
}
@ -637,7 +637,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
[MethodImpl(InliningOptions.ShortMethod)]
private static void Fill(Span<byte> dst, int value, int size)
{
for (int j = 0; j < size; ++j)
for (int j = 0; j < size; j++)
{
dst.Slice(j * WebpConstants.Bps, size).Fill((byte)value);
}

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

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int j;
int[] distribution = new int[MaxCoeffThresh + 1];
for (j = startBlock; j < endBlock; ++j)
for (j = startBlock; j < endBlock; j++)
{
short[] output = new short[16];
@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int i;
int[] tmp = new int[16];
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
int d0 = src[0] - reference[0]; // 9bit dynamic range ([-255,255])
int d1 = src[1] - reference[1];
@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
}
}
for (i = 0; i < 4; ++i)
for (i = 0; i < 4; i++)
{
int a0 = tmp[0 + i] + tmp[12 + i]; // 15b
int a1 = tmp[4 + i] + tmp[8 + i];

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

@ -67,7 +67,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{
int sum;
int i;
for (i = 0; i < 2; ++i)
for (i = 0; i < 2; i++)
{
int isAcCoeff = i > 0 ? 1 : 0;
int bias = BiasMatrices[type][isAcCoeff];
@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
this.ZThresh[i] = ((1 << WebpConstants.QFix) - 1 - this.Bias[i]) / this.IQ[i];
}
for (i = 2; i < 16; ++i)
for (i = 2; i < 16; i++)
{
this.Q[i] = this.Q[1];
this.IQ[i] = this.IQ[1];
@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
this.ZThresh[i] = this.ZThresh[1];
}
for (sum = 0, i = 0; i < 16; ++i)
for (sum = 0, i = 0; i < 16; i++)
{
if (type == 0)
{

2
src/ImageSharp/Formats/WebP/Lossy/Vp8Residual.cs

@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int bits = WebpLookupTables.Vp8LevelCodes[v - 1][1];
int pattern = WebpLookupTables.Vp8LevelCodes[v - 1][0];
int i;
for (i = 0; (pattern >>= 1) != 0; ++i)
for (i = 0; (pattern >>= 1) != 0; i++)
{
int mask = 2 << i;
if ((pattern & 1) != 0)

32
src/ImageSharp/Formats/WebP/Lossy/WebpLossyDecoder.cs

@ -216,10 +216,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
else
{
Span<byte> modes = block.Modes.AsSpan();
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
int yMode = left[y];
for (int x = 0; x < 4; ++x)
for (int x = 0; x < 4; x++)
{
byte[] prob = WebpLookupTables.ModesProba[top[x], yMode];
int i = WebpConstants.YModesIntra4[this.bitReader.GetBit(prob[0])];
@ -299,26 +299,26 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// We only need to do this init once at block (0,0).
// Afterward, it remains valid for the whole topmost row.
Span<byte> tmp = yuv.Slice(yOff - WebpConstants.Bps - 1, 16 + 4 + 1);
for (int i = 0; i < tmp.Length; ++i)
for (int i = 0; i < tmp.Length; i++)
{
tmp[i] = 127;
}
tmp = yuv.Slice(uOff - WebpConstants.Bps - 1, 8 + 1);
for (int i = 0; i < tmp.Length; ++i)
for (int i = 0; i < tmp.Length; i++)
{
tmp[i] = 127;
}
tmp = yuv.Slice(vOff - WebpConstants.Bps - 1, 8 + 1);
for (int i = 0; i < tmp.Length; ++i)
for (int i = 0; i < tmp.Length; i++)
{
tmp[i] = 127;
}
}
// Reconstruct one row.
for (int mbx = 0; mbx < dec.MbWidth; ++mbx)
for (int mbx = 0; mbx < dec.MbWidth; mbx++)
{
Vp8MacroBlockData block = dec.MacroBlockData[mbx];
@ -326,14 +326,14 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// pixels at a time for alignment reason, and because of in-loop filter.
if (mbx > 0)
{
for (int i = -1; i < 16; ++i)
for (int i = -1; i < 16; i++)
{
int srcIdx = (i * WebpConstants.Bps) + 12 + yOff;
int dstIdx = (i * WebpConstants.Bps) - 4 + yOff;
yuv.Slice(srcIdx, 4).CopyTo(yuv.Slice(dstIdx));
}
for (int i = -1; i < 8; ++i)
for (int i = -1; i < 8; i++)
{
int srcIdx = (i * WebpConstants.Bps) + 4 + uOff;
int dstIdx = (i * WebpConstants.Bps) - 4 + uOff;
@ -511,12 +511,12 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
Span<byte> yOut = dec.CacheY.Memory.Span.Slice(dec.CacheYOffset + (mbx * 16));
Span<byte> uOut = dec.CacheU.Memory.Span.Slice(dec.CacheUvOffset + (mbx * 8));
Span<byte> vOut = dec.CacheV.Memory.Span.Slice(dec.CacheUvOffset + (mbx * 8));
for (int j = 0; j < 16; ++j)
for (int j = 0; j < 16; j++)
{
yDst.Slice(j * WebpConstants.Bps, Math.Min(16, yOut.Length)).CopyTo(yOut.Slice(j * dec.CacheYStride));
}
for (int j = 0; j < 8; ++j)
for (int j = 0; j < 8; j++)
{
int jUvStride = j * dec.CacheUvStride;
uDst.Slice(j * WebpConstants.Bps, Math.Min(8, uOut.Length)).CopyTo(uOut.Slice(jUvStride));
@ -748,7 +748,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
LossyUtils.YuvToBgr(bottomY[0], (int)uv0 & 0xff, (int)(uv0 >> 16), bottomDst);
}
for (int x = 1; x <= lastPixelPair; ++x)
for (int x = 1; x <= lastPixelPair; x++)
{
uint tuv = LossyUtils.LoadUv(topU[x], topV[x]); // top sample
uint uv = LossyUtils.LoadUv(curU[x], curV[x]); // sample
@ -903,11 +903,11 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
byte tnz = (byte)(mb.NoneZeroAcDcCoeffs & 0x0f);
byte lnz = (byte)(leftMb.NoneZeroAcDcCoeffs & 0x0f);
for (int y = 0; y < 4; ++y)
for (int y = 0; y < 4; y++)
{
int l = lnz & 1;
uint nzCoeffs = 0;
for (int x = 0; x < 4; ++x)
for (int x = 0; x < 4; x++)
{
int ctx = l + (tnz & 1);
int nz = this.GetCoeffs(br, acProba, ctx, q.Y1Mat, first, dst.AsSpan(dstOffset));
@ -931,10 +931,10 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int chPlus4 = 4 + ch;
tnz = (byte)(mb.NoneZeroAcDcCoeffs >> chPlus4);
lnz = (byte)(leftMb.NoneZeroAcDcCoeffs >> chPlus4);
for (int y = 0; y < 2; ++y)
for (int y = 0; y < 2; y++)
{
int l = lnz & 1;
for (int x = 0; x < 2; ++x)
for (int x = 0; x < 2; x++)
{
int ctx = l + (tnz & 1);
int nz = this.GetCoeffs(br, bands[2], ctx, q.UvMat, 0, dst.AsSpan(dstOffset));
@ -1204,7 +1204,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
int dquvDc = hasValue ? this.bitReader.ReadSignedValue(4) : 0;
hasValue = this.bitReader.ReadBool();
int dquvAc = hasValue ? this.bitReader.ReadSignedValue(4) : 0;
for (int i = 0; i < WebpConstants.NumMbSegments; ++i)
for (int i = 0; i < WebpConstants.NumMbSegments; i++)
{
int q;
if (vp8SegmentHeader.UseSegment)

8
src/ImageSharp/Formats/WebP/WebpLookupTables.cs

@ -1234,25 +1234,25 @@ namespace SixLabors.ImageSharp.Formats.Webp
}
Abs0 = new Dictionary<int, byte>();
for (int i = -255; i <= 255; ++i)
for (int i = -255; i <= 255; i++)
{
Abs0[i] = (byte)((i < 0) ? -i : i);
}
Clip1 = new Dictionary<int, byte>();
for (int i = -255; i <= 255 + 255; ++i)
for (int i = -255; i <= 255 + 255; i++)
{
Clip1[i] = (byte)(i < 0 ? 0 : i > 255 ? 255 : i);
}
Sclip1 = new Dictionary<int, sbyte>();
for (int i = -1020; i <= 1020; ++i)
for (int i = -1020; i <= 1020; i++)
{
Sclip1[i] = (sbyte)(i < -128 ? -128 : i > 127 ? 127 : i);
}
Sclip2 = new Dictionary<int, sbyte>();
for (int i = -112; i <= 112; ++i)
for (int i = -112; i <= 112; i++)
{
Sclip2[i] = (sbyte)(i < -16 ? -16 : i > 15 ? 15 : i);
}

Loading…
Cancel
Save