Skip to content

Commit 3949db0

Browse files
Merge branch 'main' into js/format-conversion
2 parents d83f763 + 10e9c49 commit 3949db0

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

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

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

699+
histogramImageSize = maxIndex;
700+
699701
this.bitWriter.PutBits((uint)(this.HistoBits - 2), 3);
700702
this.EncodeImageNoHuffman(
701703
histogramBgra,
@@ -711,7 +713,7 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
711713
// Store Huffman codes.
712714
// Find maximum number of symbols for the huffman tree-set.
713715
int maxTokens = 0;
714-
for (int i = 0; i < 5 * histogramImage.Count; i++)
716+
for (int i = 0; i < 5 * histogramImageSize; i++)
715717
{
716718
HuffmanTreeCode codes = huffmanCodes[i];
717719
if (maxTokens < codes.NumSymbols)
@@ -726,7 +728,7 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
726728
tokens[i] = new HuffmanTreeToken();
727729
}
728730

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

tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,23 @@ public void Encode_Lossy_WorksWithTestPattern<TPixel>(TestImageProvider<TPixel>
499499
image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f));
500500
}
501501

502+
// https://github.com/SixLabors/ImageSharp/issues/2763
503+
[Theory]
504+
[WithFile(Lossy.Issue2763, PixelTypes.Rgba32)]
505+
public void WebpDecoder_CanDecode_Issue2763<TPixel>(TestImageProvider<TPixel> provider)
506+
where TPixel : unmanaged, IPixel<TPixel>
507+
{
508+
WebpEncoder encoder = new()
509+
{
510+
Quality = 84,
511+
FileFormat = WebpFileFormatType.Lossless
512+
};
513+
514+
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance);
515+
image.DebugSave(provider);
516+
image.VerifyEncoder(provider, "webp", string.Empty, encoder);
517+
}
518+
502519
public static void RunEncodeLossy_WithPeakImage()
503520
{
504521
TestImageProvider<Rgba32> provider = TestImageProvider<Rgba32>.File(TestImageLossyFullPath);

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ public static class Lossy
823823
public const string Issue2243 = "Webp/issues/Issue2243.webp";
824824
public const string Issue2257 = "Webp/issues/Issue2257.webp";
825825
public const string Issue2670 = "Webp/issues/Issue2670.webp";
826+
public const string Issue2763 = "Webp/issues/Issue2763.png";
826827
}
827828
}
828829

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)