Skip to content

Commit c8fe7f2

Browse files
Merge branch 'main' into js/gif-fixes
2 parents 14f9127 + 6a7e5ff commit c8fe7f2

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ private void Write1BitPixelData<TPixel>(Configuration configuration, Stream stre
669669

670670
if (quantizedPixelRow.Length % 8 != 0)
671671
{
672-
int startIdx = quantizedPixelRow.Length - 7;
672+
int startIdx = quantizedPixelRow.Length - (quantizedPixelRow.Length % 8);
673673
endIdx = quantizedPixelRow.Length;
674674
Write1BitPalette(stream, startIdx, endIdx, quantizedPixelRow);
675675
}

tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,30 @@ public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixe
373373
TestBmpEncoderCore(provider, bitsPerPixel);
374374
}
375375

376+
[Theory]
377+
[WithFile(BlackWhitePalletDataMatrix, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel1)]
378+
public void Encode_Issue2467<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
379+
where TPixel : unmanaged, IPixel<TPixel>
380+
{
381+
using Image<TPixel> image = provider.GetImage();
382+
383+
using var reencodedStream = new MemoryStream();
384+
var encoder = new BmpEncoder
385+
{
386+
BitsPerPixel = bitsPerPixel,
387+
SupportTransparency = false,
388+
Quantizer = KnownQuantizers.Octree
389+
};
390+
image.SaveAsBmp(reencodedStream, encoder);
391+
reencodedStream.Seek(0, SeekOrigin.Begin);
392+
393+
using Image<TPixel> reencodedImage = Image.Load<TPixel>(reencodedStream);
394+
395+
reencodedImage.DebugSave(provider);
396+
397+
reencodedImage.CompareToOriginal(provider);
398+
}
399+
376400
private static void TestBmpEncoderCore<TPixel>(
377401
TestImageProvider<TPixel> provider,
378402
BmpBitsPerPixel bitsPerPixel,

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ public static class Bmp
407407
public const string Rgba321010102 = "Bmp/rgba32-1010102.bmp";
408408
public const string RgbaAlphaBitfields = "Bmp/rgba32abf.bmp";
409409

410+
public const string BlackWhitePalletDataMatrix = "Bmp/bit1datamatrix.bmp";
411+
410412
public static readonly string[] BitFields =
411413
{
412414
Rgb32bfdef,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3b2288e2a059b15c7855eb141c05e3ce69431e7c3ddef851033f7fd9ca39a2d4
3+
size 102

0 commit comments

Comments
 (0)