Skip to content

Commit 00b253d

Browse files
committed
Fix issue in EncodeImage() not using correct histogram image size, fixes #2763
1 parent c9a29f0 commit 00b253d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
698698
}
699699
}
700700

701+
histogramImageSize = maxIndex;
702+
701703
this.bitWriter.PutBits((uint)(this.HistoBits - 2), 3);
702704
this.EncodeImageNoHuffman(
703705
histogramBgra,
@@ -713,7 +715,7 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
713715
// Store Huffman codes.
714716
// Find maximum number of symbols for the huffman tree-set.
715717
int maxTokens = 0;
716-
for (int i = 0; i < 5 * histogramImage.Count; i++)
718+
for (int i = 0; i < 5 * histogramImageSize; i++)
717719
{
718720
HuffmanTreeCode codes = huffmanCodes[i];
719721
if (maxTokens < codes.NumSymbols)
@@ -728,7 +730,7 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
728730
tokens[i] = new HuffmanTreeToken();
729731
}
730732

731-
for (int i = 0; i < 5 * histogramImage.Count; i++)
733+
for (int i = 0; i < 5 * histogramImageSize; i++)
732734
{
733735
HuffmanTreeCode codes = huffmanCodes[i];
734736
this.StoreHuffmanCode(huffTree, tokens, codes);

0 commit comments

Comments
 (0)