From 4d5beeec14deba995f7855ae97ae030576ed27bd Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Thu, 31 Aug 2017 10:46:25 +0100 Subject: [PATCH 1/4] enable reading bmp with larger headers --- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 24 +++++++++++++++---- tests/ImageSharp.Tests/TestImages.cs | 4 +++- .../TestImages/Formats/Bmp/BITMAPV5HEADER.bmp | 3 +++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 tests/ImageSharp.Tests/TestImages/Formats/Bmp/BITMAPV5HEADER.bmp diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 108006adea..3dcbf40756 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -375,11 +375,18 @@ namespace ImageSharp.Formats // read header size this.currentStream.Read(data, 0, BmpInfoHeader.HeaderSizeSize); int headerSize = BitConverter.ToInt32(data, 0); - if (headerSize < BmpInfoHeader.HeaderSizeSize || headerSize > BmpInfoHeader.MaxHeaderSize) + if (headerSize < BmpInfoHeader.BitmapCoreHeaderSize) { throw new NotSupportedException($"This kind of bitmap files (header size $headerSize) is not supported."); } + int skipAmmount = 0; + if (headerSize > BmpInfoHeader.MaxHeaderSize) + { + skipAmmount = headerSize - BmpInfoHeader.MaxHeaderSize; + headerSize = BmpInfoHeader.MaxHeaderSize; + } + // read the rest of the header this.currentStream.Read(data, BmpInfoHeader.HeaderSizeSize, headerSize - BmpInfoHeader.HeaderSizeSize); @@ -388,14 +395,23 @@ namespace ImageSharp.Formats case BmpInfoHeader.BitmapCoreHeaderSize: this.infoHeader = this.ParseBitmapCoreHeader(data); break; - case BmpInfoHeader.BitmapInfoHeaderSize: this.infoHeader = this.ParseBitmapInfoHeader(data); break; - default: - throw new NotSupportedException($"This kind of bitmap files (header size $headerSize) is not supported."); + if (headerSize > BmpInfoHeader.BitmapInfoHeaderSize) + { + this.infoHeader = this.ParseBitmapInfoHeader(data); + break; + } + else + { + throw new NotSupportedException($"This kind of bitmap files (header size $headerSize) is not supported."); + } } + + // skip the remaining header because we can't read those parts + this.currentStream.Skip(skipAmmount); } /// diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index da27ab081a..764d768ae0 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -117,7 +117,9 @@ namespace ImageSharp.Tests public const string F = "Bmp/F.bmp"; public const string NegHeight = "Bmp/neg_height.bmp"; public const string CoreHeader = "Bmp/BitmapCoreHeaderQR.bmp"; - public static readonly string[] All = { Car, F, NegHeight, CoreHeader }; + public const string V5Header = "Bmp/BITMAPV5HEADER.bmp"; + + public static readonly string[] All = { Car, F, NegHeight, CoreHeader, V5Header }; } public static class Gif diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Bmp/BITMAPV5HEADER.bmp b/tests/ImageSharp.Tests/TestImages/Formats/Bmp/BITMAPV5HEADER.bmp new file mode 100644 index 0000000000..1ab56bb007 --- /dev/null +++ b/tests/ImageSharp.Tests/TestImages/Formats/Bmp/BITMAPV5HEADER.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d99f80a05e0ddb6309c84846dfac7d2ef4e9cdda6ed437646bc0edfee7d3130 +size 174026 From b93e3c5639d6ad74596f60d9d7eb98c7a39535d2 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Fri, 1 Sep 2017 21:14:55 +0200 Subject: [PATCH 2/4] Fixed typo --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ff3c9605c6..6692c20695 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# How to contribute to ImageSHarp +# How to contribute to ImageSharp #### **Did you find a bug?** From a8aee461635ec573be6e79d4f1187292e655b0f8 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Fri, 1 Sep 2017 21:21:41 +0200 Subject: [PATCH 3/4] Changed url to repo in the links. --- .github/CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6692c20695..188c11ff31 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -2,9 +2,9 @@ #### **Did you find a bug?** -- Please **ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/JimBobSquarePants/ImageSharp/issues). +- Please **ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/SixLabors/ImageSharp/issues). -- If you're unable to find an open issue addressing the problem, please [open a new one](https://github.com/JimBobSquarePants/ImageSharp/issues/new). Be sure to include a **title, the applicable version, a clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. Please do not hijack existing issues. +- If you're unable to find an open issue addressing the problem, please [open a new one](https://github.com/SixLabors/ImageSharp/issues/new). Be sure to include a **title, the applicable version, a clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. Please do not hijack existing issues. #### **Did you write a patch that fixes a bug?** From 16be5eeb0e8019db242a37a12ca9faf6d6efc6ce Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Fri, 1 Sep 2017 23:18:21 +0200 Subject: [PATCH 4/4] Fixed links and added files to the solution. --- .github/ISSUE_TEMPLATE.md | 2 +- .github/PULL_REQUEST_TEMPLATE.md | 2 +- ImageSharp.sln | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index e2c1276eb8..a172605e64 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -3,7 +3,7 @@ - [ ] I have written a descriptive issue title - [ ] I have verified that I am running the latest version of ImageSharp - [ ] I have verified if the problem exist in both `DEBUG` and `RELEASE` mode -- [ ] I have searched [open](https://github.com/JimBobSquarePants/ImageSharp/issuess) and [closed](https://github.com/JimBobSquarePants/ImageSharp/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported +- [ ] I have searched [open](https://github.com/SixLabors/ImageSharp/issues) and [closed](https://github.com/SixLabors/ImageSharp/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported ### Description diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 11444a3b23..4be3511650 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,7 +1,7 @@ ### Prerequisites - [ ] I have written a descriptive pull-request title -- [ ] I have verified that there are no overlapping [pull-requests](https://github.com/JimBobSquarePants/ImageSharp/pulls) open +- [ ] I have verified that there are no overlapping [pull-requests](https://github.com/SixLabors/ImageSharp/pulls) open - [ ] I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:. - [ ] I have provided test coverage for my change (where applicable) diff --git a/ImageSharp.sln b/ImageSharp.sln index a584c56868..a004f13711 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.14 +VisualStudioVersion = 15.0.26730.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}" ProjectSection(SolutionItems) = preProject @@ -14,7 +14,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt features.md = features.md ImageSharp.ruleset = ImageSharp.ruleset ImageSharp.sln.DotSettings = ImageSharp.sln.DotSettings + .github\ISSUE_TEMPLATE.md = .github\ISSUE_TEMPLATE.md NuGet.config = NuGet.config + .github\PULL_REQUEST_TEMPLATE.md = .github\PULL_REQUEST_TEMPLATE.md README.md = README.md EndProjectSection EndProject