Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ private void WriteJfifApplicationHeader(ImageMetadata meta)
/// <param name="componentCount">The number of components to write.</param>
private void WriteDefineHuffmanTables(int componentCount)
{
// This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
// and doesn't incur any allocation at all.
// Table identifiers.
ReadOnlySpan<byte> headers = stackalloc byte[]
ReadOnlySpan<byte> headers = new byte[]
{
0x00,
0x10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ private void WriteCode(Stream stream, int code)

private void ResetTables()
{
this.children.GetSpan().Fill(0);
this.siblings.GetSpan().Fill(0);
this.children.GetSpan().Clear();
this.siblings.GetSpan().Clear();
this.bitsPerCode = MinBits;
this.maxCode = MaxValue(this.bitsPerCode);
this.nextValidCode = EoiCode + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void Decompress(BufferedReadStream stream, int byteCount, int
uint bitsWritten = 0;
for (int y = 0; y < height; y++)
{
scanLine.Fill(0);
scanLine.Clear();
Decode2DScanline(bitReader, this.isWhiteZero, referenceScanLine, scanLine);

bitsWritten = this.WriteScanLine(buffer, scanLine, bitsWritten);
Expand Down Expand Up @@ -116,7 +116,15 @@ private static void Decode2DScanline(T6BitReader bitReader, bool whiteIsZero, Cc
{
// If a TIFF reader encounters EOFB before the expected number of lines has been extracted,
// it is appropriate to assume that the missing rows consist entirely of white pixels.
scanline.Fill(whiteIsZero ? (byte)0 : (byte)255);
if (whiteIsZero)
{
scanline.Clear();
}
else
{
scanline.Fill((byte)255);
}

break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossless/CostModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static void ConvertPopulationCountTableToBitEstimates(int numSymbols, ui

if (nonzeros <= 1)
{
output.AsSpan(0, numSymbols).Fill(0);
output.AsSpan(0, numSymbols).Clear();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossless/HistogramEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static void OptimizeHistogramSymbols(ushort[] clusterMappings, int numCl

// Create a mapping from a cluster id to its minimal version.
int clusterMax = 0;
clusterMappingsTmp.AsSpan().Fill(0);
clusterMappingsTmp.AsSpan().Clear();

// Re-map the ids.
for (int i = 0; i < symbols.Length; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static class HuffmanUtils
public static void CreateHuffmanTree(uint[] histogram, int treeDepthLimit, bool[] bufRle, HuffmanTree[] huffTree, HuffmanTreeCode huffCode)
{
int numSymbols = huffCode.NumSymbols;
bufRle.AsSpan().Fill(false);
bufRle.AsSpan().Clear();
OptimizeHuffmanForRle(numSymbols, bufRle, histogram);
GenerateOptimalTree(huffTree, histogram, numSymbols, treeDepthLimit, huffCode.CodeLengths);

Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/Formats/Webp/Lossless/Vp8LHistogram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private void AddLiteral(Vp8LHistogram b, Vp8LHistogram output, int literalSize)
}
else
{
output.Literal.AsSpan(0, literalSize).Fill(0);
output.Literal.AsSpan(0, literalSize).Clear();
}
}

Expand All @@ -343,7 +343,7 @@ private void AddRed(Vp8LHistogram b, Vp8LHistogram output, int size)
}
else
{
output.Red.AsSpan(0, size).Fill(0);
output.Red.AsSpan(0, size).Clear();
}
}

Expand All @@ -366,7 +366,7 @@ private void AddBlue(Vp8LHistogram b, Vp8LHistogram output, int size)
}
else
{
output.Blue.AsSpan(0, size).Fill(0);
output.Blue.AsSpan(0, size).Clear();
}
}

Expand All @@ -389,7 +389,7 @@ private void AddAlpha(Vp8LHistogram b, Vp8LHistogram output, int size)
}
else
{
output.Alpha.AsSpan(0, size).Fill(0);
output.Alpha.AsSpan(0, size).Clear();
}
}

Expand All @@ -412,7 +412,7 @@ private void AddDistance(Vp8LHistogram b, Vp8LHistogram output, int size)
}
else
{
output.Distance.AsSpan(0, size).Fill(0);
output.Distance.AsSpan(0, size).Clear();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/Formats/Webp/Lossy/Vp8EncIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -911,22 +911,22 @@ private void InitLeft()

this.LeftNz[8] = 0;

this.LeftDerr.AsSpan().Fill(0);
this.LeftDerr.AsSpan().Clear();
}

private void InitTop()
{
int topSize = this.mbw * 16;
this.YTop.AsSpan(0, topSize).Fill(127);
this.UvTop.AsSpan().Fill(127);
this.Nz.AsSpan().Fill(0);
this.Nz.AsSpan().Clear();

int predsW = (4 * this.mbw) + 1;
int predsH = (4 * this.mbh) + 1;
int predsSize = predsW * predsH;
this.Preds.AsSpan(predsSize + this.predsWidth, this.mbw).Fill(0);
this.Preds.AsSpan(predsSize + this.predsWidth, this.mbw).Clear();

this.TopDerr.AsSpan().Fill(0);
this.TopDerr.AsSpan().Clear();
}

private int Bit(uint nz, int n) => (nz & (1 << n)) != 0 ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossy/Vp8Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ private void ResetBoundaryPredictions()
int predsW = (4 * this.Mbw) + 1;
int predsH = (4 * this.Mbh) + 1;
int predsSize = predsW * predsH;
this.Preds.AsSpan(predsSize + this.PredsWidth - 4, 4).Fill(0);
this.Preds.AsSpan(predsSize + this.PredsWidth - 4, 4).Clear();

this.Nz[0] = 0; // constant
}
Expand Down