diff --git a/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs b/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs index 5d91140010..10ec6201dd 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/BitWriterBase.cs @@ -61,13 +61,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter /// The height of the image. public abstract void WriteEncodedImageToStream(Stream stream, ExifProfile exifProfile, uint width, uint height); - protected bool ResizeBuffer(int maxBytes, int sizeRequired) + protected void ResizeBuffer(int maxBytes, int sizeRequired) { - if (maxBytes > 0 && sizeRequired < maxBytes) - { - return true; - } - int newSize = (3 * maxBytes) >> 1; if (newSize < sizeRequired) { @@ -77,8 +72,6 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter // Make new size multiple of 1k. newSize = ((newSize >> 10) + 1) << 10; Array.Resize(ref this.buffer, newSize); - - return false; } /// diff --git a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs index e3e1a9ddc9..2f942231fb 100644 --- a/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs +++ b/src/ImageSharp/Formats/WebP/BitWriter/Vp8LBitWriter.cs @@ -43,14 +43,14 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter /// private int cur; - private int end; - /// /// Initializes a new instance of the class. /// /// The expected size in bytes. public Vp8LBitWriter(int expectedSize) - : base(expectedSize) => this.end = this.Buffer.Length; + : base(expectedSize) + { + } /// /// Initializes a new instance of the class. @@ -184,9 +184,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter private void PutBitsFlushBits() { // If needed, make some room by flushing some bits out. - if (this.cur + WriterBytes > this.end) + if (this.cur + WriterBytes > this.Buffer.Length) { - int extraSize = this.end - this.cur + MinExtraSize; + int extraSize = this.Buffer.Length - this.cur + MinExtraSize; this.BitWriterResize(extraSize); } @@ -204,15 +204,9 @@ namespace SixLabors.ImageSharp.Formats.Webp.BitWriter /// The extra size in bytes needed. public override void BitWriterResize(int extraSize) { - int maxBytes = this.end + this.Buffer.Length; + int maxBytes = this.Buffer.Length + this.Buffer.Length; int sizeRequired = this.cur + extraSize; - - if (this.ResizeBuffer(maxBytes, sizeRequired)) - { - return; - } - - this.end = this.Buffer.Length; + this.ResizeBuffer(maxBytes, sizeRequired); } } } diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index d0b2c73a19..95ea65d2b0 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs @@ -64,6 +64,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 4, 100)] [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 5, 100)] [WithFile(Lossy.NoFilter06, PixelTypes.Rgba32, 6, 100)] + [WithFile(TestImages.Png.BikeSmall, PixelTypes.Rgba32, 6, 100)] public void Encode_Lossless_WithDifferentMethodAndQuality_Works(TestImageProvider provider, int method, int quality) where TPixel : unmanaged, IPixel { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index a223ce0fe7..2925457475 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -44,6 +44,7 @@ namespace SixLabors.ImageSharp.Tests public const string CalliphoraPartial = "Png/CalliphoraPartial.png"; public const string CalliphoraPartialGrayscale = "Png/CalliphoraPartialGrayscale.png"; public const string Bike = "Png/Bike.png"; + public const string BikeSmall = "Png/bike-small.png"; public const string BikeGrayscale = "Png/BikeGrayscale.png"; public const string SnakeGame = "Png/SnakeGame.png"; public const string Icon = "Png/icon.png";