From 10af2ed98c206271457a40d0999c3a6a51c30655 Mon Sep 17 00:00:00 2001 From: popow Date: Sun, 16 Dec 2018 19:06:08 +0100 Subject: [PATCH 1/5] fix for Windows 2.0 or OS/2 1.x bitmaps only use 3 bytes per color palette entry --- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 29 ++++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index ef3ca24ee8..b11f7934d2 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -108,7 +108,7 @@ public Image Decode(Stream stream) { try { - this.ReadImageHeaders(stream, out bool inverted, out byte[] palette); + int bytesPerColorMapEntry = this.ReadImageHeaders(stream, out bool inverted, out byte[] palette); var image = new Image(this.configuration, this.infoHeader.Width, this.infoHeader.Height, this.metaData); @@ -137,6 +137,7 @@ public Image Decode(Stream stream) this.infoHeader.Width, this.infoHeader.Height, this.infoHeader.BitsPerPixel, + bytesPerColorMapEntry, inverted); } @@ -329,18 +330,20 @@ private void UncompressRle8(int w, Span buffer) /// The containing the colors. /// The width of the bitmap. /// The height of the bitmap. - /// The number of bits per pixel. + /// The number of bits per pixel. + /// Usually 4 bytes, but in case of Windows 2.x bitmaps or OS/2 1.x bitmaps + /// the bytes per color palette entry's can be 3 bytes instead of 4. /// Whether the bitmap is inverted. - private void ReadRgbPalette(Buffer2D pixels, byte[] colors, int width, int height, int bits, bool inverted) + private void ReadRgbPalette(Buffer2D pixels, byte[] colors, int width, int height, int bitsPerPixel, int bytesPerColorMapEntry, bool inverted) where TPixel : struct, IPixel { // Pixels per byte (bits per pixel) - int ppb = 8 / bits; + int ppb = 8 / bitsPerPixel; int arrayWidth = (width + ppb - 1) / ppb; // Bit mask - int mask = 0xFF >> (8 - bits); + int mask = 0xFF >> (8 - bitsPerPixel); // Rows are aligned on 4 byte boundaries int padding = arrayWidth % 4; @@ -366,7 +369,7 @@ private void ReadRgbPalette(Buffer2D pixels, byte[] colors, int int colOffset = x * ppb; for (int shift = 0, newX = colOffset; shift < ppb && newX < width; shift++, newX++) { - int colorIndex = ((rowSpan[offset] >> (8 - bits - (shift * bits))) & mask) * 4; + int colorIndex = ((rowSpan[offset] >> (8 - bitsPerPixel - (shift * bitsPerPixel))) & mask) * bytesPerColorMapEntry; color.FromBgr24(Unsafe.As(ref colors[colorIndex])); pixelRow[newX] = color; @@ -571,7 +574,9 @@ private void ReadFileHeader() /// /// Reads the and from the stream and sets the corresponding fields. /// - private void ReadImageHeaders(Stream stream, out bool inverted, out byte[] palette) + /// Bytes per color palette entry. Usually 4 bytes, but in case of Windows 2.x bitmaps or OS/2 1.x bitmaps + /// the bytes per color palette entry's can be 3 bytes instead of 4. + private int ReadImageHeaders(Stream stream, out bool inverted, out byte[] palette) { this.stream = stream; @@ -591,6 +596,7 @@ private void ReadImageHeaders(Stream stream, out bool inverted, out byte[] palet } int colorMapSize = -1; + int bytesPerColorMapEntry = 4; if (this.infoHeader.ClrUsed == 0) { @@ -598,12 +604,15 @@ private void ReadImageHeaders(Stream stream, out bool inverted, out byte[] palet || this.infoHeader.BitsPerPixel == 4 || this.infoHeader.BitsPerPixel == 8) { - colorMapSize = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel) * 4; + int colorMapSizeBytes = this.fileHeader.Offset - BmpFileHeader.Size - this.infoHeader.HeaderSize; + int colorCountForBitDepth = ImageMaths.GetColorCountForBitDepth(this.infoHeader.BitsPerPixel); + bytesPerColorMapEntry = colorMapSizeBytes / colorCountForBitDepth; + colorMapSize = colorMapSizeBytes; } } else { - colorMapSize = this.infoHeader.ClrUsed * 4; + colorMapSize = this.infoHeader.ClrUsed * bytesPerColorMapEntry; } palette = null; @@ -622,6 +631,8 @@ private void ReadImageHeaders(Stream stream, out bool inverted, out byte[] palet } this.infoHeader.VerifyDimensions(); + + return bytesPerColorMapEntry; } } } \ No newline at end of file From 0e41c13d3ccef2792db6fad809375f0a2d845f20 Mon Sep 17 00:00:00 2001 From: popow Date: Tue, 18 Dec 2018 19:34:28 +0100 Subject: [PATCH 2/5] added Test for decoding windows BMPv2 and one for a bitmap which has 4 bytes per color palette --- .../Formats/Bmp/BmpDecoderTests.cs | 24 ++++++++++++++++++ tests/ImageSharp.Tests/TestImages.cs | 3 +++ tests/Images/Input/Bmp/pal8-0.bmp | Bin 0 -> 9270 bytes tests/Images/Input/Bmp/pal8os2v1_winv2.bmp | Bin 0 -> 8986 bytes 4 files changed, 27 insertions(+) create mode 100644 tests/Images/Input/Bmp/pal8-0.bmp create mode 100644 tests/Images/Input/Bmp/pal8os2v1_winv2.bmp diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index 5f2de9f51e..d60d9d918a 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -55,6 +55,30 @@ public void BmpDecoder_IsNotBoundToSinglePixelType(TestImageProvider(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage(new BmpDecoder())) + { + image.DebugSave(provider, "png"); + image.CompareToOriginal(provider); + } + } + + [Theory] + [WithFile(Bit8Palette4, PixelTypes.Rgba32)] + public void BmpDecoder_CanDecode4BytePerEntryPalette(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage(new BmpDecoder())) + { + image.DebugSave(provider, "png"); + image.CompareToOriginal(provider); + } + } + [Theory] [InlineData(Car, 24)] [InlineData(F, 24)] diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 1144a3f7c0..9c747dcb8a 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -201,6 +201,9 @@ public static class Bmp public const string Bit16 = "Bmp/test16.bmp"; public const string Bit16Inverted = "Bmp/test16-inverted.bmp"; public const string Bit32Rgb = "Bmp/rgb32.bmp"; + // Note: This format can be called OS/2 BMPv1, or Windows BMPv2 + public const string WinBmpv2 = "Bmp/pal8os2v1_winv2.bmp"; + public const string Bit8Palette4 = "Bmp/pal8-0.bmp"; public static readonly string[] All = { diff --git a/tests/Images/Input/Bmp/pal8-0.bmp b/tests/Images/Input/Bmp/pal8-0.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ab8815a360d315ed119604c5a60feb81bfa65625 GIT binary patch literal 9270 zcmbuDPfS$T9>*_#1ly_$qX~(P3ttyc*f3mlMjPSf8Jd{TbRoK^ESv!@118c1p^1q+ zOlnwkOk@Uy3k!J*12Lu~CK?uCT8Ae(+=Y;s)`cmFiN*!x^#%OL;=a%CoHH;p474xr zoE~O4!=2yf^ZTAVPWtyR4}WHrm|u>Qs>u(tDat6}q^!*W?3%eSlw9xB+c zV84R>3id15KgIqj_D`{Yiv3gUpJKm<{T}vv*zaM#hy5P*Z?S)i{aftcV*eKVx7dHm z{!{j!vj3F*r|dsvpZ_eMeV=`weV={bx7cCHbXYFSW3dmX4W|vK4W|vK4W|vK4W|vK z4W|vK4X541eh>R_+Hl%%+Hl%%+Hl%%+Hl%%+Hl%%+Hl%%+Hl%%+Hl%%+Hl%%+Hl%% z+HgXx2pxVpa5`{0a5`{0a5`{0a5`{0a5`{0a5`{0a5`{0a5`{0a5_Eg!|A~3!0Ev0 z!0Ev0!0Ev0!0Ev0!0Ev0!0Ev0!0Ev0!0Ev0!0Ev0z)5FW(n+C|>9N>{(}mN8(}mN8 z(}mN8(}mN8(}mN8(}mN8(}mN8)9qm&P8UuWP8UuWP8UuWP8UuWP8UuWP8UuWP8UuW zP8UuWP8UuWP8UwnXGz-9NuiX}<3q-qH*eIRSEzBCaq09W zHEyf%^Upu?dWlua*tv7pu04D9?%BI{ALGEM2N(wr9*k@~xV+M;EIC|xw({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F^lH#Ij{Ey<_jDLSyf7=lLDea&0`6G^2 zRMnU4r|i10B!yF6F|Pt zUnzfH`IEg2@gJiBql%9)EbhzwCs}n)ZkLJfA|ymk8%HxlmA`vpCtb&u1}_hW>e%p zw?+0Qe;OeE&EhW|z<+v3>5Kn<87CN>Cpy)*!ARYZ?xa#HE8?ae}Hrjs(fEEDG0WjP?)c>y`p--h&0ib%>iTyPH1n0k#06J;@4bFdx_NP{s z=4t;k02Tmv3BclHa_YCFbWg6wU-FmiCHJ)@r$j9)Cx7j)^Cy4|e>$+{PX`#3SN@s# zYk!?T0Vsb;=bhk){~`Pj;opM)wf1Z6!}!k*&0@EjTE!oG0>B>t>^oKa0iZkp^JCBO ze}?}8{;wuqO)lcUoLtt|i@&y~+0p?u*B`|{EC2pK$Y0{$D*vgC`3r)af%Qk7JzsRh z|C0>=bL21nbRadW{6E|O+5WHazaWzUZg$?h@dSV;sVBTH{=a1Sza)S0rvs^FxnBG0 z-1Bun`~j#w#QopWe2(___YV&Z)BcnId{|vO|2ltZzv_S-0FyreHq9yzLYG z549X^X*t(??%cKh;b8)pC4gD+R{@+*0G$_@H*ZJ)(tZ$DR_Eu(=6}Ke*}~n0g_rkU zzI-*cxJUrY1h9<1i*wcj#np>%nVaR$`OnHf?N9kNf7O9a^5^_#zsc}J#n`%5^tUlrO`T6-@=ASWs{S|-4t5=JR zWg4)u%vtT z$)C|8{w?U^|F2>68JYeUzFOCRa#Q^2fbu7Q#)9}SppXA=i|8|WeY5P76lYPN_5;uY z0OebT&kbLr{IDtyfNDPhP+kGtym0d-0sxd>SbVwoit>x9JOGltUVJaW IIA>Y^1(tjtKmY&$ literal 0 HcmV?d00001 diff --git a/tests/Images/Input/Bmp/pal8os2v1_winv2.bmp b/tests/Images/Input/Bmp/pal8os2v1_winv2.bmp new file mode 100644 index 0000000000000000000000000000000000000000..14901b3882cea0679832e4f45a49f6b10034d3ce GIT binary patch literal 8986 zcmbuDPiU0a-p5Z&O!`M%h=N>;i{5UU**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Qw`d{xg9_j!9 literal 0 HcmV?d00001 From 5ef46927fcdb71f16db8a526349c7146f6d8f43c Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 20 Dec 2018 20:59:38 +1100 Subject: [PATCH 3/5] Use MagickReferenceDecoder for bmp. --- .../TestUtilities/TestEnvironment.Formats.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs index 334b6552ac..34a075ac7f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs @@ -34,8 +34,7 @@ internal static IImageFormat GetImageFormat(string filePath) { string extension = Path.GetExtension(filePath); - IImageFormat format = Configuration.ImageFormatsManager.FindFormatByFileExtension(extension); - return format; + return Configuration.ImageFormatsManager.FindFormatByFileExtension(extension); } private static void ConfigureCodecs( @@ -69,7 +68,7 @@ private static Configuration CreateDefaultConfiguration() cfg.ConfigureCodecs( BmpFormat.Instance, - SystemDrawingReferenceDecoder.Instance, + MagickReferenceDecoder.Instance, bmpEncoder, new BmpImageFormatDetector()); From 890134cec61a6c65a11562046635a248fd4d4158 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 20 Dec 2018 21:54:59 +1100 Subject: [PATCH 4/5] Fix reference tests --- .../TestUtilities/Tests/TestEnvironmentTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index 30bb16c2a0..8abbd94bda 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -101,7 +101,7 @@ public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(string fileName, [Theory] [InlineData("lol/foo.png", typeof(MagickReferenceDecoder))] - [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] + [InlineData("lol/Rofl.bmp", typeof(MagickReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] public void GetReferenceDecoder_ReturnsCorrectDecoders_Windows(string fileName, Type expectedDecoderType) @@ -127,7 +127,7 @@ public void GetReferenceEncoder_ReturnsCorrectEncoders_Linux(string fileName, Ty [Theory] [InlineData("lol/foo.png", typeof(MagickReferenceDecoder))] - [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] + [InlineData("lol/Rofl.bmp", typeof(MagickReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] public void GetReferenceDecoder_ReturnsCorrectDecoders_Linux(string fileName, Type expectedDecoderType) From 2f3c0fce47c8636c7f2102b0b89705eaa778f217 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 20 Dec 2018 23:25:23 +1100 Subject: [PATCH 5/5] Use S.D in Windows. --- tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs | 2 +- .../TestUtilities/Tests/TestEnvironmentTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs index 34a075ac7f..7d06847223 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestEnvironment.Formats.cs @@ -68,7 +68,7 @@ private static Configuration CreateDefaultConfiguration() cfg.ConfigureCodecs( BmpFormat.Instance, - MagickReferenceDecoder.Instance, + IsWindows ? (IImageDecoder)SystemDrawingReferenceDecoder.Instance : MagickReferenceDecoder.Instance, bmpEncoder, new BmpImageFormatDetector()); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs index 8abbd94bda..122234ae89 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestEnvironmentTests.cs @@ -101,7 +101,7 @@ public void GetReferenceEncoder_ReturnsCorrectEncoders_Windows(string fileName, [Theory] [InlineData("lol/foo.png", typeof(MagickReferenceDecoder))] - [InlineData("lol/Rofl.bmp", typeof(MagickReferenceDecoder))] + [InlineData("lol/Rofl.bmp", typeof(SystemDrawingReferenceDecoder))] [InlineData("lol/Baz.JPG", typeof(JpegDecoder))] [InlineData("lol/Baz.gif", typeof(GifDecoder))] public void GetReferenceDecoder_ReturnsCorrectDecoders_Windows(string fileName, Type expectedDecoderType)