Skip to content

Commit 2f3d24d

Browse files
committedJul 10, 2024·
Merge branch 'release/3.1.x' into js/fix-2752
2 parents d7f7d5a + 1d4a287 commit 2f3d24d

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed
 

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
699699
}
700700
}
701701

702+
histogramImageSize = maxIndex;
703+
702704
this.bitWriter.PutBits((uint)(this.HistoBits - 2), 3);
703705
this.EncodeImageNoHuffman(
704706
histogramBgra,
@@ -714,7 +716,7 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
714716
// Store Huffman codes.
715717
// Find maximum number of symbols for the huffman tree-set.
716718
int maxTokens = 0;
717-
for (int i = 0; i < 5 * histogramImage.Count; i++)
719+
for (int i = 0; i < 5 * histogramImageSize; i++)
718720
{
719721
HuffmanTreeCode codes = huffmanCodes[i];
720722
if (maxTokens < codes.NumSymbols)
@@ -729,7 +731,7 @@ private void EncodeImage(int width, int height, bool useCache, CrunchConfig conf
729731
tokens[i] = new HuffmanTreeToken();
730732
}
731733

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

‎src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs

-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ public static WebpImageInfo ReadVp8XHeader(BufferedReadStream stream, Span<byte>
218218

219219
// 3 reserved bytes should follow which are supposed to be zero.
220220
stream.Read(buffer, 0, 3);
221-
if (buffer[0] != 0 || buffer[1] != 0 || buffer[2] != 0)
222-
{
223-
WebpThrowHelper.ThrowImageFormatException("reserved bytes should be zero");
224-
}
225221

226222
// 3 bytes for the width.
227223
uint width = ReadUInt24LittleEndian(stream, buffer) + 1;

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

+17
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,23 @@ public void Encode_Lossy_WorksWithTestPattern<TPixel>(TestImageProvider<TPixel>
497497
image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f));
498498
}
499499

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

‎tests/ImageSharp.Tests/TestImages.cs

+1
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

Loading

0 commit comments

Comments
 (0)
Please sign in to comment.