From 26b3e664db2eb20d5ddb848dd0c01ea1b31c1c37 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Fri, 3 Dec 2021 11:34:45 +0100 Subject: [PATCH] Fix bug in black and white plain decoding --- src/ImageSharp/Formats/Pbm/PlainDecoder.cs | 4 ++-- src/ImageSharp/Formats/Pbm/PlainEncoder.cs | 2 +- tests/ImageSharp.Tests/Formats/Pbm/PbmRoundTripTests.cs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs index bf2b10e1d7..9fa8e513e0 100644 --- a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs +++ b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs @@ -174,8 +174,8 @@ namespace SixLabors.ImageSharp.Formats.Pbm MemoryAllocator allocator = configuration.MemoryAllocator; using IMemoryOwner row = allocator.Allocate(width); Span rowSpan = row.GetSpan(); - var white = new L8(0); - var black = new L8(255); + var white = new L8(255); + var black = new L8(0); for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Formats/Pbm/PlainEncoder.cs b/src/ImageSharp/Formats/Pbm/PlainEncoder.cs index 2e7c60e5ee..8d534b7a9a 100644 --- a/src/ImageSharp/Formats/Pbm/PlainEncoder.cs +++ b/src/ImageSharp/Formats/Pbm/PlainEncoder.cs @@ -230,7 +230,7 @@ namespace SixLabors.ImageSharp.Formats.Pbm int written = 0; for (int x = 0; x < width; x++) { - byte value = (rowSpan[x].PackedValue > 127) ? Zero : One; + byte value = (rowSpan[x].PackedValue < 128) ? One : Zero; plainSpan[written++] = value; plainSpan[written++] = Space; } diff --git a/tests/ImageSharp.Tests/Formats/Pbm/PbmRoundTripTests.cs b/tests/ImageSharp.Tests/Formats/Pbm/PbmRoundTripTests.cs index 1735efdce8..cba75b2a01 100644 --- a/tests/ImageSharp.Tests/Formats/Pbm/PbmRoundTripTests.cs +++ b/tests/ImageSharp.Tests/Formats/Pbm/PbmRoundTripTests.cs @@ -14,6 +14,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Pbm public class PbmRoundTripTests { [Theory] + [InlineData(BlackAndWhitePlain)] [InlineData(BlackAndWhiteBinary)] [InlineData(GrayscalePlain)] [InlineData(GrayscaleBinary)]